From 66088d1ecabd5480a534b6c9bc0b5557d7556944 Mon Sep 17 00:00:00 2001 From: Koopzington Date: Sun, 13 Nov 2016 16:12:47 +0100 Subject: [PATCH 1/8] Remove CS dependencies and add zend-coding-standard to require-dev --- composer.json | 2 +- composer.lock | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 34058fdb..97627681 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "require-dev": { "phpunit/phpUnit": "^4.8", - "squizlabs/php_codesniffer": "^2.3.1" + "zendframework/zend-coding-standard": "~1.0.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index c3173409..673ee020 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "3df882c920dac6a817267fdb427bc683", - "content-hash": "40d432af69dc02ab455872e5fc9f995a", + "hash": "eb8cd078b87569f0e931d332c8431f0d", + "content-hash": "48a0c3c9c51e6c430e39d0c58d09546d", "packages": [ { "name": "zendframework/zend-code", @@ -1168,16 +1168,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "2.6.1", + "version": "2.7.0", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "fb72ed32f8418db5e7770be1653e62e0d6f5dd3d" + "reference": "571e27b6348e5b3a637b2abc82ac0d01e6d7bbed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/fb72ed32f8418db5e7770be1653e62e0d6f5dd3d", - "reference": "fb72ed32f8418db5e7770be1653e62e0d6f5dd3d", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/571e27b6348e5b3a637b2abc82ac0d01e6d7bbed", + "reference": "571e27b6348e5b3a637b2abc82ac0d01e6d7bbed", "shasum": "" }, "require": { @@ -1242,7 +1242,7 @@ "phpcs", "standards" ], - "time": "2016-05-30 22:24:32" + "time": "2016-09-01 23:53:02" }, { "name": "symfony/yaml", @@ -1341,6 +1341,35 @@ "validate" ], "time": "2015-08-24 13:29:44" + }, + { + "name": "zendframework/zend-coding-standard", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/zendframework/zend-coding-standard.git", + "reference": "893316d2904e93f1c74c1384b6d7d57778299cb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/zendframework/zend-coding-standard/zipball/893316d2904e93f1c74c1384b6d7d57778299cb6", + "reference": "893316d2904e93f1c74c1384b6d7d57778299cb6", + "shasum": "" + }, + "require": { + "squizlabs/php_codesniffer": "^2.7" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "description": "Zend Framework coding standard", + "keywords": [ + "Coding Standard", + "zf" + ], + "time": "2016-11-09 21:30:43" } ], "aliases": [], From f60f8181bb904cf4763ad529bdaab25577642370 Mon Sep 17 00:00:00 2001 From: Koopzington Date: Sun, 13 Nov 2016 20:07:03 +0100 Subject: [PATCH 2/8] add/update phpcs.xml --- phpcs.xml | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index 25a3ac67..c48d19c5 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,24 +1,8 @@ - Zend Framework coding standard - - - - - - - - - - - - - + src test - */TestAsset/* - */_files/* - */compatibility/* From 2b8d89a77c895a15903fd3fcb540c8333a754736 Mon Sep 17 00:00:00 2001 From: Koopzington Date: Sun, 13 Nov 2016 20:28:15 +0100 Subject: [PATCH 3/8] add/update composer scripts --- composer.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/composer.json b/composer.json index 97627681..6373ba82 100644 --- a/composer.json +++ b/composer.json @@ -34,5 +34,16 @@ "files": [ "test/TestAsset/reflectionTestFunction.php" ] + }, + "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" } } From f6c22d47fbae59011694236412b1ee60377062de Mon Sep 17 00:00:00 2001 From: Koopzington Date: Sun, 13 Nov 2016 20:41:39 +0100 Subject: [PATCH 4/8] Use composer scripts in .travis.yml --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5a969711..3d89b79f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,13 +75,12 @@ install: - composer show script: - - if [[ $TEST_COVERAGE == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi - - if [[ $TEST_COVERAGE != 'true' ]]; then ./vendor/bin/phpunit ; fi - - if [[ $CS_CHECK == 'true' ]]; then ./vendor/bin/phpcs ; 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 [[ $TEST_COVERAGE == 'true' ]]; then ./vendor/bin/coveralls ; fi + - if [[ $TEST_COVERAGE == 'true' ]]; then composer upload-coverage ; fi From 1b2d61f7dd51048cb94ac0a82ba36a608173b104 Mon Sep 17 00:00:00 2001 From: Koopzington Date: Sun, 13 Nov 2016 20:43:26 +0100 Subject: [PATCH 5/8] Replace mentions of php-cs-fixer with phpcs --- CONTRIBUTING.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6c5f1cf0..bfc49c7a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 +$ ./vendor/bin/phpcs ``` -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 +$ ./vendor/bin/phpcbf ``` -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 From 2f166f731d5b8189b27792b4be55bf80f4c145d4 Mon Sep 17 00:00:00 2001 From: Koopzington Date: Tue, 15 Nov 2016 19:32:38 +0100 Subject: [PATCH 6/8] Replace mentions of phpcs and phpcbf with composer scripts --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bfc49c7a..4e5022e8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -84,14 +84,14 @@ standards checks, and provides configuration for our selected checks. To run checks only: ```console -$ ./vendor/bin/phpcs +$ composer cs-check ``` `phpcs` also includes a tool for fixing most CS violations, `phpcbf`: ```console -$ ./vendor/bin/phpcbf +$ composer cs-fix ``` If you allow `phpcbf` to fix CS issues, please re-run the tests to ensure From fb240bf13dc2f4af1c8b23bbf02d0ff1aeddb311 Mon Sep 17 00:00:00 2001 From: Koopzington Date: Thu, 17 Nov 2016 21:51:31 +0100 Subject: [PATCH 7/8] Automated CS fixes --- src/AbstractServer.php | 6 +++--- src/Cache.php | 4 ++-- src/Definition.php | 4 ++-- src/Method/Callback.php | 2 +- src/Method/Definition.php | 6 +++--- src/Method/Prototype.php | 2 +- src/Reflection.php | 6 +++--- src/Reflection/AbstractFunction.php | 8 ++++---- src/Reflection/Node.php | 6 +++--- src/Reflection/Prototype.php | 2 +- src/Reflection/ReflectionClass.php | 2 +- src/Reflection/ReflectionMethod.php | 10 +++++----- src/Reflection/ReflectionParameter.php | 4 ++-- src/Reflection/ReflectionReturnValue.php | 4 ++-- 14 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/AbstractServer.php b/src/AbstractServer.php index f14e8178..4ba85c88 100644 --- a/src/AbstractServer.php +++ b/src/AbstractServer.php @@ -91,7 +91,7 @@ protected function _buildSignature(Reflection\AbstractFunction $reflection, $cla $name = $reflection->getName(); $method = empty($ns) ? $name : $ns . '.' . $name; - if (!$this->overwriteExistingMethods && $this->table->hasMethod($method)) { + if (! $this->overwriteExistingMethods && $this->table->hasMethod($method)) { throw new Exception\RuntimeException('Duplicate method registered: ' . $method); } @@ -153,9 +153,9 @@ protected function _dispatch(Method\Definition $invokable, array $params) } $object = $invokable->getObject(); - if (!is_object($object)) { + if (! is_object($object)) { $invokeArgs = $invokable->getInvokeArguments(); - if (!empty($invokeArgs)) { + if (! empty($invokeArgs)) { $reflection = new ReflectionClass($class); $object = $reflection->newInstanceArgs($invokeArgs); } else { diff --git a/src/Cache.php b/src/Cache.php index 8fe09ce7..2deff643 100644 --- a/src/Cache.php +++ b/src/Cache.php @@ -36,7 +36,7 @@ class Cache */ public static function save($filename, Server $server) { - if (!is_string($filename) || (!file_exists($filename) && !is_writable(dirname($filename)))) { + if (! is_string($filename) || (! file_exists($filename) && ! is_writable(dirname($filename)))) { return false; } @@ -96,7 +96,7 @@ public static function save($filename, Server $server) */ public static function get($filename, Server $server) { - if (!is_string($filename) || !file_exists($filename) || !is_readable($filename)) { + if (! is_string($filename) || ! file_exists($filename) || ! is_readable($filename)) { return false; } diff --git a/src/Definition.php b/src/Definition.php index f614b220..ca2e87ed 100644 --- a/src/Definition.php +++ b/src/Definition.php @@ -63,7 +63,7 @@ public function addMethod($method, $name = null) { if (is_array($method)) { $method = new Method\Definition($method); - } elseif (!$method instanceof Method\Definition) { + } elseif (! $method instanceof Method\Definition) { throw new Exception\InvalidArgumentException('Invalid method provided'); } @@ -79,7 +79,7 @@ public function addMethod($method, $name = null) throw new Exception\InvalidArgumentException('No method name provided'); } - if (!$this->overwriteExistingMethods && array_key_exists($name, $this->methods)) { + if (! $this->overwriteExistingMethods && array_key_exists($name, $this->methods)) { throw new Exception\InvalidArgumentException(sprintf('Method by name of "%s" already exists', $name)); } $this->methods[$name] = $method; diff --git a/src/Method/Callback.php b/src/Method/Callback.php index 0b6152f2..10a7ed0b 100644 --- a/src/Method/Callback.php +++ b/src/Method/Callback.php @@ -149,7 +149,7 @@ public function getMethod() */ public function setType($type) { - if (!in_array($type, $this->types)) { + if (! in_array($type, $this->types)) { throw new Server\Exception\InvalidArgumentException(sprintf( 'Invalid method callback type "%s" passed to %s', $type, diff --git a/src/Method/Definition.php b/src/Method/Definition.php index e6bafd2d..1ba74215 100644 --- a/src/Method/Definition.php +++ b/src/Method/Definition.php @@ -108,7 +108,7 @@ public function setCallback($callback) { if (is_array($callback)) { $callback = new Callback($callback); - } elseif (!$callback instanceof Callback) { + } elseif (! $callback instanceof Callback) { throw new Server\Exception\InvalidArgumentException('Invalid method callback provided'); } $this->callback = $callback; @@ -136,7 +136,7 @@ public function addPrototype($prototype) { if (is_array($prototype)) { $prototype = new Prototype($prototype); - } elseif (!$prototype instanceof Prototype) { + } elseif (! $prototype instanceof Prototype) { throw new Server\Exception\InvalidArgumentException('Invalid method prototype provided'); } $this->prototypes[] = $prototype; @@ -211,7 +211,7 @@ public function getMethodHelp() */ public function setObject($object) { - if (!is_object($object) && (null !== $object)) { + if (! is_object($object) && (null !== $object)) { throw new Server\Exception\InvalidArgumentException(sprintf( 'Invalid object passed to %s', __METHOD__ diff --git a/src/Method/Prototype.php b/src/Method/Prototype.php index add39018..2f9a6bcf 100644 --- a/src/Method/Prototype.php +++ b/src/Method/Prototype.php @@ -145,7 +145,7 @@ public function getParameterObjects() */ public function getParameter($index) { - if (!is_string($index) && !is_numeric($index)) { + if (! is_string($index) && ! is_numeric($index)) { return; } if (array_key_exists($index, $this->parameterNameMap)) { diff --git a/src/Reflection.php b/src/Reflection.php index f5919c34..a7005160 100644 --- a/src/Reflection.php +++ b/src/Reflection.php @@ -44,7 +44,7 @@ public static function reflectClass($class, $argv = false, $namespace = '') throw new Reflection\Exception\InvalidArgumentException('Invalid class or object passed to attachClass()'); } - if ($argv && !is_array($argv)) { + if ($argv && ! is_array($argv)) { throw new Reflection\Exception\InvalidArgumentException('Invalid argv argument passed to reflectClass'); } @@ -70,14 +70,14 @@ public static function reflectClass($class, $argv = false, $namespace = '') */ public static function reflectFunction($function, $argv = false, $namespace = '') { - if (!is_string($function) || !function_exists($function)) { + if (! is_string($function) || ! function_exists($function)) { throw new Reflection\Exception\InvalidArgumentException(sprintf( 'Invalid function "%s" passed to reflectFunction', $function )); } - if ($argv && !is_array($argv)) { + if ($argv && ! is_array($argv)) { throw new Reflection\Exception\InvalidArgumentException('Invalid argv argument passed to reflectFunction'); } diff --git a/src/Reflection/AbstractFunction.php b/src/Reflection/AbstractFunction.php index 33b1e938..679f5557 100644 --- a/src/Reflection/AbstractFunction.php +++ b/src/Reflection/AbstractFunction.php @@ -194,7 +194,7 @@ protected function buildSignatures($return, $returnDesc, $paramTypes, $paramDesc } foreach ($endPoints as $node) { - if (!$node instanceof Node) { + if (! $node instanceof Node) { continue; } @@ -242,7 +242,7 @@ protected function reflect() $paramCount = $function->getNumberOfParameters(); $parameters = $function->getParameters(); - if (!$this->docComment) { + if (! $this->docComment) { $this->docComment = $function->getDocComment(); } @@ -376,7 +376,7 @@ public function setNamespace($namespace) return; } - if (!is_string($namespace) || !preg_match('/[a-z0-9_\.]+/i', $namespace)) { + if (! is_string($namespace) || ! preg_match('/[a-z0-9_\.]+/i', $namespace)) { throw new Exception\InvalidArgumentException('Invalid namespace'); } @@ -402,7 +402,7 @@ public function getNamespace() */ public function setDescription($string) { - if (!is_string($string)) { + if (! is_string($string)) { throw new Exception\InvalidArgumentException('Invalid description'); } diff --git a/src/Reflection/Node.php b/src/Reflection/Node.php index b8460f11..dba7bef4 100644 --- a/src/Reflection/Node.php +++ b/src/Reflection/Node.php @@ -159,7 +159,7 @@ public function setValue($value) public function getEndPoints() { $endPoints = []; - if (!$this->hasChildren()) { + if (! $this->hasChildren()) { return $endPoints; } @@ -170,10 +170,10 @@ public function getEndPoints() $endPoints[] = $this; } elseif ((null !== $value) && $child->hasChildren()) { $childEndPoints = $child->getEndPoints(); - if (!empty($childEndPoints)) { + if (! empty($childEndPoints)) { $endPoints = array_merge($endPoints, $childEndPoints); } - } elseif ((null !== $value) && !$child->hasChildren()) { + } elseif ((null !== $value) && ! $child->hasChildren()) { $endPoints[] = $child; } } diff --git a/src/Reflection/Prototype.php b/src/Reflection/Prototype.php index 69750ae4..1c11f103 100644 --- a/src/Reflection/Prototype.php +++ b/src/Reflection/Prototype.php @@ -31,7 +31,7 @@ public function __construct(ReflectionReturnValue $return, array $params = []) $this->return = $return; foreach ($params as $param) { - if (!$param instanceof ReflectionParameter) { + if (! $param instanceof ReflectionParameter) { throw new Exception\InvalidArgumentException('One or more params are invalid'); } } diff --git a/src/Reflection/ReflectionClass.php b/src/Reflection/ReflectionClass.php index ed45b3aa..310b8d6a 100644 --- a/src/Reflection/ReflectionClass.php +++ b/src/Reflection/ReflectionClass.php @@ -156,7 +156,7 @@ public function setNamespace($namespace) return; } - if (!is_string($namespace) || !preg_match('/[a-z0-9_\.]+/i', $namespace)) { + if (! is_string($namespace) || ! preg_match('/[a-z0-9_\.]+/i', $namespace)) { throw new Exception\InvalidArgumentException('Invalid namespace'); } diff --git a/src/Reflection/ReflectionMethod.php b/src/Reflection/ReflectionMethod.php index 20fb32a6..a483f91f 100644 --- a/src/Reflection/ReflectionMethod.php +++ b/src/Reflection/ReflectionMethod.php @@ -47,9 +47,9 @@ public function __construct(ReflectionClass $class, \ReflectionMethod $r, $names $classNamespace = $class->getNamespace(); // Determine namespace - if (!empty($namespace)) { + if (! empty($namespace)) { $this->setNamespace($namespace); - } elseif (!empty($classNamespace)) { + } elseif (! empty($classNamespace)) { $this->setNamespace($classNamespace); } @@ -126,7 +126,7 @@ private function fetchRecursiveDocComment() // fetch doc blocks from interfaces $interfaceReflectionList = $this->classReflection->getInterfaces(); foreach ($interfaceReflectionList as $interfaceReflection) { - if (!$interfaceReflection->hasMethod($currentMethodName)) { + if (! $interfaceReflection->hasMethod($currentMethodName)) { continue; } @@ -160,11 +160,11 @@ private function fetchRecursiveDocBlockFromParent($reflectionClass, $methodName) { $docComment = []; $parentReflectionClass = $reflectionClass->getParentClass(); - if (!$parentReflectionClass) { + if (! $parentReflectionClass) { return; } - if (!$parentReflectionClass->hasMethod($methodName)) { + if (! $parentReflectionClass->hasMethod($methodName)) { return; } diff --git a/src/Reflection/ReflectionParameter.php b/src/Reflection/ReflectionParameter.php index 730731bb..6302be06 100644 --- a/src/Reflection/ReflectionParameter.php +++ b/src/Reflection/ReflectionParameter.php @@ -89,7 +89,7 @@ public function getType() */ public function setType($type) { - if (!is_string($type) && (null !== $type)) { + if (! is_string($type) && (null !== $type)) { throw new Exception\InvalidArgumentException('Invalid parameter type'); } @@ -115,7 +115,7 @@ public function getDescription() */ public function setDescription($description) { - if (!is_string($description) && (null !== $description)) { + if (! is_string($description) && (null !== $description)) { throw new Exception\InvalidArgumentException('Invalid parameter description'); } diff --git a/src/Reflection/ReflectionReturnValue.php b/src/Reflection/ReflectionReturnValue.php index 3b7e1839..035f279a 100644 --- a/src/Reflection/ReflectionReturnValue.php +++ b/src/Reflection/ReflectionReturnValue.php @@ -59,7 +59,7 @@ public function getType() */ public function setType($type) { - if (!is_string($type) && (null !== $type)) { + if (! is_string($type) && (null !== $type)) { throw new Exception\InvalidArgumentException('Invalid parameter type'); } @@ -85,7 +85,7 @@ public function getDescription() */ public function setDescription($description) { - if (!is_string($description) && (null !== $description)) { + if (! is_string($description) && (null !== $description)) { throw new Exception\InvalidArgumentException('Invalid parameter description'); } From 7806a93142f580c5b3ccf281bfce073fcf85e661 Mon Sep 17 00:00:00 2001 From: Koopzington Date: Thu, 17 Nov 2016 21:52:11 +0100 Subject: [PATCH 8/8] CS fixes --- test/TestAsset/ReflectionTestClass.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/TestAsset/ReflectionTestClass.php b/test/TestAsset/ReflectionTestClass.php index 64a32864..4a712737 100644 --- a/test/TestAsset/ReflectionTestClass.php +++ b/test/TestAsset/ReflectionTestClass.php @@ -43,8 +43,10 @@ public function one($arg1, $arg2 = null) * @param array $arg2 * @return string */ + // @codingStandardsIgnoreStart protected function _one($arg1, $arg2 = null) { + // @codingStandardsIgnoreEnd } /**