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

New coding standard #65

Merged
merged 9 commits into from
Jun 19, 2017
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.

17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ matrix:
include:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- CS_CHECK=true
- php: 5.5
env:
- EVENT_MANAGER_VERSION="^2.6.2"
- SERVICE_MANAGER_VERSION="^2.7.5"
- 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: 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: 5.6
Expand All @@ -67,9 +67,9 @@ notifications:

before_install:
- pecl -q install mongodb
- 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
- if [[ $EVENT_MANAGER_VERSION != '' ]]; then composer require --no-update "zendframework/zend-eventmanager:$EVENT_MANAGER_VERSION" ; fi
- if [[ $EVENT_MANAGER_VERSION == '' ]]; then composer require --no-update "zendframework/zend-eventmanager:^3.0" ; fi
- if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi
Expand All @@ -79,13 +79,12 @@ 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 @@ -25,8 +25,8 @@
"zendframework/zend-validator": "^2.6",
"container-interop/container-interop": "^1.1",
"mongodb/mongodb": "^1.0.1",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
"phpunit/PHPUnit": "~4.0",
"zendframework/zend-coding-standard": "~1.0.0"
},
"suggest": {
"zendframework/zend-cache": "Zend\\Cache component",
Expand All @@ -52,5 +52,16 @@
"psr-4": {
"ZendTest\\Session\\": "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"
}
}
10 changes: 10 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?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>
<!-- Needs to get excluded due it executing code AND declaring symbols -->
<exclude-pattern>/src/ValidatorChain.php</exclude-pattern>
</ruleset>
24 changes: 12 additions & 12 deletions src/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class AbstractContainer extends ArrayObject
*/
public function __construct($name = 'Default', Manager $manager = null)
{
if (!preg_match('/^[a-z0-9][a-z0-9_\\\\]+$/i', $name)) {
if (! preg_match('/^[a-z0-9][a-z0-9_\\\\]+$/i', $name)) {
throw new Exception\InvalidArgumentException(
'Name passed to container is invalid; must consist of alphanumerics, backslashes and underscores only'
);
Expand Down Expand Up @@ -101,7 +101,7 @@ public static function getDefaultManager()
{
if (null === static::$defaultManager) {
$manager = new static::$managerDefaultClass();
if (!$manager instanceof Manager) {
if (! $manager instanceof Manager) {
throw new Exception\InvalidArgumentException(
'Invalid default manager type provided; must implement ManagerInterface'
);
Expand Down Expand Up @@ -133,7 +133,7 @@ protected function setManager(Manager $manager = null)
{
if (null === $manager) {
$manager = static::getDefaultManager();
if (!$manager instanceof Manager) {
if (! $manager instanceof Manager) {
throw new Exception\InvalidArgumentException(
'Manager provided is invalid; must implement ManagerInterface'
);
Expand Down Expand Up @@ -192,13 +192,13 @@ protected function verifyNamespace($createContainer = true)
{
$storage = $this->getStorage();
$name = $this->getName();
if (!isset($storage[$name])) {
if (!$createContainer) {
if (! isset($storage[$name])) {
if (! $createContainer) {
return;
}
$storage[$name] = $this->createContainer();
}
if (!is_array($storage[$name]) && !$storage[$name] instanceof Traversable) {
if (! is_array($storage[$name]) && ! $storage[$name] instanceof Traversable) {
throw new Exception\RuntimeException('Container cannot write to storage due to type mismatch');
}

Expand All @@ -219,7 +219,7 @@ protected function expireKeys($key = null)
$name = $this->getName();

// Return early if key not found
if ((null !== $key) && !isset($storage[$name][$key])) {
if ((null !== $key) && ! isset($storage[$name][$key])) {
return true;
}

Expand Down Expand Up @@ -407,13 +407,13 @@ public function offsetExists($key)
$name = $this->getName();

// Return early if the key isn't set
if (!isset($storage[$name][$key])) {
if (! isset($storage[$name][$key])) {
return false;
}

$expired = $this->expireKeys($key);

return !$expired;
return ! $expired;
}

/**
Expand All @@ -424,7 +424,7 @@ public function offsetExists($key)
*/
public function offsetGet($key)
{
if (!$this->offsetExists($key)) {
if (! $this->offsetExists($key)) {
return;
}
$storage = $this->getStorage();
Expand All @@ -441,7 +441,7 @@ public function offsetGet($key)
*/
public function offsetUnset($key)
{
if (!$this->offsetExists($key)) {
if (! $this->offsetExists($key)) {
return;
}
$storage = $this->getStorage();
Expand All @@ -462,7 +462,7 @@ public function exchangeArray($input)
if (is_object($input) && ($input instanceof ArrayObject || $input instanceof \ArrayObject)) {
$input = $input->getArrayCopy();
}
if (!is_array($input)) {
if (! is_array($input)) {
$input = (array) $input;
}

Expand Down
8 changes: 4 additions & 4 deletions src/AbstractManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function __construct(
) {
// init config
if ($config === null) {
if (!class_exists($this->defaultConfigClass)) {
if (! class_exists($this->defaultConfigClass)) {
throw new Exception\RuntimeException(sprintf(
'Unable to locate config class "%s"; class does not exist',
$this->defaultConfigClass
Expand All @@ -79,7 +79,7 @@ public function __construct(

$config = new $this->defaultConfigClass();

if (!$config instanceof Config) {
if (! $config instanceof Config) {
throw new Exception\RuntimeException(sprintf(
'Default config class %s is invalid; must implement %s\Config\ConfigInterface',
$this->defaultConfigClass,
Expand All @@ -92,7 +92,7 @@ public function __construct(

// init storage
if ($storage === null) {
if (!class_exists($this->defaultStorageClass)) {
if (! class_exists($this->defaultStorageClass)) {
throw new Exception\RuntimeException(sprintf(
'Unable to locate storage class "%s"; class does not exist',
$this->defaultStorageClass
Expand All @@ -101,7 +101,7 @@ public function __construct(

$storage = new $this->defaultStorageClass();

if (!$storage instanceof Storage) {
if (! $storage instanceof Storage) {
throw new Exception\RuntimeException(sprintf(
'Default storage class %s is invalid; must implement %s\Storage\StorageInterface',
$this->defaultConfigClass,
Expand Down
8 changes: 4 additions & 4 deletions src/Config/SessionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function setSerializeHandler($serializeHandler)
public function setCacheLimiter($cacheLimiter)
{
$cacheLimiter = (string) $cacheLimiter;
if (!in_array($cacheLimiter, $this->validCacheLimiters)) {
if (! in_array($cacheLimiter, $this->validCacheLimiters)) {
throw new Exception\InvalidArgumentException('Invalid cache limiter provided');
}
$this->setOption('cache_limiter', $cacheLimiter);
Expand All @@ -215,7 +215,7 @@ public function setHashFunction($hashFunction)
{
$hashFunction = (string) $hashFunction;
$validHashFunctions = $this->getHashFunctions();
if (!in_array($hashFunction, $validHashFunctions, true)) {
if (! in_array($hashFunction, $validHashFunctions, true)) {
throw new Exception\InvalidArgumentException('Invalid hash function provided');
}

Expand All @@ -233,8 +233,8 @@ public function setHashFunction($hashFunction)
*/
public function setHashBitsPerCharacter($hashBitsPerCharacter)
{
if (!is_numeric($hashBitsPerCharacter)
|| !in_array($hashBitsPerCharacter, $this->validHashBitsPerCharacters)
if (! is_numeric($hashBitsPerCharacter)
|| ! in_array($hashBitsPerCharacter, $this->validHashBitsPerCharacters)
) {
throw new Exception\InvalidArgumentException('Invalid hash bits per character provided');
}
Expand Down
Loading