Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/php-short-array-syntax'
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed Jun 5, 2015
2 parents a681623 + 99df34b commit a80bbfe
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 67 deletions.
1 change: 1 addition & 0 deletions .php_cs
Expand Up @@ -32,6 +32,7 @@ $config->fixers(
'object_operator',
'php_closing_tag',
'remove_lines_between_uses',
'short_array_syntax',
'short_tag',
'standardize_not_equal',
'trailing_spaces',
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/AbstractAdapter.php
Expand Up @@ -22,10 +22,10 @@ abstract class AbstractAdapter
*
* @var array
*/
protected $skipOptions = array(
protected $skipOptions = [
'options',
'config',
);
];

/**
* Create a new adapter
Expand Down
14 changes: 7 additions & 7 deletions src/Adapter/Console.php
Expand Up @@ -65,11 +65,11 @@ class Console extends AbstractAdapter
*
* @var array
*/
protected $elements = array(
protected $elements = [
self::ELEMENT_PERCENT,
self::ELEMENT_BAR,
self::ELEMENT_ETA,
);
];

/**
* Which action to do at finish call
Expand Down Expand Up @@ -248,10 +248,10 @@ public function setWidth($width = null)
*/
public function setElements(array $elements)
{
$allowedElements = array(self::ELEMENT_PERCENT,
$allowedElements = [self::ELEMENT_PERCENT,
self::ELEMENT_BAR,
self::ELEMENT_ETA,
self::ELEMENT_TEXT);
self::ELEMENT_TEXT];

if (count(array_diff($elements, $allowedElements)) > 0) {
throw new Exception\InvalidArgumentException('Invalid element found in $elements array');
Expand Down Expand Up @@ -347,9 +347,9 @@ public function setCharset($charset)
*/
public function setFinishAction($action)
{
$allowedActions = array(self::FINISH_ACTION_CLEAR_LINE,
$allowedActions = [self::FINISH_ACTION_CLEAR_LINE,
self::FINISH_ACTION_EOL,
self::FINISH_ACTION_NONE);
self::FINISH_ACTION_NONE];

if (!in_array($action, $allowedActions)) {
throw new Exception\InvalidArgumentException('Invalid finish action specified');
Expand Down Expand Up @@ -382,7 +382,7 @@ public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $te
}

// Build all elements
$renderedElements = array();
$renderedElements = [];

foreach ($this->elements as $element) {
switch ($element) {
Expand Down
6 changes: 3 additions & 3 deletions src/Adapter/JsPull.php
Expand Up @@ -48,15 +48,15 @@ public function setExitAfterSend($exitAfterSend)
*/
public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $text)
{
$arguments = array(
$arguments = [
'current' => $current,
'max' => $max,
'percent' => ($percent * 100),
'timeTaken' => $timeTaken,
'timeRemaining' => $timeRemaining,
'text' => $text,
'finished' => false
);
];

$data = Json::encode($arguments);

Expand All @@ -71,7 +71,7 @@ public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $te
*/
public function finish()
{
$data = Json::encode(array('finished' => true));
$data = Json::encode(['finished' => true]);

$this->_outputData($data);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/JsPush.php
Expand Up @@ -70,14 +70,14 @@ public function setFinishMethodName($methodName)
*/
public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $text)
{
$arguments = array(
$arguments = [
'current' => $current,
'max' => $max,
'percent' => ($percent * 100),
'timeTaken' => $timeTaken,
'timeRemaining' => $timeRemaining,
'text' => $text
);
];

$data = '<script type="text/javascript">'
. 'parent.' . $this->updateMethodName . '(' . Json::encode($arguments) . ');'
Expand Down
8 changes: 4 additions & 4 deletions src/Upload/AbstractUploadHandler.php
Expand Up @@ -34,7 +34,7 @@ abstract class AbstractUploadHandler implements UploadHandlerInterface
* @param array|Traversable $options Optional options
* @throws Exception\InvalidArgumentException
*/
public function __construct($options = array())
public function __construct($options = [])
{
if (!empty($options)) {
$this->setOptions($options);
Expand Down Expand Up @@ -112,13 +112,13 @@ public function getProgressAdapter()
*/
public function getProgress($id)
{
$status = array(
$status = [
'total' => 0,
'current' => 0,
'rate' => 0,
'message' => 'No upload in progress',
'done' => true
);
];
if (empty($id)) {
return $status;
}
Expand Down Expand Up @@ -169,7 +169,7 @@ abstract protected function getUploadProgress($id);
*/
protected function toByteString($size)
{
$sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$sizes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
for ($i=0; $size >= 1024 && $i < 9; $i++) {
$size /= 1024;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Upload/ApcProgress.php
Expand Up @@ -32,13 +32,13 @@ protected function getUploadProgress($id)
return false;
}

$status = array(
$status = [
'total' => 0,
'current' => 0,
'rate' => 0,
'message' => '',
'done' => false
);
];
$status = $uploadInfo + $status;
if (!empty($status['cancel_upload'])) {
$status['done'] = true;
Expand Down
4 changes: 2 additions & 2 deletions src/Upload/SessionProgress.php
Expand Up @@ -35,13 +35,13 @@ protected function getUploadProgress($id)
return false;
}

$status = array(
$status = [
'total' => 0,
'current' => 0,
'rate' => 0,
'message' => '',
'done' => false,
);
];
$status = $uploadInfo + $status;
$status['total'] = $status['content_length'];
$status['current'] = $status['bytes_processed'];
Expand Down
4 changes: 2 additions & 2 deletions src/Upload/UploadProgress.php
Expand Up @@ -34,13 +34,13 @@ protected function getUploadProgress($id)
return false;
}

$status = array(
$status = [
'total' => 0,
'current' => 0,
'rate' => 0,
'message' => '',
'done' => false
);
];
$status = $uploadInfo + $status;
$status['total'] = $status['bytes_total'];
$status['current'] = $status['bytes_uploaded'];
Expand Down
48 changes: 24 additions & 24 deletions test/Adapter/ConsoleTest.php
Expand Up @@ -52,7 +52,7 @@ public function testStandardOutputStream()

public function testManualStandardOutputStream()
{
$adapter = new ConsoleStub(array('outputStream' => 'php://stdout'));
$adapter = new ConsoleStub(['outputStream' => 'php://stdout']);

$this->assertInternalType('resource', $adapter->getOutputStream());

Expand All @@ -62,7 +62,7 @@ public function testManualStandardOutputStream()

public function testManualErrorOutputStream()
{
$adapter = new ConsoleStub(array('outputStream' => 'php://stderr'));
$adapter = new ConsoleStub(['outputStream' => 'php://stderr']);

$this->assertInternalType('resource', $adapter->getOutputStream());

Expand All @@ -72,7 +72,7 @@ public function testManualErrorOutputStream()

public function testFixedWidth()
{
$adapter = new ConsoleStub(array('width' => 30));
$adapter = new ConsoleStub(['width' => 30]);
$adapter->notify(0, 100, 0, 0, null, null);

$this->assertEquals(' 0% [----------] ', $adapter->getLastOutput());
Expand All @@ -81,12 +81,12 @@ public function testFixedWidth()
public function testInvalidElement()
{
$this->setExpectedException('Zend\ProgressBar\Adapter\Exception\InvalidArgumentException', 'Invalid element found');
$adapter = new ConsoleStub(array('width' => 30, 'elements' => array('foo')));
$adapter = new ConsoleStub(['width' => 30, 'elements' => ['foo']]);
}

public function testCariageReturn()
{
$adapter = new ConsoleStub(array('width' => 30));
$adapter = new ConsoleStub(['width' => 30]);
$adapter->notify(0, 100, 0, 0, null, null);
$adapter->notify(0, 100, 0, 0, null, null);

Expand All @@ -95,89 +95,89 @@ public function testCariageReturn()

public function testBarLayout()
{
$adapter = new ConsoleStub(array('width' => 30));
$adapter = new ConsoleStub(['width' => 30]);
$adapter->notify(50, 100, .5, 0, null, null);

$this->assertContains(' 50% [#####-----]', $adapter->getLastOutput());
}

public function testBarOnly()
{
$adapter = new ConsoleStub(array('width' => 20, 'elements' => array(Adapter\Console::ELEMENT_BAR)));
$adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR]]);
$adapter->notify(0, 100, 0, 0, null, null);

$this->assertEquals('[------------------]', $adapter->getLastOutput());
}

public function testPercentageOnly()
{
$adapter = new ConsoleStub(array('width' => 20, 'elements' => array(Adapter\Console::ELEMENT_PERCENT)));
$adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_PERCENT]]);
$adapter->notify(0, 100, 0, 0, null, null);

$this->assertEquals(' 0%', $adapter->getLastOutput());
}

public function testEtaOnly()
{
$adapter = new ConsoleStub(array('width' => 20, 'elements' => array(Adapter\Console::ELEMENT_ETA)));
$adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_ETA]]);
$adapter->notify(0, 100, 0, 0, null, null);

$this->assertEquals(' ', $adapter->getLastOutput());
}

public function testCustomOrder()
{
$adapter = new ConsoleStub(array('width' => 25, 'elements' => array(Adapter\Console::ELEMENT_ETA,
$adapter = new ConsoleStub(['width' => 25, 'elements' => [Adapter\Console::ELEMENT_ETA,
Adapter\Console::ELEMENT_PERCENT,
Adapter\Console::ELEMENT_BAR)));
Adapter\Console::ELEMENT_BAR]]);
$adapter->notify(0, 100, 0, 0, null, null);

$this->assertEquals(' 0% [-----]', $adapter->getLastOutput());
}

public function testBarStyleIndicator()
{
$adapter = new ConsoleStub(array('width' => 20, 'elements' => array(Adapter\Console::ELEMENT_BAR), 'barIndicatorChar' => '>'));
$adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barIndicatorChar' => '>']);
$adapter->notify(10, 100, .1, 0, null, null);

$this->assertContains('[##>---------------]', $adapter->getLastOutput());
}

public function testBarStyleIndicatorWide()
{
$adapter = new ConsoleStub(array('width' => 20, 'elements' => array(Adapter\Console::ELEMENT_BAR), 'barIndicatorChar' => '[]'));
$adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barIndicatorChar' => '[]']);
$adapter->notify(10, 100, .1, 0, null, null);

$this->assertContains('[##[]--------------]', $adapter->getLastOutput());
}

public function testBarStyleLeftRightNormal()
{
$adapter = new ConsoleStub(array('width' => 20, 'elements' => array(Adapter\Console::ELEMENT_BAR), 'barLeftChar' => '+', 'barRightChar' => ' '));
$adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barLeftChar' => '+', 'barRightChar' => ' ']);
$adapter->notify(10, 100, .1, 0, null, null);

$this->assertContains('[++ ]', $adapter->getLastOutput());
}

public function testBarStyleLeftRightWide()
{
$adapter = new ConsoleStub(array('width' => 20, 'elements' => array(Adapter\Console::ELEMENT_BAR), 'barLeftChar' => '+-', 'barRightChar' => '=-'));
$adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barLeftChar' => '+-', 'barRightChar' => '=-']);
$adapter->notify(10, 100, .1, 0, null, null);

$this->assertContains('[+-=-=-=-=-=-=-=-=-]', $adapter->getLastOutput());
}

public function testBarStyleLeftIndicatorRightWide()
{
$adapter = new ConsoleStub(array('width' => 20, 'elements' => array(Adapter\Console::ELEMENT_BAR), 'barLeftChar' => '+-', 'barIndicatorChar' => '[]', 'barRightChar' => '=-'));
$adapter = new ConsoleStub(['width' => 20, 'elements' => [Adapter\Console::ELEMENT_BAR], 'barLeftChar' => '+-', 'barIndicatorChar' => '[]', 'barRightChar' => '=-']);
$adapter->notify(10, 100, .1, 0, null, null);

$this->assertContains('[+-[]=-=-=-=-=-=-=-]', $adapter->getLastOutput());
}

public function testEtaDelayDisplay()
{
$adapter = new ConsoleStub(array('width' => 100, 'elements' => array(Adapter\Console::ELEMENT_ETA)));
$adapter = new ConsoleStub(['width' => 100, 'elements' => [Adapter\Console::ELEMENT_ETA]]);

$adapter->notify(33, 100, .33, 3, null, null);
$this->assertContains(' ', $adapter->getLastOutput());
Expand All @@ -190,7 +190,7 @@ public function testEtaDelayDisplay()

public function testEtaHighValue()
{
$adapter = new ConsoleStub(array('width' => 100, 'elements' => array(Adapter\Console::ELEMENT_ETA)));
$adapter = new ConsoleStub(['width' => 100, 'elements' => [Adapter\Console::ELEMENT_ETA]]);

$adapter->notify(1, 100005, .001, 5, 100000, null);

Expand All @@ -199,15 +199,15 @@ public function testEtaHighValue()

public function testTextElementDefaultLength()
{
$adapter = new ConsoleStub(array('width' => 100, 'elements' => array(Adapter\Console::ELEMENT_TEXT, Adapter\Console::ELEMENT_BAR)));
$adapter = new ConsoleStub(['width' => 100, 'elements' => [Adapter\Console::ELEMENT_TEXT, Adapter\Console::ELEMENT_BAR]]);
$adapter->notify(0, 100, 0, 0, null, 'foobar');

$this->assertContains('foobar [', $adapter->getLastOutput());
}

public function testTextElementCustomLength()
{
$adapter = new ConsoleStub(array('width' => 100, 'elements' => array(Adapter\Console::ELEMENT_TEXT, Adapter\Console::ELEMENT_BAR), 'textWidth' => 10));
$adapter = new ConsoleStub(['width' => 100, 'elements' => [Adapter\Console::ELEMENT_TEXT, Adapter\Console::ELEMENT_BAR], 'textWidth' => 10]);
$adapter->notify(0, 100, 0, 0, null, 'foobar');

$this->assertContains('foobar [', $adapter->getLastOutput());
Expand Down Expand Up @@ -301,10 +301,10 @@ public function testSetInvalidFinishAction()
public function testMultibyteTruncateFixedWidth()
{
$outputWidth = 50;
$adapter = new ConsoleStub(array('width' => $outputWidth, 'elements' => array(Adapter\Console::ELEMENT_PERCENT,
$adapter = new ConsoleStub(['width' => $outputWidth, 'elements' => [Adapter\Console::ELEMENT_PERCENT,
Adapter\Console::ELEMENT_BAR,
Adapter\Console::ELEMENT_ETA,
Adapter\Console::ELEMENT_TEXT)));
Adapter\Console::ELEMENT_TEXT]]);
$adapter->notify(21, 100, .21, 60, 60, 'ChineseTest 這是多字節長度裁剪的測試。我們希望能有超過20名中國字符的長字符串');
$this->assertEquals(' 21% [##-------] ETA 00:01:00 ChineseTest 這是多字節長度裁', $adapter->getLastOutput());

Expand All @@ -318,10 +318,10 @@ public function testMultibyteTruncateFixedWidth()
public function testMultibytePadFixedWidth()
{
$outputWidth = 50;
$adapter = new ConsoleStub(array('width' => $outputWidth, 'elements' => array(Adapter\Console::ELEMENT_PERCENT,
$adapter = new ConsoleStub(['width' => $outputWidth, 'elements' => [Adapter\Console::ELEMENT_PERCENT,
Adapter\Console::ELEMENT_BAR,
Adapter\Console::ELEMENT_ETA,
Adapter\Console::ELEMENT_TEXT)));
Adapter\Console::ELEMENT_TEXT]]);
$adapter->notify(21, 100, .21, 60, 60, '這是');
$this->assertEquals(' 21% [##-------] ETA 00:01:00 這是 ', $adapter->getLastOutput());

Expand Down

0 comments on commit a80bbfe

Please sign in to comment.