Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions .php_cs

This file was deleted.

15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ matrix:
include:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- CS_CHECK=true
- php: 5.6
env:
- EXECUTE_TEST_COVERALLS=true
- TEST_COVERAGE=true
- DEPLOY_DOCS="$(if [[ $TRAVIS_BRANCH == 'master' && $TRAVIS_PULL_REQUEST == 'false' ]]; then echo -n 'true' ; else echo -n 'false' ; fi)"
- PATH="$HOME/.local/bin:$PATH"
- php: 7
Expand All @@ -42,21 +42,20 @@ notifications:
email: false

before_install:
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- composer self-update
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs

script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
- if [[ $DEPLOY_DOCS == "true" && "$TRAVIS_TEST_RESULT" == "0" ]]; then wget -O theme-installer.sh "https://raw.githubusercontent.com/zendframework/zf-mkdoc-theme/master/theme-installer.sh" ; chmod 755 theme-installer.sh ; ./theme-installer.sh ; fi

after_success:
- if [[ $DEPLOY_DOCS == "true" ]]; then echo "Preparing to build and deploy documentation" ; ./zf-mkdoc-theme/deploy.sh ; echo "Completed deploying documentation" ; fi

after_script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then composer upload-coverage ; fi
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ To do so:

## Running Coding Standards Checks

