diff --git a/composer.json b/composer.json index 5781eadb..f8ab01ea 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": "^7.1", "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", "slevomat/coding-standard": "^4.8.0", - "squizlabs/php_codesniffer": "^3.3.2", + "squizlabs/php_codesniffer": "^3.4.0", "webimpress/coding-standard": "dev-master" }, "extra": { diff --git a/src/ZendCodingStandard/ruleset.xml b/src/ZendCodingStandard/ruleset.xml index ee4eb02b..b29cd359 100644 --- a/src/ZendCodingStandard/ruleset.xml +++ b/src/ZendCodingStandard/ruleset.xml @@ -15,6 +15,15 @@ + + + + + + + + + @@ -34,10 +43,14 @@ + + + + @@ -46,21 +59,70 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -177,6 +239,10 @@ + + + + @@ -201,7 +267,7 @@ - + @@ -224,22 +290,8 @@ - - - - - - - - - - - - - - - - + + @@ -247,21 +299,19 @@ - - - - - - - + + + - - - + + + + + @@ -281,40 +331,40 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + diff --git a/test/expected-report.txt b/test/expected-report.txt index 95a6b918..a90ee1c0 100644 --- a/test/expected-report.txt +++ b/test/expected-report.txt @@ -3,40 +3,43 @@ PHP CODE SNIFFER REPORT SUMMARY ---------------------------------------------------------------------- FILE ERRORS WARNINGS ---------------------------------------------------------------------- -test/fixable/anonymous-classes.php 9 0 -test/fixable/array-indentation.php 39 1 -test/fixable/class-name-resolution.php 13 0 +test/fixable/anonymous-classes.php 11 0 +test/fixable/array-indentation.php 47 1 +test/fixable/class-name-resolution.php 15 0 test/fixable/class-properties.php 6 0 -test/fixable/classes-traits-interfaces.php 13 0 +test/fixable/classes-traits-interfaces.php 17 1 test/fixable/closures.php 19 0 -test/fixable/commenting.php 17 0 -test/fixable/concatenation-spacing.php 15 0 -test/fixable/control-structures.php 5 0 -test/fixable/example-class.php 30 0 -test/fixable/extends-and-implements-multiline.php 10 0 +test/fixable/commenting.php 26 0 +test/fixable/concatenation-spacing.php 21 0 +test/fixable/control-structures.php 6 0 +test/fixable/example-class.php 29 0 +test/fixable/extends-and-implements-multiline.php 13 0 test/fixable/extends-and-implements.php 5 0 -test/fixable/forbidden-comments.php 4 0 +test/fixable/forbidden-comments.php 6 0 test/fixable/forbidden-functions.php 6 0 +test/fixable/heredoc-nowdoc.php 6 0 test/fixable/LowCaseTypes.php 2 0 -test/fixable/method-and-function-arguments.php 11 0 -test/fixable/method-and-function-calls.php 13 0 -test/fixable/namespaces-spacing.php 3 0 +test/fixable/method-and-function-arguments.php 16 0 +test/fixable/method-and-function-calls.php 15 0 +test/fixable/namespaces-spacing.php 7 0 +test/fixable/naming.php 12 0 test/fixable/new-with-parentheses.php 19 0 -test/fixable/not-spacing.php 14 0 -test/fixable/operators.php 9 0 +test/fixable/not-spacing.php 33 1 +test/fixable/operators.php 17 0 test/fixable/return-type-on-methods.php 17 0 -test/fixable/semicolon-spacing.php 3 0 +test/fixable/semicolon-spacing.php 5 0 +test/fixable/spacing.php 18 1 test/fixable/statement-alignment.php 19 0 test/fixable/test-case.php 4 0 test/fixable/traits-uses.php 9 0 test/fixable/UnusedVariables.php 1 0 -test/fixable/useless-semicolon.php 2 0 +test/fixable/useless-semicolon.php 8 0 test/fixable/variable-names.php 5 2 test/fixable/visibility-declaration.php 1 0 ---------------------------------------------------------------------- -A TOTAL OF 323 ERRORS AND 3 WARNINGS WERE FOUND IN 30 FILES +A TOTAL OF 441 ERRORS AND 6 WARNINGS WERE FOUND IN 33 FILES ---------------------------------------------------------------------- -PHPCBF CAN FIX 276 OF THESE SNIFF VIOLATIONS AUTOMATICALLY +PHPCBF CAN FIX 377 OF THESE SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------- diff --git a/test/fixable/anonymous-classes.php b/test/fixable/anonymous-classes.php index 1be99ac4..ba05dc08 100644 --- a/test/fixable/anonymous-classes.php +++ b/test/fixable/anonymous-classes.php @@ -12,8 +12,8 @@ // Brace on the next line $instance = new class() extends \Foo implements \ArrayAccess, - \Countable, - \Serializable + \Countable, + \Serializable { // Class content diff --git a/test/fixable/class-name-resolution.php b/test/fixable/class-name-resolution.php index 5d228873..d14aa244 100644 --- a/test/fixable/class-name-resolution.php +++ b/test/fixable/class-name-resolution.php @@ -37,4 +37,11 @@ public function getMethodWithFullyQualifiedName() : string { return \get_called_class(); } + + public function classNotationInsteadOfString() : string + { + $a = '\PHP_CodeSniffer\Config'; + + return '\ArrayObject'; + } } diff --git a/test/fixable/classes-traits-interfaces.php b/test/fixable/classes-traits-interfaces.php index 38836bae..f4b4b871 100644 --- a/test/fixable/classes-traits-interfaces.php +++ b/test/fixable/classes-traits-interfaces.php @@ -2,6 +2,10 @@ declare(strict_types=1); +namespace FooBar; + +use Arrayobject as AO; + class Foo { @@ -9,16 +13,20 @@ class Foo } -trait Bar +trait BarTrait { public $var; } -interface Baz +interface BazInterface { public function big() : int; } + +new \Datetime(); +new \arrayobject(); +new Ao(); diff --git a/test/fixable/commenting.php b/test/fixable/commenting.php index 53453dc2..a033e8c8 100644 --- a/test/fixable/commenting.php +++ b/test/fixable/commenting.php @@ -115,4 +115,33 @@ private function filterUserInfoPart(string $part) : string // to match and thus prevent double-encoding. return 'foo'; } + + /** + * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod + * tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim + * veniam, quis nostrud exercitation ullamco + * + * @param ConfigInterface|null $config A custom configuration to utilize. An empty configuration is used + * when null is passed or the parameter is omitted. + * @param ContainerInterface|null $container The IoC container to retrieve dependency instances. + * `Zend\Di\DefaultContainer` is used when null is passed or the parameter is omitted. + * @param Definition\DefinitionInterface $definition A custom definition instance for creating requested instances. + * The runtime definition is used when null is passed or the parameter is omitted. + * @param Resolver\DependencyResolverInterface|null $resolver A custom resolver instance to resolve dependencies. + * The default resolver is used when null is passed or the parameter is omitted + * @return array|Traversable|iterable|DateTime[] Aliquam ac sem fringilla + * felis efficitur luctus sit amet in eros. Vestibulum magna purus, + * lobortis vitae scelerisque at, feugiat quis nulla + * @throws InvalidArgumentException Itaque earum rerum hic tenetur a + * sapiente delectus, ut aut reiciendis voluptatibus maiores alias + * consequatur aut perferendis doloribus asperiores repellat + */ + public function multipleLinesComments( + ?ConfigInterface $config = null, + ?ContainerInterface $container = null, + ?Definition\DefinitionInterface $definition = null, + ?Resolver\DependencyResolverInterface $resolver = null + ) : iterable { + return []; + } } diff --git a/test/fixable/control-structures.php b/test/fixable/control-structures.php index 513a9914..b3cbd4f0 100644 --- a/test/fixable/control-structures.php +++ b/test/fixable/control-structures.php @@ -21,3 +21,7 @@ break 2; } } + +if ($a === ($b + 1)) { + echo 1; +} diff --git a/test/fixable/example-class.php b/test/fixable/example-class.php index 70f746e1..ae713685 100644 --- a/test/fixable/example-class.php +++ b/test/fixable/example-class.php @@ -14,6 +14,14 @@ */ class Example implements \IteratorAggregate { + use ATrait, BTrait { + ATrait::functionA as functionA; + } + use CTrait { + hello as hello; + world as protected world; + } + private const VERSION = \PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION; public const ID = 'id'; public const SKU = 'sku'; diff --git a/test/fixable/forbidden-comments.php b/test/fixable/forbidden-comments.php index 24112344..47b0acd4 100644 --- a/test/fixable/forbidden-comments.php +++ b/test/fixable/forbidden-comments.php @@ -1,12 +1,12 @@ process($bar); + } } diff --git a/test/fixable/namespaces-spacing.php b/test/fixable/namespaces-spacing.php index bd14b45d..f8ace32c 100644 --- a/test/fixable/namespaces-spacing.php +++ b/test/fixable/namespaces-spacing.php @@ -17,4 +17,4 @@ ->format(DATE_RFC3339) ); -// new \ Bar \ Baz(); +new \ Bar \ Baz(); diff --git a/test/fixable/naming.php b/test/fixable/naming.php new file mode 100644 index 00000000..bd516a99 --- /dev/null +++ b/test/fixable/naming.php @@ -0,0 +1,25 @@ + [1, 2, 3], + 'longKey' => [111, 222, 333], +]; + +abstract class MyClassSpacing +{ + abstract public function method($x,$y, $z); +} + +$a1 = array_unique([1, 2], [3, 4]); +$a2 = [[1, 2, 3]]; diff --git a/test/fixable/useless-semicolon.php b/test/fixable/useless-semicolon.php index 66149f36..98b93f78 100644 --- a/test/fixable/useless-semicolon.php +++ b/test/fixable/useless-semicolon.php @@ -13,3 +13,13 @@ for (;;) { echo 'To infity and beyond'; }; + +echo 1;; + +$closure = function () { +; +}; + +$anonym = new class() +{ +}; diff --git a/test/fixable/visibility-declaration.php b/test/fixable/visibility-declaration.php index bdba45df..d43700c3 100644 --- a/test/fixable/visibility-declaration.php +++ b/test/fixable/visibility-declaration.php @@ -4,7 +4,7 @@ namespace VisibilityDeclaration; -abstract class ClassName +abstract class AbstractClassName { protected static $foo; diff --git a/test/fixed/array-indentation.php b/test/fixed/array-indentation.php index 4ccaa3d8..7fffc804 100644 --- a/test/fixed/array-indentation.php +++ b/test/fixed/array-indentation.php @@ -59,7 +59,7 @@ App\Http\Auth\LogoutHandler::class => App\Http\Auth\LogoutHandlerFactory::class, App\Infrastructure\View\TemplateDefaultsMiddleware::class - => App\Infrastructure\View\TemplateDefaultsMiddlewareFactory::class, + => App\Infrastructure\View\TemplateDefaultsMiddlewareFactory::class, App\Http\HomePageHandler::class => App\Http\HomePageHandlerFactory::class, App\Http\StaticPageHandler::class => App\Http\StaticPageHandlerFactory::class, ], diff --git a/test/fixed/class-name-resolution.php b/test/fixed/class-name-resolution.php index 0ffdd44b..e17d168a 100644 --- a/test/fixed/class-name-resolution.php +++ b/test/fixed/class-name-resolution.php @@ -37,4 +37,11 @@ public function getMethodWithFullyQualifiedName() : string { return static::class; } + + public function classNotationInsteadOfString() : string + { + $a = PHP_CodeSniffer\Config::class; + + return ArrayObject::class; + } } diff --git a/test/fixed/classes-traits-interfaces.php b/test/fixed/classes-traits-interfaces.php index 10baab4a..2c09c8c4 100644 --- a/test/fixed/classes-traits-interfaces.php +++ b/test/fixed/classes-traits-interfaces.php @@ -2,17 +2,26 @@ declare(strict_types=1); +namespace FooBar; + +use ArrayObject as AO; +use DateTime; + class Foo { public $bar; } -trait Bar +trait BarTrait { public $var; } -interface Baz +interface BazInterface { public function big() : int; } + +new DateTime(); +new AO(); +new AO(); diff --git a/test/fixed/commenting.php b/test/fixed/commenting.php index db40a2b3..c417455c 100644 --- a/test/fixed/commenting.php +++ b/test/fixed/commenting.php @@ -109,4 +109,36 @@ private function filterUserInfoPart(string $part) : string // to match and thus prevent double-encoding. return 'foo'; } + + /** + * Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod + * tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim + * veniam, quis nostrud exercitation ullamco + * + * @param ConfigInterface|null $config A custom configuration to utilize. An empty configuration is used + * when null is passed or the parameter is omitted. + * @param ContainerInterface|null $container The IoC container to retrieve dependency instances. + * `Zend\Di\DefaultContainer` is used when null is + * passed or the parameter is omitted. + * @param Definition\DefinitionInterface $definition A custom definition instance for creating requested instances. + * The runtime definition is used when null is passed or the + * parameter is omitted. + * @param Resolver\DependencyResolverInterface|null $resolver A custom resolver instance to resolve dependencies. + * The default resolver is used when null is passed or + * the parameter is omitted + * @return array|Traversable|iterable|DateTime[] Aliquam ac sem fringilla + * felis efficitur luctus sit amet in eros. Vestibulum magna purus, + * lobortis vitae scelerisque at, feugiat quis nulla + * @throws InvalidArgumentException Itaque earum rerum hic tenetur a + * sapiente delectus, ut aut reiciendis voluptatibus maiores alias + * consequatur aut perferendis doloribus asperiores repellat + */ + public function multipleLinesComments( + ?ConfigInterface $config = null, + ?ContainerInterface $container = null, + ?Definition\DefinitionInterface $definition = null, + ?Resolver\DependencyResolverInterface $resolver = null + ) : iterable { + return []; + } } diff --git a/test/fixed/concatenation-spacing.php b/test/fixed/concatenation-spacing.php index 90b46036..ca611480 100644 --- a/test/fixed/concatenation-spacing.php +++ b/test/fixed/concatenation-spacing.php @@ -17,9 +17,9 @@ $string .= $foo; $string = '1' - . '2' - . '3'; + . '2' + . '3'; -$string = '1' . - '2' . - '3'; +$string = '1' + . '2' + . '3'; diff --git a/test/fixed/control-structures.php b/test/fixed/control-structures.php index 8faacffd..67e9e1b7 100644 --- a/test/fixed/control-structures.php +++ b/test/fixed/control-structures.php @@ -21,3 +21,7 @@ break 2; } } + +if ($a === $b + 1) { + echo 1; +} diff --git a/test/fixed/example-class.php b/test/fixed/example-class.php index dcfe0644..96cf1a3e 100644 --- a/test/fixed/example-class.php +++ b/test/fixed/example-class.php @@ -22,6 +22,12 @@ */ class Example implements IteratorAggregate { + use ATrait; + use BTrait; + use CTrait { + world as protected world; + } + private const VERSION = PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION; public const ID = 'id'; public const SKU = 'sku'; diff --git a/test/fixed/forbidden-comments.php b/test/fixed/forbidden-comments.php index 67029f24..73d6c68e 100644 --- a/test/fixed/forbidden-comments.php +++ b/test/fixed/forbidden-comments.php @@ -4,7 +4,7 @@ namespace Test; -class Foo +class ForbiddenComments { public function __construct() { @@ -22,5 +22,5 @@ public function getBar() : int public function getBaz() : int { return 456; - } -} + } // end getBaz +} // end class diff --git a/test/fixed/heredoc-nowdoc.php b/test/fixed/heredoc-nowdoc.php new file mode 100644 index 00000000..a929db22 --- /dev/null +++ b/test/fixed/heredoc-nowdoc.php @@ -0,0 +1,25 @@ +process($bar); + } } diff --git a/test/fixed/namespaces-spacing.php b/test/fixed/namespaces-spacing.php index 068b129a..8385e1f7 100644 --- a/test/fixed/namespaces-spacing.php +++ b/test/fixed/namespaces-spacing.php @@ -4,6 +4,7 @@ namespace Foo; +use Bar\Baz; use DateInterval; use DateTimeImmutable; use DateTimeZone; @@ -19,4 +20,4 @@ ->format(DATE_RFC3339) ); -// new \ Bar \ Baz(); +new Baz(); diff --git a/test/fixed/naming.php b/test/fixed/naming.php new file mode 100644 index 00000000..bd516a99 --- /dev/null +++ b/test/fixed/naming.php @@ -0,0 +1,25 @@ + [1, 2, 3], + 'longKey' => [111, 222, 333], +]; + +abstract class MyClassSpacing +{ + abstract public function method($x, $y, $z); +} + +$a1 = array_unique([1, 2], [3, 4]); +$a2 = [[1, 2, 3]]; diff --git a/test/fixed/useless-semicolon.php b/test/fixed/useless-semicolon.php index 358277bd..d6ce1d99 100644 --- a/test/fixed/useless-semicolon.php +++ b/test/fixed/useless-semicolon.php @@ -13,3 +13,11 @@ for (;;) { echo 'To infity and beyond'; } + +echo 1; + +$closure = function () { +}; + +$anonym = new class() { +}; diff --git a/test/fixed/visibility-declaration.php b/test/fixed/visibility-declaration.php index bdba45df..d43700c3 100644 --- a/test/fixed/visibility-declaration.php +++ b/test/fixed/visibility-declaration.php @@ -4,7 +4,7 @@ namespace VisibilityDeclaration; -abstract class ClassName +abstract class AbstractClassName { protected static $foo;