Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a85a47e

Browse files
committed
Refactor.
1 parent ee2d432 commit a85a47e

File tree

4 files changed

+45
-32
lines changed

4 files changed

+45
-32
lines changed

lib/Psf/Helpers/Table.php

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* TableHelper
3+
* Table
44
*
55
* @author Piotr Olaszewski
66
*/
@@ -11,86 +11,86 @@
1111

1212
class Table implements HelperInterface
1313
{
14-
private $headers = array();
15-
private $rows = array();
14+
private $_headers = array();
15+
private $_rows = array();
1616
/**
1717
* @var Writer
1818
*/
19-
private $output;
19+
private $_output;
2020

2121
public function setHeaders(array $headers)
2222
{
23-
$this->headers = $headers;
23+
$this->_headers = $headers;
2424
return $this;
2525
}
2626

2727
public function setRows(array $rows)
2828
{
29-
$this->rows = $rows;
29+
$this->_rows = $rows;
3030
return $this;
3131
}
3232

3333
public function render(Writer $output)
3434
{
35-
$this->output = $output;
35+
$this->_output = $output;
3636

37-
$this->renderHeaderRowSeparator();
38-
$this->generateHeaderRow();
39-
$this->renderHeaderRowSeparator();
37+
$this->_renderHeaderRowSeparator();
38+
$this->_generateHeaderRow();
39+
$this->_renderHeaderRowSeparator();
4040

41-
$this->generateBodyRows();
42-
$this->renderHeaderRowSeparator();
41+
$this->_generateBodyRows();
42+
$this->_renderHeaderRowSeparator();
4343
}
4444

45-
private function renderHeaderRowSeparator()
45+
private function _renderHeaderRowSeparator()
4646
{
4747
$separator = '+';
48-
foreach ($this->headers as $column => $header) {
49-
$columnWidth = $this->getColumnWidth($column);
48+
foreach ($this->_headers as $column => $header) {
49+
$columnWidth = $this->_getColumnWidth($column);
5050
$separator .= str_repeat('-', $columnWidth) . '+';
5151
}
52-
$this->output->writeMessage($separator);
52+
$this->_output->writeMessage($separator);
5353
}
5454

55-
private function generateHeaderRow()
55+
private function _generateHeaderRow()
5656
{
57-
$this->renderDataRow($this->headers);
57+
$this->_renderDataRow($this->_headers);
5858
}
5959

60-
private function generateBodyRows()
60+
private function _generateBodyRows()
6161
{
62-
foreach ($this->rows as $row) {
63-
$this->renderDataRow($row);
62+
foreach ($this->_rows as $row) {
63+
$this->_renderDataRow($row);
6464
}
6565
}
6666

67-
private function renderDataRow($row)
67+
private function _renderDataRow($row)
6868
{
6969
$line = '|';
7070
foreach ($row as $column => $name) {
71-
$columnWidth = $this->getColumnWidth($column);
71+
$columnWidth = $this->_getColumnWidth($column);
7272
$spaces = $columnWidth - strlen($name) - 1;
7373
$line .= ' ' . $name . str_repeat(' ', $spaces) . '|';
7474
}
75-
$this->output->writeMessage($line);
75+
$this->_output->writeMessage($line);
7676
}
7777

78-
private function getColumnWidth($column)
78+
private function _getColumnWidth($column)
7979
{
8080
$width = 0;
81-
if (isset($this->headers[$column])) {
82-
$width = strlen($this->headers[$column]);
81+
if (isset($this->_headers[$column])) {
82+
$width = strlen($this->_headers[$column]);
8383
}
8484
array_map(function ($element) use (&$width, $column) {
8585
$length = strlen($element[$column]);
8686
if ($length > $width) {
8787
$width = $length;
8888
}
89-
}, $this->rows);
90-
return $this->widthWithSpaces($width);
89+
}, $this->_rows);
90+
return $this->_widthWithSpaces($width);
9191
}
9292

93-
private function widthWithSpaces($width)
93+
private function _widthWithSpaces($width)
9494
{
9595
return $width + 2;
9696
}

lib/Psf/Input/Reader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Reader
44
*
5-
* @author Piotrooo
5+
* @author Piotr Olaszewski
66
*/
77
namespace Psf\Input;
88

lib/Psf/Output/StyleFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* StyleFormatter
44
*
5-
* @author Piotrooo
5+
* @author Piotr Olaszewski
66
*/
77
namespace Psf\Output;
88

lib/Psf/Shell.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,24 @@
1616
class Shell
1717
{
1818
public $parsedArgv;
19+
/**
20+
* @var Writer
21+
*/
1922
private $_stdout;
23+
/**
24+
* @var Writer
25+
*/
2026
private $_stderr;
27+
/**
28+
* @var Reader
29+
*/
2130
private $_stdin;
31+
/**
32+
* @var DefinedInput[]
33+
*/
2234
private $_userDefinedInput = array();
2335
private $_applicationName;
36+
2437
public function __construct($applicationName, $parsedArgv)
2538
{
2639
$this->_applicationName = $applicationName;

0 commit comments

Comments
 (0)