This component uses [php-cs-fixer](http://cs.sensiolabs.org/) for coding
This component uses [phpcs](https://github.com/squizlabs/PHP_CodeSniffer) for coding
standards checks, and provides configuration for our selected checks.
`php-cs-fixer` is installed by default via Composer.
`phpcs` is installed by default via Composer.

To run checks only:

```console
$ ./vendor/bin/php-cs-fixer fix . -v --diff --dry-run --config-file=.php_cs
$ composer cs-check
```

To have `php-cs-fixer` attempt to fix problems for you, omit the `--dry-run`
flag:
`phpcs` also includes a tool for fixing most CS violations, `phpcbf`:


```console
$ ./vendor/bin/php-cs-fixer fix . -v --diff --config-file=.php_cs
$ composer cs-fix
```

If you allow php-cs-fixer to fix CS issues, please re-run the tests to ensure
If you allow `phpcbf` to fix CS issues, please re-run the tests to ensure
they pass, and make sure you add and commit the changes after verification.

## Recommended Workflow for Contributions
Expand Down
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"require-dev": {
"zendframework/zend-json": "^2.6.1",
"zendframework/zend-session": "^2.6.2",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
"phpunit/PHPUnit": "~4.0",
"zendframework/zend-coding-standard": "~1.0.0"
},
"suggest": {
"zendframework/zend-json": "Zend\\Json component",
Expand All @@ -38,5 +38,16 @@
"psr-4": {
"ZendTest\\ProgressBar\\": "test/"
}
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"upload-coverage": "coveralls -v"
}
}
8 changes: 8 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework coding standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>
</ruleset>
25 changes: 19 additions & 6 deletions src/Adapter/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function setOutputStream($resource)
public function getOutputStream()
{
if ($this->outputStream === null) {
if (!defined('STDOUT')) {
if (! defined('STDOUT')) {
$this->outputStream = fopen('php://stdout', 'w');
} else {
return STDOUT;
Expand All @@ -210,7 +210,7 @@ public function getOutputStream()
*/
public function setWidth($width = null)
{
if ($width === null || !is_int($width)) {
if ($width === null || ! is_int($width)) {
if (substr(PHP_OS, 0, 3) === 'WIN') {
// We have to default to 79 on windows, because the windows
// terminal always has a fixed width of 80 characters and the
Expand Down Expand Up @@ -243,7 +243,8 @@ public function setWidth($width = null)
* Set the elements to display with the progressbar
*
* @param array $elements
* @throws \Zend\ProgressBar\Adapter\Exception\InvalidArgumentException When an invalid element is found in the array
* @throws \Zend\ProgressBar\Adapter\Exception\InvalidArgumentException When an invalid element is found
* in the array
* @return \Zend\ProgressBar\Adapter\Console
*/
public function setElements(array $elements)
Expand Down Expand Up @@ -351,7 +352,7 @@ public function setFinishAction($action)
self::FINISH_ACTION_EOL,
self::FINISH_ACTION_NONE];

if (!in_array($action, $allowedActions)) {
if (! in_array($action, $allowedActions)) {
throw new Exception\InvalidArgumentException('Invalid finish action specified');
}

Expand Down Expand Up @@ -394,14 +395,22 @@ public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $te

$doneWidth = min($visualWidth - $indicatorWidth, round($visualWidth * $percent));
if ($doneWidth > 0) {
$bar .= substr(str_repeat($this->barLeftChar, ceil($doneWidth / strlen($this->barLeftChar))), 0, $doneWidth);
$bar .= substr(
str_repeat($this->barLeftChar, ceil($doneWidth / strlen($this->barLeftChar))),
0,
$doneWidth
);
}

$bar .= $this->barIndicatorChar;

$leftWidth = $visualWidth - $doneWidth - $indicatorWidth;
if ($leftWidth > 0) {
$bar .= substr(str_repeat($this->barRightChar, ceil($leftWidth / strlen($this->barRightChar))), 0, $leftWidth);
$bar .= substr(
str_repeat($this->barRightChar, ceil($leftWidth / strlen($this->barRightChar))),
0,
$leftWidth
);
}

$bar .= ']';
Expand Down Expand Up @@ -485,8 +494,10 @@ public function finish()
*
* @return void
*/
// @codingStandardsIgnoreStart
protected function _calculateBarWidth()
{
// @codingStandardsIgnoreEnd
if (in_array(self::ELEMENT_BAR, $this->elements)) {
$barWidth = $this->width;

Expand Down Expand Up @@ -514,8 +525,10 @@ protected function _calculateBarWidth()
* @param string $data
* @return void
*/
// @codingStandardsIgnoreStart
protected function _outputData($data)
{
// @codingStandardsIgnoreEnd
fwrite($this->getOutputStream(), $data);
}
}
2 changes: 2 additions & 0 deletions src/Adapter/JsPull.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ public function finish()
* @param string $data
* @return void
*/
// @codingStandardsIgnoreStart
protected function _outputData($data)
{
// @codingStandardsIgnoreEnd
echo $data;

if ($this->exitAfterSend) {
Expand Down
2 changes: 2 additions & 0 deletions src/Adapter/JsPush.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ public function finish()
* @param string $data
* @return void
*/
// @codingStandardsIgnoreStart
protected function _outputData($data)
{
// @codingStandardsIgnoreEnd
// 1024 padding is required for Safari, while 256 padding is required
// for Internet Explorer. The <br /> is required so Safari actually
// executes the <script />
Expand Down
8 changes: 4 additions & 4 deletions src/Upload/AbstractUploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class AbstractUploadHandler implements UploadHandlerInterface
*/
public function __construct($options = [])
{
if (!empty($options)) {
if (! empty($options)) {
$this->setOptions($options);
}
}
Expand All @@ -54,7 +54,7 @@ public function setOptions($options)
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
} elseif (!is_array($options)) {
} elseif (! is_array($options)) {
throw new Exception\InvalidArgumentException(
'The options parameter must be an array or a Traversable'
);
Expand Down Expand Up @@ -141,7 +141,7 @@ public function getProgress($id)
$this->setProgressAdapter($adapter);
}

if (!$adapter instanceof ProgressBar) {
if (! $adapter instanceof ProgressBar) {
throw new Exception\RuntimeException('Unknown Adapter type given');
}

Expand Down Expand Up @@ -170,7 +170,7 @@ abstract protected function getUploadProgress($id);
protected function toByteString($size)
{
$sizes = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
for ($i=0; $size >= 1024 && $i < 9; $i++) {
for ($i = 0; $size >= 1024 && $i < 9; $i++) {
$size /= 1024;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Upload/ApcProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class ApcProgress extends AbstractUploadHandler
*/
protected function getUploadProgress($id)
{
if (!$this->isApcAvailable()) {
if (! $this->isApcAvailable()) {
throw new Exception\PhpEnvironmentException('APC extension is not installed');
}

$uploadInfo = apc_fetch(ini_get('apc.rfc1867_prefix') . $id);
if (!is_array($uploadInfo)) {
if (! is_array($uploadInfo)) {
return false;
}

Expand All @@ -40,7 +40,7 @@ protected function getUploadProgress($id)
'done' => false
];
$status = $uploadInfo + $status;
if (!empty($status['cancel_upload'])) {
if (! empty($status['cancel_upload'])) {
$status['done'] = true;
$status['message'] = 'The upload has been canceled';
}
Expand Down
6 changes: 3 additions & 3 deletions src/Upload/SessionProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ class SessionProgress extends AbstractUploadHandler
*/
protected function getUploadProgress($id)
{
if (!$this->isSessionUploadProgressAvailable()) {
if (! $this->isSessionUploadProgressAvailable()) {
throw new Exception\PhpEnvironmentException(
'Session Upload Progress is not available'
);
}

$sessionKey = ini_get('session.upload_progress.prefix') . $id;
$uploadInfo = (isset($_SESSION[$sessionKey])) ? $_SESSION[$sessionKey] : null;
if (!is_array($uploadInfo)) {
if (! is_array($uploadInfo)) {
return false;
}

Expand All @@ -49,7 +49,7 @@ protected function getUploadProgress($id)
$time = time() - $status['start_time'];
$status['rate'] = ($time > 0) ? $status['bytes_processed'] / $time : 0;

if (!empty($status['cancel_upload'])) {
if (! empty($status['cancel_upload'])) {
$status['done'] = true;
$status['message'] = 'The upload has been canceled';
}
Expand Down
4 changes: 2 additions & 2 deletions src/Upload/UploadProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class UploadProgress extends AbstractUploadHandler
*/
protected function getUploadProgress($id)
{
if (!$this->isUploadProgressAvailable()) {
if (! $this->isUploadProgressAvailable()) {
throw new Exception\PhpEnvironmentException(
'UploadProgress extension is not installed'
);
}

$uploadInfo = uploadprogress_get_info($id);
if (!is_array($uploadInfo)) {
if (! is_array($uploadInfo)) {
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions test/Adapter/ConsoleStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public function getLastOutput()
return $this->lastOutput;
}

// @codingStandardsIgnoreStart
protected function _outputData($data)
{
// @codingStandardsIgnoreEnd
$this->lastOutput = $data;
}

Expand Down
Loading