From e5aff5af89290ebb61ddac203c502de5276fc462 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Mon, 14 Oct 2019 20:50:35 +0200 Subject: [PATCH 01/20] Update dependencies --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f8ab01ea..5b72b00b 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,9 @@ "require": { "php": "^7.1", "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", - "slevomat/coding-standard": "^4.8.0", - "squizlabs/php_codesniffer": "^3.4.0", - "webimpress/coding-standard": "dev-master" + "slevomat/coding-standard": "^5.0.4", + "squizlabs/php_codesniffer": "^3.5.0", + "webimpress/coding-standard": "^1.0.5" }, "extra": { "branch-alias": { From ecc14c7a03a3a4d4b59debb6f4b0770c50d80d44 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Tue, 15 Oct 2019 13:22:42 +0200 Subject: [PATCH 02/20] Rebase rules on PSR-12 and restructure tests --- src/ZendCodingStandard/ruleset.xml | 870 ++++++++++-------- test/fixable/2.1.BasicCodingStandard.php | 40 + test/fixable/2.2.Files.php | 25 + test/fixable/2.3.Lines.php | 34 + test/fixable/2.4.Indenting.php | 14 + test/fixable/2.5.KeywordsAndTypes.php | 33 + ...StatementsNamespaceAndImportStatements.php | 96 ++ test/fixable/4.1.ExtendsAndImplements.php | 36 + test/fixable/4.2.UsingTraits.php | 36 + test/fixable/4.3.PropertiesAndConstants.php | 39 + test/fixable/4.4.MethodsAndFunctions.php | 33 + .../4.5 .MethodAndFunctionArguments.php | 61 ++ test/fixable/4.6.AbstractFinalAndStatic.php | 24 + test/fixable/4.7.MethodAndFunctionCalls.php | 38 + .../fixable/4.ClassesPropertiesAndMethods.php | 27 + test/fixable/5.1.IfElseifElse.php | 49 + test/fixable/5.2.SwitchCase.php | 54 ++ test/fixable/5.3.WhileAndDoWhile.php | 51 + test/fixable/5.4.ForStructure.php | 31 + test/fixable/5.5.ForEachStructure.php | 17 + test/fixable/5.6.TryCatchFinally.php | 26 + test/fixable/5.ControlStructures.php | 30 + test/fixable/6.1.UnaryOperators.php | 36 + test/fixable/6.2.BinaryOperators.php | 19 + test/fixable/6.3.TernaryOperators.php | 21 + test/fixable/6.Operators.php | 17 + test/fixable/7.Closures.php | 98 ++ test/fixable/8.AnonymousClasses.php | 41 + test/fixable/LowCaseTypes.php | 18 - test/fixable/UnusedVariables.php | 17 - test/fixable/anonymous-classes.php | 21 - test/fixable/array-indentation.php | 65 -- test/fixable/class-name-resolution.php | 47 - test/fixable/class-properties.php | 12 - test/fixable/classes-traits-interfaces.php | 32 - test/fixable/closures.php | 37 - test/fixable/commenting.php | 147 --- test/fixable/concatenation-spacing.php | 25 - test/fixable/control-structures.php | 27 - test/fixable/example-class.php | 101 -- .../extends-and-implements-multiline.php | 20 - test/fixable/extends-and-implements.php | 17 - test/fixable/forbidden-comments.php | 34 - test/fixable/forbidden-functions.php | 30 - test/fixable/heredoc-nowdoc.php | 25 - .../fixable/method-and-function-arguments.php | 51 - test/fixable/method-and-function-calls.php | 23 - test/fixable/namespaces-spacing.php | 20 - test/fixable/naming.php | 25 - test/fixable/new-with-parentheses.php | 37 - test/fixable/not-spacing.php | 57 -- test/fixable/operators.php | 46 - test/fixable/return-type-on-methods.php | 73 -- test/fixable/semicolon-spacing.php | 13 - test/fixable/spacing.php | 30 - test/fixable/statement-alignment.php | 16 - test/fixable/test-case.php | 41 - test/fixable/traits-uses.php | 25 - test/fixable/useless-semicolon.php | 25 - test/fixable/variable-names.php | 31 - test/fixable/visibility-declaration.php | 17 - test/fixed/2.1.BasicCodingStandard.php | 30 + test/fixed/2.2.Files.php | 21 + test/fixed/2.3.Lines.php | 35 + test/fixed/2.4.Indenting.php | 14 + test/fixed/2.5.KeywordsAndTypes.php | 33 + ...StatementsNamespaceAndImportStatements.php | 99 ++ test/fixed/4.1.ExtendsAndImplements.php | 34 + test/fixed/4.2.UsingTraits.php | 36 + test/fixed/4.3.PropertiesAndConstants.php | 39 + test/fixed/4.4.MethodsAndFunctions.php | 31 + .../fixed/4.5 .MethodAndFunctionArguments.php | 61 ++ test/fixed/4.6.AbstractFinalAndStatic.php | 24 + test/fixed/4.7.MethodAndFunctionCalls.php | 40 + test/fixed/4.ClassesPropertiesAndMethods.php | 27 + test/fixed/5.1.IfElseifElse.php | 47 + test/fixed/5.2.SwitchCase.php | 54 ++ test/fixed/5.3.WhileAndDoWhile.php | 53 ++ test/fixed/5.4.ForStructure.php | 28 + test/fixed/5.5.ForEachStructure.php | 17 + test/fixed/5.6.TryCatchFinally.php | 23 + test/fixed/5.ControlStructures.php | 30 + test/fixed/6.1.UnaryOperators.php | 36 + test/fixed/6.2.BinaryOperators.php | 19 + test/fixed/6.3.TernaryOperators.php | 21 + test/fixed/6.Operators.php | 17 + test/fixed/7.Closures.php | 97 ++ test/fixed/8.AnonymousClasses.php | 41 + test/fixed/LowCaseTypes.php | 18 - test/fixed/UnusedVariables.php | 17 - test/fixed/anonymous-classes.php | 20 - test/fixed/array-indentation.php | 67 -- test/fixed/class-name-resolution.php | 47 - test/fixed/class-properties.php | 12 - test/fixed/classes-traits-interfaces.php | 27 - test/fixed/closures.php | 35 - test/fixed/commenting.php | 144 --- test/fixed/concatenation-spacing.php | 25 - test/fixed/control-structures.php | 27 - test/fixed/example-class.php | 97 -- .../extends-and-implements-multiline.php | 18 - test/fixed/extends-and-implements.php | 19 - test/fixed/forbidden-comments.php | 26 - test/fixed/forbidden-functions.php | 30 - test/fixed/heredoc-nowdoc.php | 25 - test/fixed/method-and-function-arguments.php | 51 - test/fixed/method-and-function-calls.php | 21 - test/fixed/namespaces-spacing.php | 23 - test/fixed/naming.php | 25 - test/fixed/new-with-parentheses.php | 37 - test/fixed/not-spacing.php | 52 -- test/fixed/operators.php | 45 - test/fixed/return-type-on-methods.php | 73 -- test/fixed/semicolon-spacing.php | 11 - test/fixed/spacing.php | 30 - test/fixed/statement-alignment.php | 16 - test/fixed/test-case.php | 39 - test/fixed/traits-uses.php | 24 - test/fixed/useless-semicolon.php | 23 - test/fixed/variable-names.php | 31 - test/fixed/visibility-declaration.php | 17 - 121 files changed, 2501 insertions(+), 2779 deletions(-) create mode 100644 test/fixable/2.1.BasicCodingStandard.php create mode 100644 test/fixable/2.2.Files.php create mode 100644 test/fixable/2.3.Lines.php create mode 100644 test/fixable/2.4.Indenting.php create mode 100644 test/fixable/2.5.KeywordsAndTypes.php create mode 100644 test/fixable/3.DeclareStatementsNamespaceAndImportStatements.php create mode 100644 test/fixable/4.1.ExtendsAndImplements.php create mode 100644 test/fixable/4.2.UsingTraits.php create mode 100644 test/fixable/4.3.PropertiesAndConstants.php create mode 100644 test/fixable/4.4.MethodsAndFunctions.php create mode 100644 test/fixable/4.5 .MethodAndFunctionArguments.php create mode 100644 test/fixable/4.6.AbstractFinalAndStatic.php create mode 100644 test/fixable/4.7.MethodAndFunctionCalls.php create mode 100644 test/fixable/4.ClassesPropertiesAndMethods.php create mode 100644 test/fixable/5.1.IfElseifElse.php create mode 100644 test/fixable/5.2.SwitchCase.php create mode 100644 test/fixable/5.3.WhileAndDoWhile.php create mode 100644 test/fixable/5.4.ForStructure.php create mode 100644 test/fixable/5.5.ForEachStructure.php create mode 100644 test/fixable/5.6.TryCatchFinally.php create mode 100644 test/fixable/5.ControlStructures.php create mode 100644 test/fixable/6.1.UnaryOperators.php create mode 100644 test/fixable/6.2.BinaryOperators.php create mode 100644 test/fixable/6.3.TernaryOperators.php create mode 100644 test/fixable/6.Operators.php create mode 100644 test/fixable/7.Closures.php create mode 100644 test/fixable/8.AnonymousClasses.php delete mode 100644 test/fixable/LowCaseTypes.php delete mode 100644 test/fixable/UnusedVariables.php delete mode 100644 test/fixable/anonymous-classes.php delete mode 100644 test/fixable/array-indentation.php delete mode 100644 test/fixable/class-name-resolution.php delete mode 100644 test/fixable/class-properties.php delete mode 100644 test/fixable/classes-traits-interfaces.php delete mode 100644 test/fixable/closures.php delete mode 100644 test/fixable/commenting.php delete mode 100644 test/fixable/concatenation-spacing.php delete mode 100644 test/fixable/control-structures.php delete mode 100644 test/fixable/example-class.php delete mode 100644 test/fixable/extends-and-implements-multiline.php delete mode 100644 test/fixable/extends-and-implements.php delete mode 100644 test/fixable/forbidden-comments.php delete mode 100644 test/fixable/forbidden-functions.php delete mode 100644 test/fixable/heredoc-nowdoc.php delete mode 100644 test/fixable/method-and-function-arguments.php delete mode 100644 test/fixable/method-and-function-calls.php delete mode 100644 test/fixable/namespaces-spacing.php delete mode 100644 test/fixable/naming.php delete mode 100644 test/fixable/new-with-parentheses.php delete mode 100644 test/fixable/not-spacing.php delete mode 100644 test/fixable/operators.php delete mode 100644 test/fixable/return-type-on-methods.php delete mode 100644 test/fixable/semicolon-spacing.php delete mode 100644 test/fixable/spacing.php delete mode 100644 test/fixable/statement-alignment.php delete mode 100644 test/fixable/test-case.php delete mode 100644 test/fixable/traits-uses.php delete mode 100644 test/fixable/useless-semicolon.php delete mode 100644 test/fixable/variable-names.php delete mode 100644 test/fixable/visibility-declaration.php create mode 100644 test/fixed/2.1.BasicCodingStandard.php create mode 100644 test/fixed/2.2.Files.php create mode 100644 test/fixed/2.3.Lines.php create mode 100644 test/fixed/2.4.Indenting.php create mode 100644 test/fixed/2.5.KeywordsAndTypes.php create mode 100644 test/fixed/3.DeclareStatementsNamespaceAndImportStatements.php create mode 100644 test/fixed/4.1.ExtendsAndImplements.php create mode 100644 test/fixed/4.2.UsingTraits.php create mode 100644 test/fixed/4.3.PropertiesAndConstants.php create mode 100644 test/fixed/4.4.MethodsAndFunctions.php create mode 100644 test/fixed/4.5 .MethodAndFunctionArguments.php create mode 100644 test/fixed/4.6.AbstractFinalAndStatic.php create mode 100644 test/fixed/4.7.MethodAndFunctionCalls.php create mode 100644 test/fixed/4.ClassesPropertiesAndMethods.php create mode 100644 test/fixed/5.1.IfElseifElse.php create mode 100644 test/fixed/5.2.SwitchCase.php create mode 100644 test/fixed/5.3.WhileAndDoWhile.php create mode 100644 test/fixed/5.4.ForStructure.php create mode 100644 test/fixed/5.5.ForEachStructure.php create mode 100644 test/fixed/5.6.TryCatchFinally.php create mode 100644 test/fixed/5.ControlStructures.php create mode 100644 test/fixed/6.1.UnaryOperators.php create mode 100644 test/fixed/6.2.BinaryOperators.php create mode 100644 test/fixed/6.3.TernaryOperators.php create mode 100644 test/fixed/6.Operators.php create mode 100644 test/fixed/7.Closures.php create mode 100644 test/fixed/8.AnonymousClasses.php delete mode 100644 test/fixed/LowCaseTypes.php delete mode 100644 test/fixed/UnusedVariables.php delete mode 100644 test/fixed/anonymous-classes.php delete mode 100644 test/fixed/array-indentation.php delete mode 100644 test/fixed/class-name-resolution.php delete mode 100644 test/fixed/class-properties.php delete mode 100644 test/fixed/classes-traits-interfaces.php delete mode 100644 test/fixed/closures.php delete mode 100644 test/fixed/commenting.php delete mode 100644 test/fixed/concatenation-spacing.php delete mode 100644 test/fixed/control-structures.php delete mode 100644 test/fixed/example-class.php delete mode 100644 test/fixed/extends-and-implements-multiline.php delete mode 100644 test/fixed/extends-and-implements.php delete mode 100644 test/fixed/forbidden-comments.php delete mode 100644 test/fixed/forbidden-functions.php delete mode 100644 test/fixed/heredoc-nowdoc.php delete mode 100644 test/fixed/method-and-function-arguments.php delete mode 100644 test/fixed/method-and-function-calls.php delete mode 100644 test/fixed/namespaces-spacing.php delete mode 100644 test/fixed/naming.php delete mode 100644 test/fixed/new-with-parentheses.php delete mode 100644 test/fixed/not-spacing.php delete mode 100644 test/fixed/operators.php delete mode 100644 test/fixed/return-type-on-methods.php delete mode 100644 test/fixed/semicolon-spacing.php delete mode 100644 test/fixed/spacing.php delete mode 100644 test/fixed/statement-alignment.php delete mode 100644 test/fixed/test-case.php delete mode 100644 test/fixed/traits-uses.php delete mode 100644 test/fixed/useless-semicolon.php delete mode 100644 test/fixed/variable-names.php delete mode 100644 test/fixed/visibility-declaration.php diff --git a/src/ZendCodingStandard/ruleset.xml b/src/ZendCodingStandard/ruleset.xml index 16473ebd..7d0129fa 100644 --- a/src/ZendCodingStandard/ruleset.xml +++ b/src/ZendCodingStandard/ruleset.xml @@ -4,429 +4,495 @@ name="ZendCodingStandard"> The ZendFramework coding standard. - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - - + - - - - - - + - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - error - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Variable "%s" not allowed in double quoted string; use sprintf() or concatenation instead - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - - - + + + + + + + + + + + + + + - - + - - - 5 - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/fixable/2.1.BasicCodingStandard.php b/test/fixable/2.1.BasicCodingStandard.php new file mode 100644 index 00000000..ebad51eb --- /dev/null +++ b/test/fixable/2.1.BasicCodingStandard.php @@ -0,0 +1,40 @@ + $b) { + $foo->bar($arg1); + } else { + new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')); + } + } + + final public static function bar() + { + // method body + } +} diff --git a/test/fixable/2.2.Files.php b/test/fixable/2.2.Files.php new file mode 100644 index 00000000..8bd27335 --- /dev/null +++ b/test/fixable/2.2.Files.php @@ -0,0 +1,25 @@ + diff --git a/test/fixable/2.3.Lines.php b/test/fixable/2.3.Lines.php new file mode 100644 index 00000000..46a6ba4e --- /dev/null +++ b/test/fixable/2.3.Lines.php @@ -0,0 +1,34 @@ +sub(new DateInterval('P1D')) + ->format(DATE_RFC3339) + ); + + new Baz(); + } + + public function testDeclareStatement(): void + { + // When wishing to declare strict types in files containing markup + // outside PHP opening and closing tags, the declaration MUST be on the + // first line of the file and include an opening PHP tag, the strict + // types declaration and closing tag. + // + // Declare statements MUST contain no spaces and MUST be exactly + // declare(strict_types=1) (with an optional semi-colon terminator). + // + // Block declare statements are allowed and MUST be formatted as below. + + declare(ticks=1) + { + // some code + } + } +} diff --git a/test/fixable/4.1.ExtendsAndImplements.php b/test/fixable/4.1.ExtendsAndImplements.php new file mode 100644 index 00000000..453e7051 --- /dev/null +++ b/test/fixable/4.1.ExtendsAndImplements.php @@ -0,0 +1,36 @@ +bar( $arg1 ); + Foo::bar( $arg2 , $arg3 ); + } + + public function testArguments(): void + { + // Argument lists MAY be split across multiple lines, where each + // subsequent line is indented once. When doing so, the first item in the + // list MUST be on the next line, and there MUST be only one argument per + // line. A single argument being split across multiple lines (as might be + // the case with an anonymous function or array) does not constitute + // splitting the argument list itself. + + $foo->bar( + $longArgument, $longerArgument, $muchLongerArgument + ); + + $app->get('/hello/{name}', function ($name) use ($app) { + return 'Hello ' . $app->escape($name); + }); + } +} diff --git a/test/fixable/4.ClassesPropertiesAndMethods.php b/test/fixable/4.ClassesPropertiesAndMethods.php new file mode 100644 index 00000000..9c32f9dc --- /dev/null +++ b/test/fixable/4.ClassesPropertiesAndMethods.php @@ -0,0 +1,27 @@ + $value ) + { + echo sprintf('%d - %s', $key, $value); + } + } +} diff --git a/test/fixable/5.6.TryCatchFinally.php b/test/fixable/5.6.TryCatchFinally.php new file mode 100644 index 00000000..ff0b1412 --- /dev/null +++ b/test/fixable/5.6.TryCatchFinally.php @@ -0,0 +1,26 @@ +getMessage(); + } catch ( OtherThrowableType | AnotherThrowableType $e ) { + echo $e->getMessage(); + } finally + { + echo 'Done!'; + } + } +} diff --git a/test/fixable/5.ControlStructures.php b/test/fixable/5.ControlStructures.php new file mode 100644 index 00000000..b5ae68e4 --- /dev/null +++ b/test/fixable/5.ControlStructures.php @@ -0,0 +1,30 @@ +$b) { + $foo=$a+$b*$c; + } + } +} diff --git a/test/fixable/6.3.TernaryOperators.php b/test/fixable/6.3.TernaryOperators.php new file mode 100644 index 00000000..57893d5c --- /dev/null +++ b/test/fixable/6.3.TernaryOperators.php @@ -0,0 +1,21 @@ + 1, - 'bar' => 2, - 'baz' => 3, -]; - -$singleLine = [ - 1 => 2, -]; -$singleLine2 = [ 'foo' => 'bar' ] ; - -$serializedRequest = [ - 'method' => 'POST', - 'request_target' => '/foo/bar?baz=bat', - 'uri' => 'http://example.com/foo/bar?baz=bat', - 'protocol_version' => '1.1', - 'headers' => [ - 'Host' => ['example.com'], - 'Accept' => ['application/json'], - 'X-Foo-Bar' => [ - 'Baz', - 'Bat', - ], - ], - - 'body' => '{"test":"value"}', -]; - -// https://github.com/zendframework/zend-diactoros/blob/69dc20275fb8b9f7f8e05d556f6c0da5f36cac64/test/ServerRequestFactoryTest.php#L392-L398 -$files = [ 'files' => [ - 'tmp_name' => 'php://temp', - 'size' => 0, - 'error' => 0, - 'name' => 'foo.bar', - 'type' => 'text/plain', -]]; - -// Long lines test -$config = [ - 'dependencies' => [ - 'factories' => [ - App\Domain\User\UserRepository::class => App\Domain\User\Persistence\DoctrineUserRepositoryFactory::class, - App\Http\Auth\LoginHandler::class => App\Http\Auth\LoginHandlerFactory::class, - App\Http\Auth\LogoutHandler::class => App\Http\Auth\LogoutHandlerFactory::class, - - App\Infrastructure\View\TemplateDefaultsMiddleware::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/fixable/class-name-resolution.php b/test/fixable/class-name-resolution.php deleted file mode 100644 index d14aa244..00000000 --- a/test/fixable/class-name-resolution.php +++ /dev/null @@ -1,47 +0,0 @@ - 1) { - continue; - } - break 1; -} - -while ($a > 1) { - for ($i = $a; $i < $b; ++$i) { - if ($i % 2) { - continue 1; - } - - break 2; - } -} - -if ($a === ($b + 1)) { - echo 1; -} diff --git a/test/fixable/example-class.php b/test/fixable/example-class.php deleted file mode 100644 index ae713685..00000000 --- a/test/fixable/example-class.php +++ /dev/null @@ -1,101 +0,0 @@ -foo = $foo; - $this->bar = $bar; - $this->baz = $baz; - $this->baxBax = $baxBax; - } - - /** - * Description - */ - public function getFoo(): ? int - { - return $this->foo; - } - - /** - * @return iterable - */ - public function getIterator():array - { - assert($this->bar !== null); - return new \ArrayIterator($this->bar); - } - - public function isBaz() : bool - { - list($foo, $bar, $baz) = $this->bar; - - return $this->baz; - } - - public function mangleBar(int $length) : void - { - if (!$this->baz) { - throw new \InvalidArgumentException(); - } - - $this->bar = (string) $this->baxBax ?? \substr($this->bar, stringLength($this->bar - $length)); - } - - public static function getMinorVersion() : int - { - $version = self::VERSION; - - return $version; - } - - public static function getTestCase() : TestCase - { - return new TestCase(); - } -} diff --git a/test/fixable/extends-and-implements-multiline.php b/test/fixable/extends-and-implements-multiline.php deleted file mode 100644 index d82fa905..00000000 --- a/test/fixable/extends-and-implements-multiline.php +++ /dev/null @@ -1,20 +0,0 @@ - 1, - 'bar' => 2, - 'baz' => 3, -]; -extract($bar); - -compact('foo', 'bar'); diff --git a/test/fixable/heredoc-nowdoc.php b/test/fixable/heredoc-nowdoc.php deleted file mode 100644 index 8d92e1b1..00000000 --- a/test/fixable/heredoc-nowdoc.php +++ /dev/null @@ -1,25 +0,0 @@ -process($bar); - } -} diff --git a/test/fixable/method-and-function-calls.php b/test/fixable/method-and-function-calls.php deleted file mode 100644 index 81f51280..00000000 --- a/test/fixable/method-and-function-calls.php +++ /dev/null @@ -1,23 +0,0 @@ -bar ( $arg1 ); -Foo::bar ($arg2 , $arg3) ; - -$foo->bar( - $longArgument, - $longerArgument, - $muchLongerArgument -); - -somefunction($foo, $bar, [ - // ... -], $baz); - -$app->get ('/hello/{name}' , function ($name) use ($app) { - - return 'Hello ' . $app->escape($name); - -}); diff --git a/test/fixable/namespaces-spacing.php b/test/fixable/namespaces-spacing.php deleted file mode 100644 index f8ace32c..00000000 --- a/test/fixable/namespaces-spacing.php +++ /dev/null @@ -1,20 +0,0 @@ -sub(new DateInterval('P1D')) - ->format(DATE_RFC3339) -); - -new \ Bar \ Baz(); diff --git a/test/fixable/naming.php b/test/fixable/naming.php deleted file mode 100644 index bd516a99..00000000 --- a/test/fixable/naming.php +++ /dev/null @@ -1,25 +0,0 @@ -foo = 'Foo'; -$foo = new $classNamesInObject->foo; - -$whitespaceBetweenClassNameAndParentheses = new stdClass ; - -$x = [ - new stdClass, -]; - -$y = [new stdClass]; - -$z = new stdClass ? new stdClass : new stdClass; - -$q = $q ?: new stdClass; -$e = $e ?? new stdClass; - -// The parentheses around `(new Response())` should not be removed -// https://github.com/slevomat/coding-standard/issues/478 -$response = (new Response()) - ->withStatus(200) - ->withAddedHeader('Content-Type', 'text/plain'); - -$anonymousClass = new class extends DateTime { -}; diff --git a/test/fixable/not-spacing.php b/test/fixable/not-spacing.php deleted file mode 100644 index 43a087c9..00000000 --- a/test/fixable/not-spacing.php +++ /dev/null @@ -1,57 +0,0 @@ - 0) { - echo 1; -} elseif ( !$test === 0) { - echo 0; -} else { - echo 2; -} - -while ( ! true) { - - echo 1; - // comment - -} - -do { - - echo 1; - -} while ( ! true); - -new DateTime(); -new\DateTime(); - - -class SingleLineBetweenMethods -{ - public function __construct() - { - } - public function method() - { - } - - - public function twoLines() - { - } -} - -$a ++; -$b --; --- $c; -++ $d; - -function nullableTypes(? int $int, ? \Complex\Type $ct) : ? string -{ - return function (? bool $b) : ? float { - return 0.0; - }; -} diff --git a/test/fixable/operators.php b/test/fixable/operators.php deleted file mode 100644 index a126e54c..00000000 --- a/test/fixable/operators.php +++ /dev/null @@ -1,46 +0,0 @@ - $b) { - $variable = $foo ? 'foo' : 'bar'; -} - -$foo = isset($_GET['foo']) ? $_GET['foo'] : 'foo'; - -$bar = isset($bar) ? $bar : 'bar'; - -$bar = isset($bar['baz']) ? $bar['baz'] : 'baz'; - -if (isset($foo)) { - $bar = $foo; -} else { - $bar = 'foo'; -} - -$fooBar = isset($foo, $bar) ? 'foo' : 'bar'; - -$baz = ! isset($foo) ? 'foo' : 'baz'; - -echo Something - :: - BAR; - -if ($a && - $b) { - echo 1; -} - -$a ? - $b : - $c; diff --git a/test/fixable/return-type-on-methods.php b/test/fixable/return-type-on-methods.php deleted file mode 100644 index 58bdb665..00000000 --- a/test/fixable/return-type-on-methods.php +++ /dev/null @@ -1,73 +0,0 @@ -select() - ->from() - ->where() -; diff --git a/test/fixable/spacing.php b/test/fixable/spacing.php deleted file mode 100644 index c108bcab..00000000 --- a/test/fixable/spacing.php +++ /dev/null @@ -1,30 +0,0 @@ - [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/statement-alignment.php b/test/fixable/statement-alignment.php deleted file mode 100644 index 14f5a601..00000000 --- a/test/fixable/statement-alignment.php +++ /dev/null @@ -1,16 +0,0 @@ - $b) { + $foo->bar($arg1); + } else { + new DateTimeImmutable('@' . time(), new DateTimeZone('UTC')); + } + } + + final public static function bar() + { + // method body + } +} diff --git a/test/fixed/2.2.Files.php b/test/fixed/2.2.Files.php new file mode 100644 index 00000000..488b471f --- /dev/null +++ b/test/fixed/2.2.Files.php @@ -0,0 +1,21 @@ +sub(new DateInterval('P1D')) + ->format(DATE_RFC3339) + ); + + new Baz(); + } + + public function testDeclareStatement(): void + { + // When wishing to declare strict types in files containing markup + // outside PHP opening and closing tags, the declaration MUST be on the + // first line of the file and include an opening PHP tag, the strict + // types declaration and closing tag. + // + // Declare statements MUST contain no spaces and MUST be exactly + // declare(strict_types=1) (with an optional semi-colon terminator). + // + // Block declare statements are allowed and MUST be formatted as below. + + declare(ticks=1) { + // some code + } + } +} diff --git a/test/fixed/4.1.ExtendsAndImplements.php b/test/fixed/4.1.ExtendsAndImplements.php new file mode 100644 index 00000000..38467282 --- /dev/null +++ b/test/fixed/4.1.ExtendsAndImplements.php @@ -0,0 +1,34 @@ +bar($arg1); + Foo::bar($arg2, $arg3); + } + + public function testArguments(): void + { + // Argument lists MAY be split across multiple lines, where each + // subsequent line is indented once. When doing so, the first item in the + // list MUST be on the next line, and there MUST be only one argument per + // line. A single argument being split across multiple lines (as might be + // the case with an anonymous function or array) does not constitute + // splitting the argument list itself. + + $foo->bar( + $longArgument, + $longerArgument, + $muchLongerArgument + ); + + $app->get('/hello/{name}', function ($name) use ($app) { + return 'Hello ' . $app->escape($name); + }); + } +} diff --git a/test/fixed/4.ClassesPropertiesAndMethods.php b/test/fixed/4.ClassesPropertiesAndMethods.php new file mode 100644 index 00000000..90ab7635 --- /dev/null +++ b/test/fixed/4.ClassesPropertiesAndMethods.php @@ -0,0 +1,27 @@ + $value) { + echo sprintf('%d - %s', $key, $value); + } + } +} diff --git a/test/fixed/5.6.TryCatchFinally.php b/test/fixed/5.6.TryCatchFinally.php new file mode 100644 index 00000000..16c19d9f --- /dev/null +++ b/test/fixed/5.6.TryCatchFinally.php @@ -0,0 +1,23 @@ +getMessage(); + } catch (OtherThrowableType | AnotherThrowableType $e) { + echo $e->getMessage(); + } finally { + echo 'Done!'; + } + } +} diff --git a/test/fixed/5.ControlStructures.php b/test/fixed/5.ControlStructures.php new file mode 100644 index 00000000..b5ae68e4 --- /dev/null +++ b/test/fixed/5.ControlStructures.php @@ -0,0 +1,30 @@ + $b) { + $foo = $a + $b * $c; + } + } +} diff --git a/test/fixed/6.3.TernaryOperators.php b/test/fixed/6.3.TernaryOperators.php new file mode 100644 index 00000000..f2114432 --- /dev/null +++ b/test/fixed/6.3.TernaryOperators.php @@ -0,0 +1,21 @@ + 1, - 'bar' => 2, - 'baz' => 3, -]; - -$singleLine = [ - 1 => 2, -]; -$singleLine2 = ['foo' => 'bar']; - -$serializedRequest = [ - 'method' => 'POST', - 'request_target' => '/foo/bar?baz=bat', - 'uri' => 'http://example.com/foo/bar?baz=bat', - 'protocol_version' => '1.1', - 'headers' => [ - 'Host' => ['example.com'], - 'Accept' => ['application/json'], - 'X-Foo-Bar' => [ - 'Baz', - 'Bat', - ], - ], - - 'body' => '{"test":"value"}', -]; - -// https://github.com/zendframework/zend-diactoros/blob/69dc20275fb8b9f7f8e05d556f6c0da5f36cac64/test/ServerRequestFactoryTest.php#L392-L398 -$files = [ - 'files' => [ - 'tmp_name' => 'php://temp', - 'size' => 0, - 'error' => 0, - 'name' => 'foo.bar', - 'type' => 'text/plain', - ], -]; - -// Long lines test -$config = [ - 'dependencies' => [ - 'factories' => [ - App\Domain\User\UserRepository::class => App\Domain\User\Persistence\DoctrineUserRepositoryFactory::class, - App\Http\Auth\LoginHandler::class => App\Http\Auth\LoginHandlerFactory::class, - App\Http\Auth\LogoutHandler::class => App\Http\Auth\LogoutHandlerFactory::class, - - App\Infrastructure\View\TemplateDefaultsMiddleware::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 deleted file mode 100644 index e17d168a..00000000 --- a/test/fixed/class-name-resolution.php +++ /dev/null @@ -1,47 +0,0 @@ - 1) { - break; - } - break; -} - -while ($a > 1) { - for ($i = $a; $i < $b; ++$i) { - if ($i % 2) { - continue; - } - - break 2; - } -} - -if ($a === $b + 1) { - echo 1; -} diff --git a/test/fixed/example-class.php b/test/fixed/example-class.php deleted file mode 100644 index 96cf1a3e..00000000 --- a/test/fixed/example-class.php +++ /dev/null @@ -1,97 +0,0 @@ -foo = $foo; - $this->bar = $bar; - $this->baz = $baz; - $this->baxBax = $baxBax; - } - - /** - * Description - */ - public function getFoo() : ?int - { - return $this->foo; - } - - /** - * @return iterable - */ - public function getIterator() : array - { - assert($this->bar !== null); - return new ArrayIterator($this->bar); - } - - public function isBaz() : bool - { - [$foo, $bar, $baz] = $this->bar; - - return $this->baz; - } - - public function mangleBar(int $length) : void - { - if (! $this->baz) { - throw new InvalidArgumentException(); - } - - $this->bar = (string) $this->baxBax ?? substr($this->bar, stringLength($this->bar - $length)); - } - - public static function getMinorVersion() : int - { - return self::VERSION; - } - - public static function getTestCase() : TestCase - { - return new TestCase(); - } -} diff --git a/test/fixed/extends-and-implements-multiline.php b/test/fixed/extends-and-implements-multiline.php deleted file mode 100644 index 04e643c5..00000000 --- a/test/fixed/extends-and-implements-multiline.php +++ /dev/null @@ -1,18 +0,0 @@ - 1, - 'bar' => 2, - 'baz' => 3, -]; -extract($bar); - -compact('foo', 'bar'); diff --git a/test/fixed/heredoc-nowdoc.php b/test/fixed/heredoc-nowdoc.php deleted file mode 100644 index a929db22..00000000 --- a/test/fixed/heredoc-nowdoc.php +++ /dev/null @@ -1,25 +0,0 @@ -process($bar); - } -} diff --git a/test/fixed/method-and-function-calls.php b/test/fixed/method-and-function-calls.php deleted file mode 100644 index 5f90cf36..00000000 --- a/test/fixed/method-and-function-calls.php +++ /dev/null @@ -1,21 +0,0 @@ -bar($arg1); -Foo::bar($arg2, $arg3); - -$foo->bar( - $longArgument, - $longerArgument, - $muchLongerArgument -); - -somefunction($foo, $bar, [ - // ... -], $baz); - -$app->get('/hello/{name}', function ($name) use ($app) { - return 'Hello ' . $app->escape($name); -}); diff --git a/test/fixed/namespaces-spacing.php b/test/fixed/namespaces-spacing.php deleted file mode 100644 index 8385e1f7..00000000 --- a/test/fixed/namespaces-spacing.php +++ /dev/null @@ -1,23 +0,0 @@ -sub(new DateInterval('P1D')) - ->format(DATE_RFC3339) -); - -new Baz(); diff --git a/test/fixed/naming.php b/test/fixed/naming.php deleted file mode 100644 index bd516a99..00000000 --- a/test/fixed/naming.php +++ /dev/null @@ -1,25 +0,0 @@ -foo = 'Foo'; -$foo = new $classNamesInObject->foo(); - -$whitespaceBetweenClassNameAndParentheses = new stdClass(); - -$x = [ - new stdClass(), -]; - -$y = [new stdClass()]; - -$z = new stdClass() ? new stdClass() : new stdClass(); - -$q = $q ?: new stdClass(); -$e = $e ?? new stdClass(); - -// The parentheses around `(new Response())` should not be removed -// https://github.com/slevomat/coding-standard/issues/478 -$response = (new Response()) - ->withStatus(200) - ->withAddedHeader('Content-Type', 'text/plain'); - -$anonymousClass = new class() extends DateTime { -}; diff --git a/test/fixed/not-spacing.php b/test/fixed/not-spacing.php deleted file mode 100644 index e69e01c1..00000000 --- a/test/fixed/not-spacing.php +++ /dev/null @@ -1,52 +0,0 @@ - 0) { - echo 1; -} elseif (! $test === 0) { - echo 0; -} else { - echo 2; -} - -while (! true) { - echo 1; - // comment -} - -do { - echo 1; -} while (! true); - -new DateTime(); -new DateTime(); - -class SingleLineBetweenMethods -{ - public function __construct() - { - } - - public function method() - { - } - - public function twoLines() - { - } -} - -$a++; -$b--; ---$c; -++$d; - -function nullableTypes(?int $int, ?Complex\Type $ct) : ?string -{ - return function (?bool $b) : ?float { - return 0.0; - }; -} diff --git a/test/fixed/operators.php b/test/fixed/operators.php deleted file mode 100644 index a85c6fad..00000000 --- a/test/fixed/operators.php +++ /dev/null @@ -1,45 +0,0 @@ - $b) { - $variable = $foo ? 'foo' : 'bar'; -} - -$foo = $_GET['foo'] ?? 'foo'; - -$bar = $bar ?? 'bar'; - -$bar = $bar['baz'] ?? 'baz'; - -if (isset($foo)) { - $bar = $foo; -} else { - $bar = 'foo'; -} - -$fooBar = isset($foo, $bar) ? 'foo' : 'bar'; - -$baz = ! isset($foo) ? 'foo' : 'baz'; - -echo Something::BAR; - -if ($a - && $b -) { - echo 1; -} - -$a - ? $b - : $c; diff --git a/test/fixed/return-type-on-methods.php b/test/fixed/return-type-on-methods.php deleted file mode 100644 index 67c377fa..00000000 --- a/test/fixed/return-type-on-methods.php +++ /dev/null @@ -1,73 +0,0 @@ -select() - ->from() - ->where(); diff --git a/test/fixed/spacing.php b/test/fixed/spacing.php deleted file mode 100644 index cbf4e8ee..00000000 --- a/test/fixed/spacing.php +++ /dev/null @@ -1,30 +0,0 @@ - [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/statement-alignment.php b/test/fixed/statement-alignment.php deleted file mode 100644 index 55cbfbcc..00000000 --- a/test/fixed/statement-alignment.php +++ /dev/null @@ -1,16 +0,0 @@ - Date: Wed, 16 Oct 2019 18:47:18 +0200 Subject: [PATCH 03/20] php_codesniffer ^3.5.1 is required which contains some needed bug fixes --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5b72b00b..cf09de27 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": "^7.1", "dealerdirect/phpcodesniffer-composer-installer": "^0.5.0", "slevomat/coding-standard": "^5.0.4", - "squizlabs/php_codesniffer": "^3.5.0", + "squizlabs/php_codesniffer": "3.x-dev", "webimpress/coding-standard": "^1.0.5" }, "extra": { From 9abf385f354791894f2e4171a644612801db8889 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Wed, 16 Oct 2019 18:48:01 +0200 Subject: [PATCH 04/20] Import additional rules --- src/ZendCodingStandard/ruleset.xml | 211 ++++++++++++++++-- test/fixable/2.1.BasicCodingStandard.php | 141 +++++++++++- test/fixable/2.2.Files.php | 8 + test/fixable/2.3.Lines.php | 72 +++++- test/fixable/2.4.Indenting.php | 2 + test/fixable/2.5.KeywordsAndTypes.php | 2 + test/fixable/2.6.Variables.php | 21 ++ ...StatementsNamespaceAndImportStatements.php | 9 +- test/fixable/4.1.ExtendsAndImplements.php | 2 + test/fixable/4.2.UsingTraits.php | 4 +- test/fixable/4.3.PropertiesAndConstants.php | 2 + test/fixable/4.4.MethodsAndFunctions.php | 25 ++- ...php => 4.5.MethodAndFunctionArguments.php} | 36 ++- test/fixable/4.6.AbstractFinalAndStatic.php | 2 + test/fixable/4.7.MethodAndFunctionCalls.php | 2 + .../fixable/4.ClassesPropertiesAndMethods.php | 93 +++++++- test/fixable/5.1.IfElseifElse.php | 30 ++- test/fixable/5.2.SwitchCase.php | 33 +++ test/fixable/5.3.WhileAndDoWhile.php | 2 + test/fixable/5.4.ForStructure.php | 2 + test/fixable/5.5.ForEachStructure.php | 2 + test/fixable/5.6.TryCatchFinally.php | 34 +++ test/fixable/5.ControlStructures.php | 59 +++++ test/fixable/6.1.UnaryOperators.php | 2 + test/fixable/6.2.BinaryOperators.php | 2 + test/fixable/6.3.TernaryOperators.php | 2 + test/fixable/6.Operators.php | 108 ++++++++- test/fixable/7.Closures.php | 69 ++---- test/fixable/8.AnonymousClasses.php | 2 + test/fixed/2.1.BasicCodingStandard.php | 139 ++++++++++++ test/fixed/2.2.Files.php | 8 + test/fixed/2.3.Lines.php | 41 ++++ test/fixed/2.4.Indenting.php | 2 + test/fixed/2.5.KeywordsAndTypes.php | 2 + test/fixed/2.6.Variables.php | 21 ++ ...StatementsNamespaceAndImportStatements.php | 7 + test/fixed/4.1.ExtendsAndImplements.php | 2 + test/fixed/4.2.UsingTraits.php | 4 +- test/fixed/4.3.PropertiesAndConstants.php | 2 + test/fixed/4.4.MethodsAndFunctions.php | 20 +- ...php => 4.5.MethodAndFunctionArguments.php} | 35 +++ test/fixed/4.6.AbstractFinalAndStatic.php | 2 + test/fixed/4.7.MethodAndFunctionCalls.php | 2 + test/fixed/4.ClassesPropertiesAndMethods.php | 90 +++++++- test/fixed/5.1.IfElseifElse.php | 30 ++- test/fixed/5.2.SwitchCase.php | 33 +++ test/fixed/5.3.WhileAndDoWhile.php | 2 + test/fixed/5.4.ForStructure.php | 2 + test/fixed/5.5.ForEachStructure.php | 2 + test/fixed/5.6.TryCatchFinally.php | 34 +++ test/fixed/5.ControlStructures.php | 58 +++++ test/fixed/6.1.UnaryOperators.php | 2 + test/fixed/6.2.BinaryOperators.php | 2 + test/fixed/6.3.TernaryOperators.php | 2 + test/fixed/6.Operators.php | 103 +++++++++ test/fixed/7.Closures.php | 64 ++---- test/fixed/8.AnonymousClasses.php | 2 + 57 files changed, 1565 insertions(+), 127 deletions(-) create mode 100644 test/fixable/2.6.Variables.php rename test/fixable/{4.5 .MethodAndFunctionArguments.php => 4.5.MethodAndFunctionArguments.php} (72%) create mode 100644 test/fixed/2.6.Variables.php rename test/fixed/{4.5 .MethodAndFunctionArguments.php => 4.5.MethodAndFunctionArguments.php} (75%) diff --git a/src/ZendCodingStandard/ruleset.xml b/src/ZendCodingStandard/ruleset.xml index 7d0129fa..70019630 100644 --- a/src/ZendCodingStandard/ruleset.xml +++ b/src/ZendCodingStandard/ruleset.xml @@ -9,12 +9,80 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -27,6 +95,12 @@ + + + + + + + + + + + + + - @@ -64,6 +148,13 @@ int instead of integer etc. --> + + + + + + + - + + + + + - + - + @@ -146,6 +241,37 @@ even when there are no arguments passed to the constructor. --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - @@ -227,6 +351,12 @@ + + + + @@ -239,6 +369,9 @@ + + + @@ -279,6 +412,8 @@ + + @@ -312,13 +447,23 @@ standardizes how the structures look and reduces the likelihood of introducing errors as new lines get added to the body. --> - - + + + + + + + + + + + @@ -358,6 +503,12 @@ + + + + + + + + + + - @@ -419,7 +575,27 @@ - + + + + + + + + + + + + + + + + + + + @@ -433,11 +609,7 @@ - - - - - + @@ -486,6 +658,11 @@ the two characters. --> + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/expected-report.txt b/test/expected-report.txt index 8b0caef9..71c3efe9 100644 --- a/test/expected-report.txt +++ b/test/expected-report.txt @@ -3,23 +3,23 @@ PHP CODE SNIFFER REPORT SUMMARY ---------------------------------------------------------------------- FILE ERRORS WARNINGS ---------------------------------------------------------------------- -test/fixable/2.1.BasicCodingStandard.php 63 1 +test/fixable/2.1.BasicCodingStandard.php 59 1 test/fixable/2.2.Files.php 4 0 test/fixable/2.3.Lines.php 35 0 test/fixable/2.4.IndentingAndSpacing.php 46 0 -test/fixable/2.5.KeywordsAndTypes.php 8 0 +test/fixable/2.5.KeywordsAndTypes.php 13 0 test/fixable/2.6.Variables.php 3 0 test/fixable/2.7.Arrays.php 9 0 test/fixable/3.DeclareNamespaceAndImport.php 15 0 test/fixable/4.1.ExtendsAndImplements.php 5 0 test/fixable/4.2.UsingTraits.php 6 0 test/fixable/4.3.PropertiesAndConstants.php 5 0 -test/fixable/4.4.MethodsAndFunctions.php 19 0 -test/fixable/4.5.MethodAndFunctionArguments.php 57 0 +test/fixable/4.4.MethodsAndFunctions.php 26 0 +test/fixable/4.5.MethodAndFunctionArguments.php 66 0 test/fixable/4.6.AbstractFinalAndStatic.php 4 0 test/fixable/4.7.MethodAndFunctionCalls.php 11 0 test/fixable/4.ClassesPropertiesAndMethods.php 32 0 -test/fixable/5.1.IfElseifElse.php 13 1 +test/fixable/5.1.IfElseifElse.php 15 1 test/fixable/5.2.SwitchCase.php 11 0 test/fixable/5.3.WhileAndDoWhile.php 12 0 test/fixable/5.4.ForStructure.php 7 0 @@ -32,10 +32,11 @@ test/fixable/6.3.TernaryOperators.php 13 0 test/fixable/6.Operators.php 97 0 test/fixable/7.Closures.php 2 0 test/fixable/8.AnonymousClasses.php 1 0 +test/fixable/9.CommentingAndDocBlocks.php 22 0 ---------------------------------------------------------------------- -A TOTAL OF 545 ERRORS AND 2 WARNINGS WERE FOUND IN 29 FILES +A TOTAL OF 586 ERRORS AND 2 WARNINGS WERE FOUND IN 30 FILES ---------------------------------------------------------------------- -PHPCBF CAN FIX 483 OF THESE SNIFF VIOLATIONS AUTOMATICALLY +PHPCBF CAN FIX 496 OF THESE SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------- diff --git a/test/fixable/2.1.BasicCodingStandard.php b/test/fixable/2.1.BasicCodingStandard.php index d7c365ec..48318cc5 100644 --- a/test/fixable/2.1.BasicCodingStandard.php +++ b/test/fixable/2.1.BasicCodingStandard.php @@ -39,7 +39,7 @@ public function sampleFunction(int $a, int $b = null): array } } - final public static function bar() + final public static function bar(): void { // method body } @@ -120,7 +120,7 @@ public function testSemicolonsUsage(): void $a = $b{0} ; $hello = 1 ;; - $world = $hello ;;; /* comment */ ;;; + $world = $hello ;;; /* comment */ } public function testNonExecutableCodeMMustBeRemoved(int $x): int diff --git a/test/fixable/9.CommentingAndDocBlocks.php b/test/fixable/9.CommentingAndDocBlocks.php new file mode 100644 index 00000000..b99d41c6 --- /dev/null +++ b/test/fixable/9.CommentingAndDocBlocks.php @@ -0,0 +1,100 @@ + + * + * + * + * @internal + * @deprecated + * @link + * @see + * @uses + * @param + * @return + * @throws + */ + public function testDocBlockSpacing(): void + { + } + + public function testInlineCommentMustBeAtTheEnd(): void + { + $hello = $world; /* comment */ + $hello = /* comment */ $world; + } + + /** + * Sets a single-line title. + * + * The `param` and `return` tags should be omitted as they are already + * type hinted. + * + * @param string $title + * @return void + */ + public function setTitle(string $title): void + { + // there should be no docblock here + $this->title = $title; + } + + /** + * All tags can be omitted as typehints describe it all. + * + * @param bool $createNew + * @return stdClass|null + */ + public function foo(bool $createNew): ?stdClass + { + if ($createNew) { + return new stdClass(); + } + return null; + } + + /** + * The returned array should be described with a `return` tag. + * + * @return SQLite3[] $connections + */ + public function testIdeAutoCompletion(): array + { + /** @var SQLite3 $sqlite */ + foreach ($connections as $sqlite) { + // there should be no docblock here + $sqlite->open('/my/database/path'); + } + + return $connections; + } +} diff --git a/test/fixed/2.1.BasicCodingStandard.php b/test/fixed/2.1.BasicCodingStandard.php index 0cb380b5..1b510675 100644 --- a/test/fixed/2.1.BasicCodingStandard.php +++ b/test/fixed/2.1.BasicCodingStandard.php @@ -33,7 +33,7 @@ public function sampleFunction(int $a, ?int $b = null): array } } - final public static function bar() + final public static function bar(): void { // method body } diff --git a/test/fixed/9.CommentingAndDocBlocks.php b/test/fixed/9.CommentingAndDocBlocks.php new file mode 100644 index 00000000..f2ea8cc4 --- /dev/null +++ b/test/fixed/9.CommentingAndDocBlocks.php @@ -0,0 +1,98 @@ + + * + * + * + * @internal + * @deprecated + * + * @link + * @uses + * @see + * + * @param + * + * @return + * + * @throws + */ + public function testDocBlockSpacing(): void + { + } + + public function testInlineCommentMustBeAtTheEnd(): void + { + $hello = $world; /* comment */ + $hello = $world; /* comment */ + } + + /** + * Sets a single-line title. + * + * The `param` and `return` tags should be omitted as they are already + * type hinted. + */ + public function setTitle(string $title): void + { + // there should be no docblock here + $this->title = $title; + } + + /** + * All tags can be omitted as typehints describe it all. + */ + public function foo(bool $createNew): ?stdClass + { + if ($createNew) { + return new stdClass(); + } + return null; + } + + /** + * The returned array should be described with a `return` tag. + * + * @return SQLite3[] $connections + */ + public function testIdeAutoCompletion(): array + { + /** @var SQLite3 $sqlite */ + foreach ($connections as $sqlite) { + // there should be no docblock here + $sqlite->open('/my/database/path'); + } + + return $connections; + } +} From 88d41317458b4594be45ce02f7ee68bb4e853c25 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Thu, 17 Oct 2019 17:48:52 +0200 Subject: [PATCH 11/20] Import ValidLogicalOperators sniff --- src/ZendCodingStandard/ruleset.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ZendCodingStandard/ruleset.xml b/src/ZendCodingStandard/ruleset.xml index 343a46ff..da60dfa4 100644 --- a/src/ZendCodingStandard/ruleset.xml +++ b/src/ZendCodingStandard/ruleset.xml @@ -639,6 +639,8 @@ + + From a2bdc2057b404360126f704bd08ad4e194f45403 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Thu, 17 Oct 2019 21:23:52 +0200 Subject: [PATCH 12/20] Update documentation --- docs/book/v2/coding-style-guide.md | 1402 +++++++++++++++++++++++----- docs/book/v2/ruleset.md | 1166 ----------------------- mkdocs.yml | 2 - src/ZendCodingStandard/ruleset.xml | 5 +- 4 files changed, 1190 insertions(+), 1385 deletions(-) delete mode 100644 docs/book/v2/ruleset.md diff --git a/docs/book/v2/coding-style-guide.md b/docs/book/v2/coding-style-guide.md index 777896bf..7d4bd8f4 100644 --- a/docs/book/v2/coding-style-guide.md +++ b/docs/book/v2/coding-style-guide.md @@ -1,192 +1,822 @@ -# Zend Framework Coding Style Guide +# ZendFramework Coding Style Guide -This specification extends and expands [PSR-12](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md), -the extended coding style guide and requires adherence to [PSR-1](https://www.php-fig.org/psr/psr-1), -the basic coding standard. +The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", +"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be +interpreted as described in [RFC 2119][]. -> Note: PSR-12 is not finalized. e.g. The `!` operator and `:` placement for return values are still under discussion. -We will change these rules, and, when PSR-12 is finalized, adapt them. +[RFC 2119]: http://tools.ietf.org/html/rfc2119 -## General +## Overview -### Basic Coding Standard +This specification extends [PSR-12][], the coding style guide and +requires adherence to [PSR-1][], the basic coding standard. -Code MUST follow all rules outlined in [PSR-1](https://www.php-fig.org/psr/psr-1) and -[PSR-12](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md), except in -specific cases outlined in this specification, until PSR-12 is accepted as a standard. +Like [PSR-12][], the intent of this specification is to reduce cognitive friction when +scanning code from different authors contributing to ZendFramework. It does so by +enumerating a shared set of rules and expectations about how to format PHP code. -### Indenting and Alignment +### Previous language versions -- There should be one space on either side of an equals sign used to assign a value to a variable. In case of a - block of related assignments, more space may be inserted before the equal sign to promote readability. - [*](ruleset.md#genericformattingmultiplestatementalignment) +Throughout this document, any instructions MAY be ignored if they do not exist in versions +of PHP supported by your project. -```php +### Example + +This example encompasses some of the rules below as a quick overview: + +~~~php 'value1', - 'key2' => 'value2', - 'keyTwenty' => 'value3', -]; - -$var = [ - 'one' => function() { - $foo = [1,2,3]; - $barBar = [ - 1, - 2, - 3, - ]; - }, - 'longer' => 2, - /* three */ 3 => 'three', -]; -``` +use function Vendor\Package\{functionA, functionB, functionC}; -### PHP Keywords, Types, Constants and Functions - -- The `global` keyword may not be used. [*](ruleset.md#squizphpglobalkeyword) -- The `PHP_SAPI` constant must be used instead of the `php_sapi_name()` function. [*](ruleset.md#genericphpsapiusage) -- PHP function calls must be in lowercase. [*](ruleset.md#squizphplowercasephpfunctions) -- PHP functions which are an alias may not be used. [*](ruleset.md#genericphpforbiddenfunctions) -- Deprecated functions should not be used. [*](ruleset.md#genericphpdeprecatedfunctions) - -### Commenting - -- Comments may be omitted and should not be used for typehinted arguments. -- Comments may not start with `#`. [*](ruleset.md#pearcommentinginlinecomment) -- Comments may not be empty. [*](ruleset.md#slevomatcodingstandardcommentingemptycomment) -- The words _private_, _protected_, _static_, _constructor_, _deconstructor_, _Created by_, _getter_ and _setter_, - may not be used in comments. [*](ruleset.md#slevomatcodingstandardcommentingforbiddencomments) -- The annotations `@api`, `@author`, `@category`, `@created`, `@package`, `@subpackage` and `@version` may not - be used in comments. Git commits provide accurate information. [*](ruleset.md#slevomatcodingstandardcommentingforbiddenannotations) -- The asterisks in a doc comment should align, and there should be one space between the asterisk and tag. - [*](ruleset.md#squizcommentingdoccommentalignment) -- Comment tags `@param`, `@throws` and `@return` should not be aligned or contain multiple spaces between the tag, - type and description. [*](ruleset.md#squizcommentingfunctioncomment) -- If a function throws any exceptions, they should be documented in `@throws` tags. - [*](ruleset.md#squizcommentingfunctioncomment) -- The `@var` tag may be used in inline comments to document the _Type_ of properties. [*](ruleset.md#slevomatcodingstandardcommentinginlinedoccommentdeclaration) -- Single-line comments with a `@var` tag should be written as one-liners. [*](ruleset.md#slevomatcodingstandardcommentingrequireonelinepropertydoccomment) -- Shorthand scalar typehint variants must be used in docblocks. [*](ruleset.md#slevomatcodingstandardtypehintslongtypehints) - -## Declare Statements, Namespace, and Import Statements - -In addition to [PSR-12](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md#3-declare-statements-namespace-and-import-statements): - -- Each PHP file should have a page level docblock with `@see`, `@copyright` and `@license`. The copyright date should - only be adjusted if the file has changed. -- Each PHP file should have a strict type declaration at the top after the page level docblock. [*](ruleset.md#slevomatcodingstandardtypehintsdeclarestricttypes) -- Import statements should be alphabetically sorted. [*](ruleset.md#webimpresscodingstandardphpinstantiatingparenthesis) -- Import statements should not be grouped. [*](ruleset.md#slevomatcodingstandardnamespacesdisallowgroupuse) -- Each import statement should be on its own line. [*](ruleset.md#slevomatcodingstandardnamespacesmultipleusesperline) -- Absolute class name references, functions and constants should be imported. [*](ruleset.md#slevomatcodingstandardnamespacesreferenceusednamesonly) -- Unused import statements are not allowed. [*](ruleset.md#webimpresscodingstandardnamespacesunusedusestatement) -- Classes and function within the same namespace should not be imported. [*](ruleset.md#webimpresscodingstandardnamespacesunusedusestatement) -- Imports should not have an alias with the same name. [*](ruleset.md#slevomatcodingstandardnamespacesuselessalias) -- A class should not have unused private constants, (or write-only) properties and methods. [*](ruleset.md#slevomatcodingstandardclassesunusedprivateelements) +use const Vendor\Package\{ConstantA, ConstantB, ConstantC}; -```php +class Foo extends Bar implements FooInterface +{ + public function sampleFunction(int $a, int $b = null): array + { + if ($a === $b) { + bar(); + } elseif ($a > $b) { + $foo->bar($arg1); + } else { + BazClass::bar($arg2, $arg3); + } + } + + final public static function bar() + { + // method body + } +} +~~~ + +## 2. General + +### 2.1 Basic Coding Standard + +Code MUST follow all rules outlined in [PSR-1]. + +The term 'StudlyCaps' in PSR-1 MUST be interpreted as PascalCase where the first letter of +each word is capitalized including the very first letter. + +> **Additional ZendFramework rules** +> +> There MAY NOT be any content before the opening tag. +> +> The short open tag MAY NOT be used. +> +> There MAY NOT be any inline HTML in PHP code. +> +> Deprecated PHP functions MUST be avoided. +> +> The backtick operator MAY NOT be used. +> +> The PHP `goto` language construct MAY NOT be used. +> +> The `global` keyword MAY NOT be used. +> +> The constant `PHP_SAPI` SHOULD be used instead of the `php_sapi_name()` function. +> +> Alias functions SHOULD NOT be used. +> +> There MAY NOT be a space before a semicolon. Redundant semicolons SHOULD be avoided. +> +> Non executable code MUST be removed. +> +> There MUST be a single space after language constructs. +> +> Parentheses MUST be omitted where possible. +> +> PHP function calls MUST be in lowercase. + +### 2.2 Files + +All PHP files MUST use the Unix LF (linefeed) line ending only. + +All PHP files MUST end with a non-blank line, terminated with a single LF. + +The closing `?>` tag MUST be omitted from files containing only PHP. + +> **Additional ZendFramework rules** +> +> The `declare(strict_types=1)` directive MUST be declared and be the first +> statement in a file. + +### 2.3 Lines + +There MUST NOT be a hard limit on line length. + +The soft limit on line length MUST be 120 characters. + +Lines SHOULD NOT be longer than 80 characters; lines longer than that SHOULD +be split into multiple subsequent lines of no more than 80 characters each. + +There MUST NOT be trailing whitespace at the end of lines. + +Blank lines MAY be added to improve readability and to indicate related +blocks of code except where explicitly forbidden. + +There MUST NOT be more than one statement per line. + +> **Additional ZendFramework rules** +> +> There MAY be maximum one blank line to improve readability and to indicate +> related blocks of code except where explicitly forbidden. +> +> There MAY NOT be any blank line after opening braces and before closing braces. + +### 2.4 Indenting and Spacing + +Code MUST use an indent of 4 spaces for each indent level, and MUST NOT use +tabs for indenting. + +> **Additional ZendFramework rules** +> +> Encapsed strings MAY be used instead of concatenating strings. When +> concatenating strings, there MUST be a single whitespace before and after the +> concatenation operator. The concatenation operator MAY NOT be the at the end +> of a line. + +### 2.5 Keywords and Types + +All PHP reserved keywords and types [[1]][keywords][[2]][types] MUST be in lower case. + +Any new types and keywords added to future PHP versions MUST be in lower case. + +Short form of type keywords MUST be used i.e. `bool` instead of `boolean`, +`int` instead of `integer` etc. + +### 2.6 Variables + +> **Additional ZendFramework rules** +> +> Variable names MUST be declared in camelCase. + +### 2.7 Arrays + +> **Additional ZendFramework rules** +> +> The short array syntax MUST be used to define arrays. +> +> All values in multiline arrays must be indented with 4 spaces. +> +> All array values must be followed by a comma, including the last value. +> +> There MUST be no whitespace around the opening bracket or before the closing +> bracket when referencing an array. +> +> All double arrow symbols MUST be aligned to one space after the longest array +> key. +> +> The short list syntax `[...]` SHOULD be used instead of `list(...)`. + +## 3. Declare Statements, Namespace, and Import Statements + +The header of a PHP file may consist of a number of different blocks. If present, +each of the blocks below MUST be separated by a single blank line, and MUST NOT contain +a blank line. Each block MUST be in the order listed below, although blocks that are +not relevant may be omitted. + +* Opening ` + + + + + +~~~ + +Declare statements MUST contain no spaces and MUST be exactly `declare(strict_types=1)` +(with an optional semi-colon terminator). + +Block declare statements are allowed and MUST be formatted as below. Note position of +braces and spacing: +~~~php +declare(ticks=1) { + // some code +} +~~~ + +> **Additional ZendFramework rules** +> +> There MUST be a single space after the namespace keyword. +> +> There MAY NOT be a space around a namespace separator. +> +> Import statements MUST be alphabetically sorted. +> +> Functions and const keywords MUST be lowercase in import statements. +> +> Unused import statements MUST be removed. +> +> Superfluous leading backslash in import statements MUST be removed. +> +> Fancy group import statements are not allowed. +> +> Each import statements MUST be on its own line. +> +> Import statements must be grouped (classes, functions, constants) and +> MUST be separated by empty lines. +> +> Import statements aliases for classes, traits, functions and constants +> MUST be useful. +> +> Classes, traits, interfaces, constants and functions MUST be imported. + +## 4. Classes, Properties, and Methods + +The term "class" refers to all classes, interfaces, and traits. + +Any closing brace MUST NOT be followed by any comment or statement on the +same line. + +When instantiating a new class, parentheses MUST always be present even when +there are no arguments passed to the constructor. + +~~~php +new Foo(); +~~~ + +> **Additional ZendFramework rules** +> +> There MAY NOT be duplicate class names. +> +> The file name MUST match the case of the terminating class name. +> +> PHP 4 style constructors SHOULD NOT be used. +> +> The correct class names MUST be used. +> +> Abstract classes MUST have a `Abstract` prefix. +> +> Exception classes MUST have a `Exception` suffix. +> +> Interface classes MUST have a `Interface` suffix. +> +> Trait classes MUST have a `Trait` suffix. +> +> For self-reference a class lower-case `self::` MUST be used without spaces +> around the scope resolution operator. +> +> Class name resolution via `::class` MUST be used instead of `__CLASS__`, +> `get_class()`, `get_class($this)`, `get_called_class()`, `get_parent_class()` +> and string reference. +> +> There MAY NOT be any whitespace around the double colon operator. +> +> Unused private methods, constants and properties MUST be removed. + +### 4.1 Extends and Implements + +The `extends` and `implements` keywords MUST be declared on the same line as +the class name. + +The opening brace for the class MUST go on its own line; the closing brace +for the class MUST go on the next line after the body. + +Opening braces MUST be on their own line and MUST NOT be preceded or followed +by a blank line. + +Closing braces MUST be on their own line and MUST NOT be preceded by a blank +line. + +~~~php + **Additional ZendFramework rules** +> +> Traits MUST be sorted alphabetically. + +~~~php **Additional ZendFramework rules** +> +> Default null values MUST be omitted for class properties. + +A property declaration looks like the following: + +~~~php + **Additional ZendFramework rules** +> +> There MUST be a single empty line between methods in a class. +> +> The pseudo-variable `$this` MAY not be called inside a static method or +> function. +> +> Returned variables SHOULD be useful and not be assign to a value and +> returned on the next line. + +### 4.5 Method and Function Arguments + +In the argument list, there MUST NOT be a space before each comma, and there +MUST be one space after each comma. + +Method and function arguments with default values MUST go at the end of the argument +list. + +~~~php + **Additional ZendFramework rules** +> +> The question mark MUST be used when the default argument value is null. + +~~~php + **Additional ZendFramework rules** +> +> The final keyword on methods MUST be omitted in final classes. + +### 4.7 Method and Function Calls + +When making a method or function call, there MUST NOT be a space between the +method or function name and the opening parenthesis, there MUST NOT be a space +after the opening parenthesis, and there MUST NOT be a space before the +closing parenthesis. In the argument list, there MUST NOT be a space before +each comma, and there MUST be one space after each comma. + +~~~php +bar($arg1); +Foo::bar($arg2, $arg3); +~~~ + +Argument lists MAY be split across multiple lines, where each subsequent line +is indented once. When doing so, the first item in the list MUST be on the +next line, and there MUST be only one argument per line. A single argument being +split across multiple lines (as might be the case with an anonymous function or +array) does not constitute splitting the argument list itself. + +~~~php +bar( + $longArgument, + $longerArgument, + $muchLongerArgument +); +~~~ + +~~~php +get('/hello/{name}', function ($name) use ($app) { + return 'Hello ' . $app->escape($name); +}); +~~~ + +## 5. Control Structures + +The general style rules for control structures are as follows: + +- There MUST be one space after the control structure keyword +- There MUST NOT be a space after the opening parenthesis +- There MUST NOT be a space before the closing parenthesis +- There MUST be one space between the closing parenthesis and the opening + brace +- The structure body MUST be indented once +- The body MUST be on the next line after the opening brace +- The closing brace MUST be on the next line after the body + +The body of each structure MUST be enclosed by braces. This standardizes how +the structures look and reduces the likelihood of introducing errors as new +lines get added to the body. + +> **Additional ZendFramework rules** +> +> There MUST be one single space after `break` and `continue` structures with +> a numeric argument argument. +> +> Statements MAY NOT be empty, except for catch statements. --> + +### 5.1 `if`, `elseif`, `else` + +An `if` structure looks like the following. Note the placement of parentheses, +spaces, and braces; and that `else` and `elseif` are on the same line as the +closing brace from the earlier body. + +~~~php **Additional ZendFramework rules** +> +> The `continue` control structure MAY NOT be used in switch statements, +> `break` SHOULD be used instead. + +~~~php $value) { // foreach body } -``` +~~~ -### try, catch, finally +### 5.6 `try`, `catch`, `finally` -- Catch blocks may be empty. [*](ruleset.md#genericcodeanalysisemptystatementdetectedcatch) -- Catch blocks must be reachable. [*](ruleset.md#slevomatcodingstandardexceptionsdeadcatch) -- Catch blocks must use `Throwable` instead of `Exception`. [*](ruleset.md#slevomatcodingstandardexceptionsreferencethrowableonly) +A `try-catch-finally` block looks like the following. Note the placement of +parentheses, spaces, and braces. -```php +~~~php **Additional ZendFramework rules** +> +> All catch blocks MUST be reachable. +> +> Catch blocks SHOULD catch `Throwable` instead of `Exception` unless intended. -```php +~~~php **Additional ZendFramework rules** +> +> There MUST be at least one space on either side of an equals sign used +> to assign a value to a variable. In case of a block of related +> assignments, more spaces MUST be inserted before the equal sign to +> promote readability. +> +> There MAY NOT be any white space around the object operator unless +> multilines are used. +> +> There MAY NOT be spaces around the object operator. +> +> Loose comparison operators SHOULD NOT be used, use strict comparison +> operators instead. +> +> The null coalesce operator MUST be used when possible. +> +> Assignment operators SHOULD be used when possible. +> +> The `&&` and `||` operators SHOULD be used instad of `and` and `or`. + +All operators not described here are left undefined. + +### 6.1. Unary operators + +The increment/decrement operators MUST NOT have any space between +the operator and operand. +~~~php +$i++; +++$j; +~~~ + +Type casting operators MUST NOT have any space within the parentheses: + +> **Additional ZendFramework rules** +> +> There MUST be one whitespace after a type casting operator. + +~~~php +$intValue = (int) $input; +~~~ + +> **Additional ZendFramework rules** +> +> There MUST be one whitespace after unary not. + +### 6.2. Binary operators + +All binary [arithmetic][], [comparison][], [assignment][], [bitwise][], +[logical][], [string][], and [type][] operators MUST be preceded and +followed by at least one space: +~~~php if ($a === $b) { $foo = $bar ?? $a ?? $b; -} elseif (! $a || $b > $c) { - $variable = $foo ? 'foo' : 'bar'; +} elseif ($a > $b) { + $foo = $a + $b * $c; } +~~~ -$var = 'foo'; -$aVeryLongName = 'bar'; -$function = function ($arg1, $arg2) {}; -``` +### 6.3. Ternary operators -## Closures +The conditional operator, also known simply as the ternary operator, MUST be +preceded and followed by at least one space around both the `?` +and `:` characters: +~~~php +$variable = $foo ? 'foo' : 'bar'; +~~~ -In addition to [PSR-12](https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md#7-closures): +When the middle operand of the conditional operator is omitted, the operator +MUST follow the same style rules as other binary [comparison][] operators: +~~~php +$variable = $foo ?: 'bar'; +~~~ -- Unused variables should not be passed to closures via `use`. [*](ruleset.md#slevomatcodingstandardfunctionsunusedinheritedvariablepassedtoclosure) +## 7. Closures -```php +Closures MUST be declared with a space after the `function` keyword, and a +space before and after the `use` keyword. + +The opening brace MUST go on the same line, and the closing brace MUST go on +the next line following the body. + +There MUST NOT be a space after the opening parenthesis of the argument list +or variable list, and there MUST NOT be a space before the closing parenthesis +of the argument list or variable list. + +In the argument list and variable list, there MUST NOT be a space before each +comma, and there MUST be one space after each comma. + +Closure arguments with default values MUST go at the end of the argument +list. + +If a return type is present, it MUST follow the same rules as with normal +functions and methods; if the `use` keyword is present, the colon MUST follow +the `use` list closing parentheses with no spaces between the two characters. + +> **Additional ZendFramework rules** +> +> Inherited variables passed via `use` MUST be used in closures. + +A closure declaration looks like the following. Note the placement of +parentheses, commas, spaces, and braces: + +~~~php bar( + $arg1, + function ($arg2) use ($var1) { + // body + }, + $arg3 +); +~~~ + +## 8. Anonymous Classes + +Anonymous Classes MUST follow the same guidelines and principles as closures +in the above section. + +~~~php ` should not have any spaces around it. [*](ruleset.md#squizwhitespaceobjectoperatorspacing) -- Semicolons should not have spaces before them. [*](ruleset.md#squizwhitespacesemicolonspacing) -- The code should not contain superfluous whitespaces. e.g. multiple empty lines, trailing spaces, etc. [*](ruleset.md#squizwhitespacesuperfluouswhitespace) +~~~ + +## 9. Commenting and DocBlocks + +> **Additional ZendFramework rules** +> +> DocBlocks and comments SHOULD only be used if necessary. Code SHOULD +> be written so it explains itself. They MAY NOT start with `#` and MAY +> NOT be empty. They MAY be omitted and SHOULD NOT be used for already +> typehinted arguments, except arrays. +> +> PHPDoc tags `@param`, `@throws` and `@return` SHOULD not be aligned or +> contain multiple spaces between the tag, type and description. +> +> If a function throws any exceptions, it SHOULD be documented with +> `@throws` tags. +> +> The asterisks in a DocBlock should align, and there should be one +> space between the asterisk and tag. +> +> DocBlocks MUST follow this specific order of annotations with empty +> newline between specific groups: +> +> ```php +> /** +> * +> * +> * +> * +> * @internal +> * @deprecated +> * +> * @link +> * @see +> * @uses +> * +> * @param +> * +> * @return +> * +> * @throws +> */ +> ``` +> +> The annotations `@api`, `@author`, `@category`, `@created`, `@package`, +> `@subpackage` and `@version` may not be used in comments. Git commits +> provide accurate information. +> +> The words _private_, _protected_, _static_, _constructor_, _deconstructor_, +> _Created by_, _getter_ and _setter_, MAY NOT be used in comments. +> +> The `@var` tag MAY be used in inline comments to document the _Type_ +> of properties. Single-line property comments with a `@var` tag SHOULD +> be written as one-liners. The `@var` MAY NOT be used for constants. +> +> The correct tag case of PHPDocs and PHPUnit tags MUST be used. +> +> Inline DocComments MAY be used at the end of the line, with at least a +> single space. Inline DocComments MAY NOT be placed after curly brackets. +> +> Typed parameters and return types SHOULD be avoided. +> +> Heredoc and nowdoc tags MUST be uppercase without spaces. + +[PSR-1]: https://www.php-fig.org/psr/psr-1/ +[PSR-2]: https://www.php-fig.org/psr/psr-2/ +[PSR-12]: https://www.php-fig.org/psr/psr-12/ +[keywords]: https://www.php.net/manual/en/reserved.keywords.php +[types]: https://www.php.net/manual/en/reserved.other-reserved-words.php +[arithmetic]: https://www.php.net/manual/en/language.operators.arithmetic.php +[assignment]: https://www.php.net/manual/en/language.operators.assignment.php +[comparison]: https://www.php.net/manual/en/language.operators.comparison.php +[bitwise]: https://www.php.net/manual/en/language.operators.bitwise.php +[logical]: https://www.php.net/manual/en/language.operators.logical.php +[string]: https://www.php.net/manual/en/language.operators.string.php +[type]: https://www.php.net/manual/en/language.operators.type.php diff --git a/docs/book/v2/ruleset.md b/docs/book/v2/ruleset.md deleted file mode 100644 index 7b4b830d..00000000 --- a/docs/book/v2/ruleset.md +++ /dev/null @@ -1,1166 +0,0 @@ -# Ruleset - -## PSR2 -Use PSR-2 coding standard as a base - -### PSR2.ControlStructures.ElseIfDeclaration.NotAllowed -_PSR-12:_ The keyword `elseif` should be used instead of `else if` so that all control keywords look like single words. - - - -## Generic - -### Generic.Arrays.ArrayIndent -All values in multiline arrays must be indented with 4 spaces. - -### Generic.Arrays.DisallowLongArraySyntax -Short array syntax must be used to define arrays. - -```php - 'bar']; -``` - -### Generic.Classes.DuplicateClassName -Class and Interface names should be unique in a project and must have a unique fully qualified name. They should never -be duplicated. - -*Valid: Unique class names.* -```php - 0; $i--) { - echo 'hello'; -} -``` - -*Invalid:* -```php -some string here -Beginning content -` tags or the short-echo `` tags; it must not use the other tag -variations. - -### Generic.PHP.DiscourageGoto -Forbid goto instruction. - -### Generic.PHP.ForbiddenFunctions -PHP functions which are an alias may not be used. _This can't be fixed automatically and need to be done manually._ - -| Alias | Replace with | -| ------------ | ---------------- | -| chop | rtrim | -| close | closedir | -| compact | | -| delete | unset | -| doubleval | floatval | -| extract | | -| fputs | fwrite | -| ini_alter | ini_set | -| is_integer | is_int | -| is_long | is_int | -| is_null | null === | -| is_real | is_float | -| is_writeable | is_writable | -| join | implode | -| key_exists | array_key_exists | -| pos | current | -| settype | | -| show_source | highlight_file | -| sizeof | count | -| strchr | strstr | - -### Generic.PHP.LowerCaseType -_PSR-12:_ Any new types and keywords added to future PHP versions must be in lower case. - -### Generic.PHP.SAPIUsage -The `PHP_SAPI` constant must be used instead of the `php_sapi_name()` function. - -*Valid: PHP_SAPI is used.* -```php -get(); - } -} -``` - -### SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment -Single-line comments with a `@var` tag should be written as one-liners. - -*Valid: One-line comment* -```php -a >>= 2; -$this->$$parameter ^= 10; -$this->{'a'} += 10; -``` - -### SlevomatCodingStandard.PHP.ShortList -Short list syntax `[...]` should be used instead of `list(...)`. - -*Valid: The short list syntax is used for array destructuring assignment.* -```php - $a, 'b' => $b, 'c' => $c] = $array; -``` - -*Invalid: Usage of `list`.* -```php - $a, 'b' => $b, 'c' => $c) = $array; -``` - -### SlevomatCodingStandard.PHP.TypeCast -_PSR-12:_ Short form of type keywords must be used. i.e. `bool` instead of `boolean`, `int` instead of `integer`, etc. - -The `binary` and `unset` cast operators are not allowed. - -### SlevomatCodingStandard.TypeHints.DeclareStrictTypes -Each PHP file should have a strict type declaration at the top after the page level docblock. - -_PSR-12:_ Declare statements MUST contain no spaces and MUST be exactly `declare(strict_types=1)`. - -```php - true, - 'debug' => false, - 'zend-expressive' => [ - 'raise_throwables' => true, - 'programmatic_pipeline' => true, - 'error_handler' => [ - 'template_404' => 'error::404', - 'template_error' => 'error::error', - ], - ], -]; -``` - -*Invalid: Double arrow symbols are not aligned.* -```php - true, - 'debug' => false, - 'zend-expressive' => [ - 'raise_throwables' => true, - 'programmatic_pipeline' => true, - 'error_handler' => [ - 'template_404' => 'error::404', - 'template_error' => 'error::error', - ], - ], -]; -``` - -### Squiz.Classes.ClassFileName -_PSR-4:_ The class name must correspond to a file name ending in .php. The file name MUST match the case of the -terminating class name. - -### Squiz.Classes.SelfMemberReference -The `self` keyword should be used instead of the current class name, and should not have spaces around `::`. - -*Valid:* -```php -` to access static variables.* -```php -$staticMember; - } -} -``` - -### Squiz.Strings.ConcatenationSpacing -Force whitespace before and after concatenation - -### Squiz.Strings.DoubleQuoteUsage -#### Squiz.Strings.DoubleQuoteUsage.ContainsVar -Double quote strings may only be used if they contain variables. SQL queries containing single quotes are an exception -to the rule. - -*Valid: Double quote strings are only used when it contains a variable.* -```php -` should not have any spaces around it. - -*Valid: No spaces around the object operator.* -```php -bar(); -``` - -*Invalid: Whitespace surrounding the object operator.* -```php - bar(); -``` - -### Squiz.WhiteSpace.ObjectOperatorSpacing -There should be one space before and after an operators. - -*Valid: One space around the operator.* -```php - - - @@ -597,6 +595,9 @@ + + + From 8a97d6c08f60c2b53bb7a2ee9659fb8f9d3e24b2 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Fri, 18 Oct 2019 16:12:24 +0200 Subject: [PATCH 13/20] Fix code block fencing and typos --- CHANGELOG.md | 2 +- README.md | 2 +- docs/book/v2/coding-style-guide.md | 238 ++++++++++++++--------------- docs/book/v2/intro.md | 2 +- src/ZendCodingStandard/ruleset.xml | 42 ++--- 5 files changed, 143 insertions(+), 143 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ef81d96..234e47fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,7 +89,7 @@ All notable changes to this project will be documented in this file, in reverse return values are still under discussion. We will change these rules, and, when PSR-12 is finalized, adapt them. - [#5](https://github.com/zendframework/zend-coding-standard/pull/5) extends - PSR-12 with ZendFramework specific rules: + PSR-12 with Zend Framework specific rules: *NOTE:* Most of these rules should look familiar as they are already being used in components rewritten for PHP 7.1. diff --git a/README.md b/README.md index 5922b094..2157946c 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ $xmlPackage->send(); > **New rules or Sniffs may not be introduced in minor or bugfix releases and should always be based on the develop branch and queued for the next major release, unless considered a bugfix for existing rules.** -If you want to test changes against ZendFramework components or your own projects, install your forked +If you want to test changes against Zend Framework components or your own projects, install your forked zend-coding-standard globally with composer: ```bash $ composer global config repositories.zend-coding-standard vcs git@github.com:/zend-coding-standard.git diff --git a/docs/book/v2/coding-style-guide.md b/docs/book/v2/coding-style-guide.md index 7d4bd8f4..1ffa7ac1 100644 --- a/docs/book/v2/coding-style-guide.md +++ b/docs/book/v2/coding-style-guide.md @@ -1,4 +1,4 @@ -# ZendFramework Coding Style Guide +# Zend Framework Coding Style Guide The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be @@ -12,7 +12,7 @@ This specification extends [PSR-12][], the coding style guide and requires adherence to [PSR-1][], the basic coding standard. Like [PSR-12][], the intent of this specification is to reduce cognitive friction when -scanning code from different authors contributing to ZendFramework. It does so by +scanning code from different authors contributing to Zend Framework. It does so by enumerating a shared set of rules and expectations about how to format PHP code. ### Previous language versions @@ -24,7 +24,7 @@ of PHP supported by your project. This example encompasses some of the rules below as a quick overview: -~~~php +```php **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > There MAY NOT be any content before the opening tag. > @@ -105,7 +105,7 @@ All PHP files MUST end with a non-blank line, terminated with a single LF. The closing `?>` tag MUST be omitted from files containing only PHP. -> **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > The `declare(strict_types=1)` directive MUST be declared and be the first > statement in a file. @@ -126,7 +126,7 @@ blocks of code except where explicitly forbidden. There MUST NOT be more than one statement per line. -> **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > There MAY be maximum one blank line to improve readability and to indicate > related blocks of code except where explicitly forbidden. @@ -138,7 +138,7 @@ There MUST NOT be more than one statement per line. Code MUST use an indent of 4 spaces for each indent level, and MUST NOT use tabs for indenting. -> **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > Encapsed strings MAY be used instead of concatenating strings. When > concatenating strings, there MUST be a single whitespace before and after the @@ -156,13 +156,13 @@ Short form of type keywords MUST be used i.e. `bool` instead of `boolean`, ### 2.6 Variables -> **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > Variable names MUST be declared in camelCase. ### 2.7 Arrays -> **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > The short array syntax MUST be used to define arrays. > @@ -208,7 +208,7 @@ must always be fully qualified. The following example illustrates a complete list of all blocks: -~~~php +```php @@ -278,20 +278,20 @@ For example: ?> -~~~ +``` Declare statements MUST contain no spaces and MUST be exactly `declare(strict_types=1)` (with an optional semi-colon terminator). Block declare statements are allowed and MUST be formatted as below. Note position of braces and spacing: -~~~php +```php declare(ticks=1) { // some code } -~~~ +``` -> **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > There MUST be a single space after the namespace keyword. > @@ -327,11 +327,11 @@ same line. When instantiating a new class, parentheses MUST always be present even when there are no arguments passed to the constructor. -~~~php +```php new Foo(); -~~~ +``` -> **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > There MAY NOT be duplicate class names. > @@ -374,7 +374,7 @@ by a blank line. Closing braces MUST be on their own line and MUST NOT be preceded by a blank line. -~~~php +```php **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > Traits MUST be sorted alphabetically. -~~~php +```php **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > Default null values MUST be omitted for class properties. A property declaration looks like the following: -~~~php +```php **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > There MUST be a single empty line between methods in a class. > @@ -598,7 +598,7 @@ MUST be one space after each comma. Method and function arguments with default values MUST go at the end of the argument list. -~~~php +```php **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > The question mark MUST be used when the default argument value is null. -~~~php +```php **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > The final keyword on methods MUST be omitted in final classes. @@ -750,13 +750,13 @@ after the opening parenthesis, and there MUST NOT be a space before the closing parenthesis. In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma. -~~~php +```php bar($arg1); Foo::bar($arg2, $arg3); -~~~ +``` Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the @@ -764,7 +764,7 @@ next line, and there MUST be only one argument per line. A single argument being split across multiple lines (as might be the case with an anonymous function or array) does not constitute splitting the argument list itself. -~~~php +```php bar( @@ -772,9 +772,9 @@ $foo->bar( $longerArgument, $muchLongerArgument ); -~~~ +``` -~~~php +```php get('/hello/{name}', function ($name) use ($app) { return 'Hello ' . $app->escape($name); }); -~~~ +``` ## 5. Control Structures @@ -803,7 +803,7 @@ The body of each structure MUST be enclosed by braces. This standardizes how the structures look and reduces the likelihood of introducing errors as new lines get added to the body. -> **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > There MUST be one single space after `break` and `continue` structures with > a numeric argument argument. @@ -816,7 +816,7 @@ An `if` structure looks like the following. Note the placement of parentheses, spaces, and braces; and that `else` and `elseif` are on the same line as the closing brace from the earlier body. -~~~php +```php **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > The `continue` control structure MAY NOT be used in switch statements, > `break` SHOULD be used instead. -~~~php +```php $value) { // foreach body } -~~~ +``` ### 5.6 `try`, `catch`, `finally` A `try-catch-finally` block looks like the following. Note the placement of parentheses, spaces, and braces. -~~~php +```php **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > All catch blocks MUST be reachable. > > Catch blocks SHOULD catch `Throwable` instead of `Exception` unless intended. -~~~php +```php **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > There MUST be at least one space on either side of an equals sign used > to assign a value to a variable. In case of a block of related @@ -1078,22 +1078,22 @@ All operators not described here are left undefined. The increment/decrement operators MUST NOT have any space between the operator and operand. -~~~php +```php $i++; ++$j; -~~~ +``` Type casting operators MUST NOT have any space within the parentheses: -> **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > There MUST be one whitespace after a type casting operator. -~~~php +```php $intValue = (int) $input; -~~~ +``` -> **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > There MUST be one whitespace after unary not. @@ -1102,28 +1102,28 @@ $intValue = (int) $input; All binary [arithmetic][], [comparison][], [assignment][], [bitwise][], [logical][], [string][], and [type][] operators MUST be preceded and followed by at least one space: -~~~php +```php if ($a === $b) { $foo = $bar ?? $a ?? $b; } elseif ($a > $b) { $foo = $a + $b * $c; } -~~~ +``` ### 6.3. Ternary operators The conditional operator, also known simply as the ternary operator, MUST be preceded and followed by at least one space around both the `?` and `:` characters: -~~~php +```php $variable = $foo ? 'foo' : 'bar'; -~~~ +``` When the middle operand of the conditional operator is omitted, the operator MUST follow the same style rules as other binary [comparison][] operators: -~~~php +```php $variable = $foo ?: 'bar'; -~~~ +``` ## 7. Closures @@ -1147,14 +1147,14 @@ If a return type is present, it MUST follow the same rules as with normal functions and methods; if the `use` keyword is present, the colon MUST follow the `use` list closing parentheses with no spaces between the two characters. -> **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > Inherited variables passed via `use` MUST be used in closures. A closure declaration looks like the following. Note the placement of parentheses, commas, spaces, and braces: -~~~php +```php bar( @@ -1243,25 +1243,25 @@ $foo->bar( }, $arg3 ); -~~~ +``` ## 8. Anonymous Classes Anonymous Classes MUST follow the same guidelines and principles as closures in the above section. -~~~php +```php **Additional ZendFramework rules** +> **Additional Zend Framework rules** > > DocBlocks and comments SHOULD only be used if necessary. Code SHOULD > be written so it explains itself. They MAY NOT start with `#` and MAY diff --git a/docs/book/v2/intro.md b/docs/book/v2/intro.md index 7e19599f..c35fceeb 100644 --- a/docs/book/v2/intro.md +++ b/docs/book/v2/intro.md @@ -109,7 +109,7 @@ $xmlPackage->send(); > **New rules or Sniffs may not be introduced in minor or bugfix releases and should always be based on the develop branch and queued for the next major release, unless considered a bugfix for existing rules.** -If you want to test changes against ZendFramework components or your own projects, install your forked +If you want to test changes against Zend Framework components or your own projects, install your forked zend-coding-standard globally with composer: ```bash $ composer global config repositories.zend-coding-standard vcs git@github.com:/zend-coding-standard.git diff --git a/src/ZendCodingStandard/ruleset.xml b/src/ZendCodingStandard/ruleset.xml index ef10f80c..93d74593 100644 --- a/src/ZendCodingStandard/ruleset.xml +++ b/src/ZendCodingStandard/ruleset.xml @@ -2,7 +2,7 @@ - The ZendFramework coding standard. + The Zend Framework coding standard. @@ -19,7 +19,7 @@ the first letter of each word is capitalized including the very first letter. --> - + @@ -95,7 +95,7 @@ - + @@ -118,7 +118,7 @@ - + @@ -135,7 +135,7 @@ - + - + - + @@ -241,7 +241,7 @@ - + @@ -284,7 +284,7 @@ even when there are no arguments passed to the constructor. --> - + @@ -345,7 +345,7 @@ taking note of indentation, spacing, and new lines. --> - + @@ -365,7 +365,7 @@ minimum version supports constant visibilities (PHP 7.1 or later). --> - + @@ -390,7 +390,7 @@ - + @@ -438,7 +438,7 @@ question mark and the type. --> - + @@ -451,7 +451,7 @@ declaration. --> - + @@ -495,7 +495,7 @@ - + @@ -544,7 +544,7 @@ - + @@ -593,7 +593,7 @@ - + @@ -607,7 +607,7 @@ used for readability purposes. --> - + - + @@ -704,7 +704,7 @@ the two characters. --> - + @@ -721,7 +721,7 @@ - + +> Statements MAY NOT be empty, except for catch statements. ### 5.1 `if`, `elseif`, `else` @@ -1028,9 +1100,8 @@ try { > ### Additional Zend Framework rules > -> All catch blocks MUST be reachable. -> -> Catch blocks SHOULD catch `Throwable` instead of `Exception` unless intended. +> All catch blocks MUST be reachable and SHOULD catch `Throwable` instead of +> `Exception` unless intended. ```php assignments, more spaces MUST be inserted before the equal sign to > promote readability. > -> There MAY NOT be any white space around the object operator unless +> There SHOULD NOT be any white space around the object operator unless > multilines are used. > -> There MAY NOT be spaces around the object operator. -> > Loose comparison operators SHOULD NOT be used, use strict comparison -> operators instead. +> operators instead. e.g. use `===` instead of `==`. > -> The null coalesce operator MUST be used when possible. +> The null coalesce operator SHOULD be used when possible. > > Assignment operators SHOULD be used when possible. > -> The `&&` and `||` operators SHOULD be used instad of `and` and `or`. +> The `&&` and `||` operators SHOULD be used instead of `and` and `or`. All operators not described here are left undefined. @@ -1078,12 +1147,13 @@ All operators not described here are left undefined. The increment/decrement operators MUST NOT have any space between the operator and operand. + ```php $i++; ++$j; ``` -Type casting operators MUST NOT have any space within the parentheses: +Type casting operators MUST NOT have any space within the parentheses. > ### Additional Zend Framework rules > @@ -1097,11 +1167,20 @@ $intValue = (int) $input; > > There MUST be one whitespace after unary not. +```php + ### Additional Zend Framework rules > -> DocBlocks and comments SHOULD only be used if necessary. Code SHOULD -> be written so it explains itself. They MAY NOT start with `#` and MAY -> NOT be empty. They MAY be omitted and SHOULD NOT be used for already -> typehinted arguments, except arrays. +> Code SHOULD be written so it explains itself. DocBlocks and comments +> SHOULD only be used if necessary. They MAY NOT start with `#` and MAY +> NOT be empty. They SHOULD NOT be used for already typehinted arguments, +> except arrays. +> +> The asterisks in a DocBlock should align, and there should be one +> space between the asterisk and tag. > -> PHPDoc tags `@param`, `@throws` and `@return` SHOULD not be aligned or +> PHPDoc tags `@param`, `@return` and `@throws` SHOULD not be aligned or > contain multiple spaces between the tag, type and description. > > If a function throws any exceptions, it SHOULD be documented with > `@throws` tags. > -> The asterisks in a DocBlock should align, and there should be one -> space between the asterisk and tag. -> > DocBlocks MUST follow this specific order of annotations with empty > newline between specific groups: > @@ -1353,3 +1433,14 @@ $instance = new class extends \Foo implements [logical]: https://www.php.net/manual/en/language.operators.logical.php [string]: https://www.php.net/manual/en/language.operators.string.php [type]: https://www.php.net/manual/en/language.operators.type.php +[short open tag]: https://www.php.net/manual/en/language.basic-syntax.phptags.php +[70.deprecated]: https://www.php.net/manual/en/migration70.deprecated.php +[71.deprecated]: https://www.php.net/manual/en/migration71.deprecated.php +[72.deprecated]: https://www.php.net/manual/en/migration72.deprecated.php +[73.deprecated]: https://www.php.net/manual/en/migration73.deprecated.php +[74.deprecated]: https://www.php.net/manual/en/migration74.deprecated.php +[backtick operator]: https://www.php.net/manual/en/language.operators.execution.php +[goto]: https://www.php.net/manual/en/control-structures.goto.php +[global]: https://www.php.net/manual/en/language.variables.scope.php#language.variables.scope.global +[PHP_SAPI]: https://www.php.net/manual/en/function.php-sapi-name.php#refsect1-function.php-sapi-name-notes +[aliases]: https://www.php.net/manual/en/aliases.php From 45301bb20dc2c810dc469e3017a450955306eaf6 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Tue, 5 Nov 2019 09:15:31 +0100 Subject: [PATCH 16/20] fix: enforce proper RFC 2119 verbiage, typos and remove too opinionated rules --- docs/book/v2/coding-style-guide.md | 71 +++++++++---------- src/ZendCodingStandard/ruleset.xml | 83 +++++++++++------------ test/expected-report.txt | 8 +-- test/fixable/5.6.TryCatchFinally.php | 17 ----- test/fixable/9.CommentingAndDocBlocks.php | 3 + test/fixed/5.6.TryCatchFinally.php | 17 ----- test/fixed/9.CommentingAndDocBlocks.php | 2 - 7 files changed, 79 insertions(+), 122 deletions(-) diff --git a/docs/book/v2/coding-style-guide.md b/docs/book/v2/coding-style-guide.md index 08956d9d..59d8e591 100644 --- a/docs/book/v2/coding-style-guide.md +++ b/docs/book/v2/coding-style-guide.md @@ -110,12 +110,16 @@ each word is capitalized including the very first letter. > - Deprecated features SHOULD be avoided ([[7.0]][70.deprecated], > [[7.1]][71.deprecated], [[7.2]][72.deprecated], [[7.3]][73.deprecated], > [[7.4]][74.deprecated]) -> - The [backtick operator][] SHOULD NOT be used. +> - The [backtick operator][] MUST NOT be used. > - The [goto][] language construct SHOULD NOT be used. -> - The [global][] keyword SHOULD NOT be used. +> - The [global][] keyword MUST NOT be used. > - The constant [PHP_SAPI][] SHOULD be used instead of the `php_sapi_name()` function. > - [aliases][] SHOULD NOT be used. > +> There MUST NOT be a space before a semicolon. Redundant semicolons SHOULD be avoided. +> +> Non executable code MUST be removed. +> > There MUST be a single space after language constructs. > > Parentheses MUST be omitted where possible. @@ -165,7 +169,8 @@ There MUST NOT be more than one statement per line. > ### Additional Zend Framework rules > -> There MAY NOT be a space before a semicolon. Redundant semicolons SHOULD be avoided. +> There MUST NOT be a space before a semicolon. Redundant semicolons SHOULD be +> avoided. ### 2.4 Indenting and Spacing @@ -176,8 +181,9 @@ tabs for indenting. > > Encapsed strings MAY be used instead of concatenating strings. When > concatenating strings, there MUST be a single whitespace before and after the -> concatenation operator. The concatenation operator MAY NOT be the at the end -> of a line. +> concatenation operator. The concatenation operator MUST NOT be the at the end +> of a line. If multi-line concatenation is used there MUST be an indent of 4 +> spaces. ```php > All array values must be followed by a comma, including the last value. > -> There MUST be no whitespace around the opening bracket or before the closing +> There MUST NOT be whitespace around the opening bracket or before the closing > bracket when referencing an array. > > All double arrow symbols MUST be aligned to one space after the longest array @@ -287,9 +293,9 @@ must always be fully qualified. > > Unused import statements SHOULD be removed. > -> Fancy group import statements are not allowed. +> Fancy group import statements MUST NOT be used. > -> Each import statements MUST be on its own line. +> Each import statement MUST be on its own line. > > Import statement aliases for classes, traits, functions and constants MUST > be useful, meaning that aliases SHOULD only be used if a class with the same @@ -405,11 +411,11 @@ new Foo(); > ### Additional Zend Framework rules > -> There MAY NOT be duplicate class names. +> There MUST NOT be duplicate class names. > > The file name MUST match the case of the terminating class name. > -> PHP 4 style constructors SHOULD NOT be used. +> PHP 4 style constructors MUST NOT be used. > > The correct class names MUST be used. > @@ -618,8 +624,8 @@ Method names MUST NOT be prefixed with a single underscore to indicate protected or private visibility. That is, an underscore prefix explicitly has no meaning. -Method and function names MUST NOT be declared with space after the method name. The -opening brace MUST go on its own line, and the closing brace MUST go on the +Method and function names MUST NOT be declared with space after the method name. +The opening brace MUST go on its own line, and the closing brace MUST go on the next line following the body. There MUST NOT be a space after the opening parenthesis, and there MUST NOT be a space before the closing parenthesis. @@ -627,10 +633,10 @@ parenthesis, and there MUST NOT be a space before the closing parenthesis. > > There MUST be a single empty line between methods in a class. > -> The pseudo-variable `$this` MAY not be called inside a static method or +> The pseudo-variable `$this` MUST NOT be called inside a static method or > function. > -> Returned variables SHOULD be useful and not be assign to a value and +> Returned variables SHOULD be useful and SHOULD NOT be assigned to a value and > returned on the next line. A method declaration looks like the following. Note the placement of @@ -880,7 +886,7 @@ lines get added to the body. > There MUST be one single space after `break` and `continue` structures with > a numeric argument argument. > -> Statements MAY NOT be empty, except for catch statements. +> Statements MUST NOT be empty, except for catch statements. ### 5.1 `if`, `elseif`, `else` @@ -936,7 +942,7 @@ indented at the same level as the `case` body. There MUST be a comment such as > ### Additional Zend Framework rules > -> The `continue` control structure MAY NOT be used in switch statements, +> The `continue` control structure MUST NOT be used in switch statements, > `break` SHOULD be used instead. ```php @@ -1100,24 +1106,12 @@ try { > ### Additional Zend Framework rules > -> All catch blocks MUST be reachable and SHOULD catch `Throwable` instead of -> `Exception` unless intended. - -```php - All catch blocks MUST be reachable. ## 6. Operators -Style rules for operators are grouped by arity (the number of operands they take). +Style rules for operators are grouped by arity (the number of operands they +take). When space is permitted around an operator, multiple spaces MAY be used for readability purposes. @@ -1129,7 +1123,7 @@ used for readability purposes. > assignments, more spaces MUST be inserted before the equal sign to > promote readability. > -> There SHOULD NOT be any white space around the object operator unless +> There MUST NOT be any white space around the object operator UNLESS > multilines are used. > > Loose comparison operators SHOULD NOT be used, use strict comparison @@ -1364,7 +1358,7 @@ $instance = new class extends \Foo implements > ### Additional Zend Framework rules > > Code SHOULD be written so it explains itself. DocBlocks and comments -> SHOULD only be used if necessary. They MAY NOT start with `#` and MAY +> SHOULD only be used if necessary. They MUST NOT start with `#` and MUST > NOT be empty. They SHOULD NOT be used for already typehinted arguments, > except arrays. > @@ -1394,19 +1388,17 @@ $instance = new class extends \Foo implements > * @uses > * > * @param -> * > * @return -> * > * @throws > */ > ``` > > The annotations `@api`, `@author`, `@category`, `@created`, `@package`, -> `@subpackage` and `@version` may not be used in comments. Git commits +> `@subpackage` and `@version` MUST NOT be used in comments. Git commits > provide accurate information. > > The words _private_, _protected_, _static_, _constructor_, _deconstructor_, -> _Created by_, _getter_ and _setter_, MAY NOT be used in comments. +> _Created by_, _getter_ and _setter_, MUST NOT be used in comments. > > The `@var` tag MAY be used in inline comments to document the _Type_ > of properties. Single-line property comments with a `@var` tag SHOULD @@ -1415,9 +1407,8 @@ $instance = new class extends \Foo implements > The correct tag case of PHPDocs and PHPUnit tags MUST be used. > > Inline DocComments MAY be used at the end of the line, with at least a -> single space. Inline DocComments MAY NOT be placed after curly brackets. -> -> Typed parameters and return types SHOULD be avoided. +> single space preceding. Inline DocComments MUST NOT be placed after curly +> brackets. > > Heredoc and nowdoc tags MUST be uppercase without spaces. diff --git a/src/ZendCodingStandard/ruleset.xml b/src/ZendCodingStandard/ruleset.xml index 93d74593..ad2332d7 100644 --- a/src/ZendCodingStandard/ruleset.xml +++ b/src/ZendCodingStandard/ruleset.xml @@ -33,11 +33,11 @@ - + - + - + @@ -70,7 +70,7 @@ - @@ -124,7 +124,7 @@ indicate related blocks of code except where explicitly forbidden. --> - @@ -139,8 +139,9 @@ + after the concatenation operator. The concatenation operator MUST NOT + be the at the end of a line. If multi-line concatenation is used + there MUST be an indent of 4 spaces. --> @@ -185,7 +186,7 @@ - - + - + @@ -286,11 +287,11 @@ - + - + @@ -394,11 +395,11 @@ - - + @@ -440,7 +441,7 @@ - + @@ -500,7 +501,7 @@ - + @@ -546,7 +547,7 @@ - @@ -598,9 +599,6 @@ - - - - @@ -640,7 +637,7 @@ - + @@ -713,8 +710,8 @@ - @@ -724,7 +721,7 @@ + + + + + + @@ -795,9 +800,7 @@ * @uses * * @param - * * @return - * * @throws */ --> @@ -824,15 +827,17 @@ @ODM\, @PHPCR\, "/> - - - + @@ -853,7 +858,7 @@ + _Created by_, _getter_ and _setter_, MUST NOT be used in comments. --> @@ -876,17 +881,11 @@ + single space preceding. Inline DocComments MUST NOT be placed after + curly brackets. --> - - - - - - - diff --git a/test/expected-report.txt b/test/expected-report.txt index 71c3efe9..3f1c1fbf 100644 --- a/test/expected-report.txt +++ b/test/expected-report.txt @@ -12,7 +12,7 @@ test/fixable/2.6.Variables.php 3 0 test/fixable/2.7.Arrays.php 9 0 test/fixable/3.DeclareNamespaceAndImport.php 15 0 test/fixable/4.1.ExtendsAndImplements.php 5 0 -test/fixable/4.2.UsingTraits.php 6 0 +test/fixable/4.2.UsingTraits.php 5 0 test/fixable/4.3.PropertiesAndConstants.php 5 0 test/fixable/4.4.MethodsAndFunctions.php 26 0 test/fixable/4.5.MethodAndFunctionArguments.php 66 0 @@ -24,7 +24,7 @@ test/fixable/5.2.SwitchCase.php 11 0 test/fixable/5.3.WhileAndDoWhile.php 12 0 test/fixable/5.4.ForStructure.php 7 0 test/fixable/5.5.ForEachStructure.php 12 0 -test/fixable/5.6.TryCatchFinally.php 10 0 +test/fixable/5.6.TryCatchFinally.php 9 0 test/fixable/5.ControlStructures.php 4 0 test/fixable/6.1.UnaryOperators.php 6 0 test/fixable/6.2.BinaryOperators.php 35 0 @@ -34,9 +34,9 @@ test/fixable/7.Closures.php 2 0 test/fixable/8.AnonymousClasses.php 1 0 test/fixable/9.CommentingAndDocBlocks.php 22 0 ---------------------------------------------------------------------- -A TOTAL OF 586 ERRORS AND 2 WARNINGS WERE FOUND IN 30 FILES +A TOTAL OF 584 ERRORS AND 2 WARNINGS WERE FOUND IN 30 FILES ---------------------------------------------------------------------- -PHPCBF CAN FIX 496 OF THESE SNIFF VIOLATIONS AUTOMATICALLY +PHPCBF CAN FIX 494 OF THESE SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------- diff --git a/test/fixable/5.6.TryCatchFinally.php b/test/fixable/5.6.TryCatchFinally.php index 10f9f7a7..3efbe61b 100644 --- a/test/fixable/5.6.TryCatchFinally.php +++ b/test/fixable/5.6.TryCatchFinally.php @@ -5,7 +5,6 @@ namespace ZendCodingStandardTest\fixed; use AnotherThrowableType; -use Exception; use FirstThrowableType; use InvalidArgumentException; use OtherThrowableType; @@ -41,20 +40,4 @@ public function testUnreacableCatchBlock(): void echo $e; // unreachable! } } - - public function testCatchBlocksShouldUseThrowable(): void - { - try { - $x = 1 + 2; - } catch (Exception $e) { - // Should be Throwable - } - - try { - $x = 1 + 2; - } catch (Exception $e) { - // OK -> catching Throwable later - } catch (Throwable $e) { - } - } } diff --git a/test/fixable/9.CommentingAndDocBlocks.php b/test/fixable/9.CommentingAndDocBlocks.php index b99d41c6..1879ed34 100644 --- a/test/fixable/9.CommentingAndDocBlocks.php +++ b/test/fixable/9.CommentingAndDocBlocks.php @@ -40,8 +40,11 @@ class CommentingAndDocBlocks * @see * @uses * @param + * * @return + * * @throws + * */ public function testDocBlockSpacing(): void { diff --git a/test/fixed/5.6.TryCatchFinally.php b/test/fixed/5.6.TryCatchFinally.php index 1662a83c..458c487e 100644 --- a/test/fixed/5.6.TryCatchFinally.php +++ b/test/fixed/5.6.TryCatchFinally.php @@ -5,7 +5,6 @@ namespace ZendCodingStandardTest\fixed; use AnotherThrowableType; -use Exception; use FirstThrowableType; use InvalidArgumentException; use OtherThrowableType; @@ -38,20 +37,4 @@ public function testUnreacableCatchBlock(): void echo $e; // unreachable! } } - - public function testCatchBlocksShouldUseThrowable(): void - { - try { - $x = 1 + 2; - } catch (Throwable $e) { - // Should be Throwable - } - - try { - $x = 1 + 2; - } catch (Exception $e) { - // OK -> catching Throwable later - } catch (Throwable $e) { - } - } } diff --git a/test/fixed/9.CommentingAndDocBlocks.php b/test/fixed/9.CommentingAndDocBlocks.php index f2ea8cc4..498287ad 100644 --- a/test/fixed/9.CommentingAndDocBlocks.php +++ b/test/fixed/9.CommentingAndDocBlocks.php @@ -42,9 +42,7 @@ class CommentingAndDocBlocks * @see * * @param - * * @return - * * @throws */ public function testDocBlockSpacing(): void From d116df40741502bd23b7e21402f0cab5992c62fd Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Tue, 5 Nov 2019 10:05:59 +0100 Subject: [PATCH 17/20] doc: add chapter 1 --- docs/book/v2/coding-style-guide.md | 6 +++--- src/ZendCodingStandard/ruleset.xml | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/book/v2/coding-style-guide.md b/docs/book/v2/coding-style-guide.md index 59d8e591..d435825b 100644 --- a/docs/book/v2/coding-style-guide.md +++ b/docs/book/v2/coding-style-guide.md @@ -6,7 +6,7 @@ interpreted as described in [RFC 2119][]. [RFC 2119]: http://tools.ietf.org/html/rfc2119 -## Overview +## 1. Overview This specification extends [PSR-12][], the coding style guide and requires adherence to [PSR-1][], the basic coding standard. @@ -15,12 +15,12 @@ Like [PSR-12][], the intent of this specification is to reduce cognitive frictio scanning code from different authors contributing to Zend Framework. It does so by enumerating a shared set of rules and expectations about how to format PHP code. -### Previous language versions +### 1.1 Previous language versions Throughout this document, any instructions MAY be ignored if they do not exist in versions of PHP supported by your project. -### Example +### 1.2 Example This example encompasses some of the rules below as a quick overview: diff --git a/src/ZendCodingStandard/ruleset.xml b/src/ZendCodingStandard/ruleset.xml index ad2332d7..dae50601 100644 --- a/src/ZendCodingStandard/ruleset.xml +++ b/src/ZendCodingStandard/ruleset.xml @@ -4,6 +4,11 @@ name="ZendCodingStandard"> The Zend Framework coding standard. + + + + From 607386d5243da54f5e3cf6f6dbba8b3730eb548a Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Tue, 5 Nov 2019 10:12:32 +0100 Subject: [PATCH 18/20] docs: remove obsolete notification and link --- README.md | 4 ---- docs/book/v2/intro.md | 4 ---- 2 files changed, 8 deletions(-) diff --git a/README.md b/README.md index 2157946c..b26b61a3 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,6 @@ Contributors have different coding styles and so do the maintainers. During code discussions about spaces and alignments, where and when was said that a function needs to be imported. And that's where this coding standard comes in: To have internal consistency in a component and between components. -> Note: PSR-12 is not finalized. e.g. The `!` operator and `:` placement for return values are still under discussion. -We will change these rules, and, when PSR-12 is finalized, adapt them. - ## Installation 1. Install the module via composer by running: @@ -135,4 +132,3 @@ be found here: - [Configuration Options](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options) - [Selectively Applying Rules](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset#selectively-applying-rules) - [Customisable Sniff Properties](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties) -- [Slevomat Coding Standard](https://github.com/slevomat/coding-standard) diff --git a/docs/book/v2/intro.md b/docs/book/v2/intro.md index c35fceeb..82eb3b8e 100644 --- a/docs/book/v2/intro.md +++ b/docs/book/v2/intro.md @@ -17,9 +17,6 @@ Contributors have different coding styles and so do the maintainers. During code discussions about spaces and alignments, where and when was said that a function needs to be imported. And that's where this coding standard comes in: To have internal consistency in a component and between components. -> Note: PSR-12 is not finalized. e.g. The `!` operator and `:` placement for return values are still under discussion. -We will change these rules, and, when PSR-12 is finalized, adapt them. - ## Installation 1. Install the module via composer by running: @@ -133,4 +130,3 @@ be found here: - [Configuration Options](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options) - [Selectively Applying Rules](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset#selectively-applying-rules) - [Customisable Sniff Properties](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties) -- [Slevomat Coding Standard](https://github.com/slevomat/coding-standard) From 5aaa89943f6e9ad04eb125416d5398a04f0d77b2 Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Tue, 5 Nov 2019 10:55:17 +0100 Subject: [PATCH 19/20] docs: add changelog for #22 --- CHANGELOG.md | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 234e47fb..3ec0cb9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,149 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 2.0.0-alpha.4 - TBD + +### Added + +- Nothing. + +### Changed + +- [#22](https://github.com/zendframework/zend-coding-standard/pull/22) refactors + documentation. It now follows the PHP-FIG PSR-12 style. +- [#22](https://github.com/zendframework/zend-coding-standard/pull/22) refactors + the ruleset. It uses PSR-12 as the base ruleset with these additional rules: + + - The short open tag SHOULD NOT be used. + - Deprecated features SHOULD be avoided. + - The backtick operator MUST NOT be used. + - The `goto` language construct SHOULD NOT be used. + - The `global` keyword MUST NOT be used. + - The constant `PHP_SAPI` SHOULD be used instead of the `php_sapi_name()` + function. + - Aliases SHOULD NOT be used. + - There MUST NOT be a space before a semicolon. Redundant semicolons SHOULD + be avoided. + - Non executable code MUST be removed. + - There MUST be a single space after language constructs. + - Parentheses MUST be omitted where possible. + - PHP function calls MUST be in lowercase. + - There MAY NOT be any content before the opening tag. Inline HTML in PHP code + SHOULD be avoided. All code MUST be executable and non executable code SHOULD + be removed. + - The `declare(strict_types=1)` directive MUST be declared and be the first + statement in a file. + - There MAY be maximum one blank line to improve readability and to indicate + related blocks of code except where explicitly forbidden. + - There MAY NOT be any blank line after opening braces and before closing braces. + - There MUST NOT be a space before a semicolon. Redundant semicolons SHOULD be + avoided. + - Encapsed strings MAY be used instead of concatenating strings. When + concatenating strings, there MUST be a single whitespace before and after the + concatenation operator. The concatenation operator MUST NOT be the at the end + of a line. If multi-line concatenation is used there MUST be an indent of 4 + spaces. + - Variable names MUST be declared in camelCase. + - The short array syntax MUST be used to define arrays. + - All values in multiline arrays must be indented with 4 spaces. + - All array values must be followed by a comma, including the last value. + - There MUST NOT be whitespace around the opening bracket or before the closing + bracket when referencing an array. + - All double arrow symbols MUST be aligned to one space after the longest array + key. + - The short list syntax `[...]` SHOULD be used instead of `list(...)`. + - There MUST be a single space after the namespace keyword and there MAY NOT be + a space around a namespace separator. + - Import statements MUST be alphabetically sorted. + - Unused import statements SHOULD be removed. + - Fancy group import statements MUST NOT be used. + - Each import statement MUST be on its own line. + - Import statement aliases for classes, traits, functions and constants MUST + be useful, meaning that aliases SHOULD only be used if a class with the same + name is imported. + - Classes, traits, interfaces, constants and functions MUST be imported. + - There MUST NOT be duplicate class names. + - The file name MUST match the case of the terminating class name. + - PHP 4 style constructors MUST NOT be used. + - The correct class names MUST be used. + - Abstract classes MUST have a `Abstract` prefix. + - Exception classes MUST have a `Exception` suffix. + - Interface classes MUST have a `Interface` suffix. + - Trait classes MUST have a `Trait` suffix. + - For self-reference a class lower-case `self::` MUST be used without spaces + around the scope resolution operator. + - Class name resolution via `::class` MUST be used instead of `__CLASS__`, + `get_class()`, `get_class($this)`, `get_called_class()`, `get_parent_class()` + and string reference. + - There MAY NOT be any whitespace around the double colon operator. + - Unused private methods, constants and properties MUST be removed. + - Traits MUST be sorted alphabetically. + - Default null values MUST be omitted for class properties. + - There MUST be a single empty line between methods in a class. + - The pseudo-variable `$this` MUST NOT be called inside a static method or + function. + - Returned variables SHOULD be useful and SHOULD NOT be assigned to a value and + returned on the next line. + - The question mark MUST be used when the default argument value is null. + - The `final` keyword on methods MUST be omitted in final declared classes. + - There MUST be one single space after `break` and `continue` structures with + a numeric argument argument. + - Statements MUST NOT be empty, except for catch statements. + - The `continue` control structure MUST NOT be used in switch statements, + `break` SHOULD be used instead. + - All catch blocks MUST be reachable. + - There MUST be at least one space on either side of an equals sign used + to assign a value to a variable. In case of a block of related + assignments, more spaces MUST be inserted before the equal sign to + promote readability. + - There MUST NOT be any white space around the object operator UNLESS + multilines are used. + - Loose comparison operators SHOULD NOT be used, use strict comparison + operators instead. e.g. use `===` instead of `==`. + - The null coalesce operator SHOULD be used when possible. + - Assignment operators SHOULD be used when possible. + - The `&&` and `||` operators SHOULD be used instead of `and` and `or`. + - There MUST be one whitespace after a type casting operator. + - There MUST be one whitespace after unary not. + - Inherited variables passed via `use` MUST be used in closures. + - Code SHOULD be written so it explains itself. DocBlocks and comments + SHOULD only be used if necessary. They MUST NOT start with `#` and MUST + NOT be empty. They SHOULD NOT be used for already typehinted arguments, + except arrays. + - The asterisks in a DocBlock should align, and there should be one + space between the asterisk and tag. + - PHPDoc tags `@param`, `@return` and `@throws` SHOULD not be aligned or + contain multiple spaces between the tag, type and description. + - If a function throws any exceptions, it SHOULD be documented with + `@throws` tags. + - DocBlocks MUST follow a specific order of annotations with empty + newline between specific groups. + - The annotations `@api`, `@author`, `@category`, `@created`, `@package`, + `@subpackage` and `@version` MUST NOT be used in comments. Git commits + provide accurate information. + - The words _private_, _protected_, _static_, _constructor_, _deconstructor_, + _Created by_, _getter_ and _setter_, MUST NOT be used in comments. + - The `@var` tag MAY be used in inline comments to document the _Type_ + of properties. Single-line property comments with a `@var` tag SHOULD + be written as one-liners. The `@var` MAY NOT be used for constants. + - The correct tag case of PHPDocs and PHPUnit tags MUST be used. + - Inline DocComments MAY be used at the end of the line, with at least a + single space preceding. Inline DocComments MUST NOT be placed after curly + brackets. + - Heredoc and nowdoc tags MUST be uppercase without spaces. + +### Deprecated + +- Nothing. + +### Removed + +- Nothing. + +### Fixed + +- Nothing. + ## 2.0.0-alpha.3 - 2019-01-01 ### Added From e6201f331b461557c544aea453de79cb6576265e Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Tue, 5 Nov 2019 16:49:16 +0100 Subject: [PATCH 20/20] docs: explain it's about class name casing --- CHANGELOG.md | 2 +- docs/book/v2/coding-style-guide.md | 2 +- src/ZendCodingStandard/ruleset.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ec0cb9b..79f8dc24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,7 +66,7 @@ All notable changes to this project will be documented in this file, in reverse - There MUST NOT be duplicate class names. - The file name MUST match the case of the terminating class name. - PHP 4 style constructors MUST NOT be used. - - The correct class names MUST be used. + - Correct class name casing MUST be used. - Abstract classes MUST have a `Abstract` prefix. - Exception classes MUST have a `Exception` suffix. - Interface classes MUST have a `Interface` suffix. diff --git a/docs/book/v2/coding-style-guide.md b/docs/book/v2/coding-style-guide.md index d435825b..f1e529b0 100644 --- a/docs/book/v2/coding-style-guide.md +++ b/docs/book/v2/coding-style-guide.md @@ -417,7 +417,7 @@ new Foo(); > > PHP 4 style constructors MUST NOT be used. > -> The correct class names MUST be used. +> Correct class name casing MUST be used. > > Abstract classes MUST have a `Abstract` prefix. > diff --git a/src/ZendCodingStandard/ruleset.xml b/src/ZendCodingStandard/ruleset.xml index dae50601..f05c6276 100644 --- a/src/ZendCodingStandard/ruleset.xml +++ b/src/ZendCodingStandard/ruleset.xml @@ -306,7 +306,7 @@ - +