diff --git a/.travis.yml b/.travis.yml index 69b2693..2c08a47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ cache: env: global: - - COMPOSER_ARGS="--no-interaction" + - COMPOSER_ARGS="--no-interaction --ignore-platform-reqs" matrix: fast_finish: true @@ -35,6 +35,12 @@ matrix: - php: 7.4 env: - DEPS=latest + - php: nightly + env: + - DEPS=lowest + - php: nightly + env: + - DEPS=latest addons: apt: diff --git a/CHANGELOG.md b/CHANGELOG.md index dcc38b8..d8a74d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,27 +2,32 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.2.0 - TBD +## 2.1.1 - 2020-10-24 -### Added +----- -- Nothing. +### Release Notes for [2.1.1](https://github.com/laminas/laminas-coding-standard/milestone/4) -### Changed +2.1.x bugfix release (patch) -- Nothing. +### 2.1.1 -### Deprecated +- Total issues resolved: **3** +- Total pull requests resolved: **4** +- Total contributors: **3** -- Nothing. +#### Documentation -### Removed + - [45: docs: add example for type hinting in docblocks](https://github.com/laminas/laminas-coding-standard/pull/45) thanks to @geerteltink and @Xerkus -- Nothing. +#### Bug -### Fixed + - [44: fix: unused imports and generics](https://github.com/laminas/laminas-coding-standard/pull/44) thanks to @geerteltink + - [41: fix: update dependencies to ensure some fixes are included](https://github.com/laminas/laminas-coding-standard/pull/41) thanks to @geerteltink -- Nothing. +#### Enhancement + + - [42: feat: php 8 support](https://github.com/laminas/laminas-coding-standard/pull/42) thanks to @geerteltink and @boesing ## 2.0.1 - 2020-07-02 diff --git a/composer.json b/composer.json index 9176b24..a3372ca 100644 --- a/composer.json +++ b/composer.json @@ -20,12 +20,12 @@ "sort-packages": true }, "require": { - "php": "^7.1", + "php": "^7.3 || ~8.0.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", "laminas/laminas-zendframework-bridge": "^1.0", - "slevomat/coding-standard": "^6.2.0", - "squizlabs/php_codesniffer": "^3.5.3", - "webimpress/coding-standard": "^1.1.5" + "slevomat/coding-standard": "^6.4.1", + "squizlabs/php_codesniffer": "^3.5.8", + "webimpress/coding-standard": "^1.1.6" }, "autoload": { "psr-4": { diff --git a/docs/book/v2/coding-style-guide.md b/docs/book/v2/coding-style-guide.md index 834b747..2e6f5c7 100644 --- a/docs/book/v2/coding-style-guide.md +++ b/docs/book/v2/coding-style-guide.md @@ -1257,11 +1257,32 @@ $instance = new class extends \Foo implements > ### Additional Laminas rules > -> 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, +> 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. +> +> DocBlocks and comments SHOULD NOT be used for already typehinted arguments, > except arrays. > + +```php +/** + * Sets a single-line title + * + * The string `param` and `return` tags should be omitted as they are already + * type hinted. + * + * A `param` tag should be here to describe the array. + * + * @param array $context + */ +public function setTitle(string $title, array $context): void +{ + // ... +} +``` + > The asterisks in a DocBlock should align, and there should be one > space between the asterisk and tag. > diff --git a/src/LaminasCodingStandard/ruleset.xml b/src/LaminasCodingStandard/ruleset.xml index f3b2c82..ac1786d 100644 --- a/src/LaminasCodingStandard/ruleset.xml +++ b/src/LaminasCodingStandard/ruleset.xml @@ -264,13 +264,17 @@ - + - + + + + + - + @@ -280,13 +284,23 @@ - + - - - - - + + + + + + + + + + + + + + + @@ -787,11 +801,14 @@ - - - - + + + + + + + diff --git a/test/expected-report.txt b/test/expected-report.txt index cade5c8..17a0e2b 100644 --- a/test/expected-report.txt +++ b/test/expected-report.txt @@ -7,22 +7,22 @@ test/fixable/2.1.BasicCodingStandard.php 48 1 test/fixable/2.2.Files.php 6 0 test/fixable/2.3.Lines.php 35 0 test/fixable/2.4.IndentingAndSpacing.php 46 0 -test/fixable/2.5.KeywordsAndTypes.php 13 0 +test/fixable/2.5.KeywordsAndTypes.php 8 0 test/fixable/2.6.Variables.php 3 0 test/fixable/2.7.Arrays.php 9 0 -test/fixable/3.DeclareNamespaceAndImport.php 11 0 +test/fixable/3.DeclareNamespaceAndImport.php 12 0 test/fixable/4.1.ExtendsAndImplements.php 5 0 -test/fixable/4.2.UsingTraits.php 4 0 -test/fixable/4.3.PropertiesAndConstants.php 5 0 -test/fixable/4.4.MethodsAndFunctions.php 26 0 +test/fixable/4.2.UsingTraits.php 5 0 +test/fixable/4.3.PropertiesAndConstants.php 7 0 +test/fixable/4.4.MethodsAndFunctions.php 27 0 test/fixable/4.5.MethodAndFunctionArguments.php 66 0 -test/fixable/4.6.AbstractFinalAndStatic.php 4 0 +test/fixable/4.6.AbstractFinalAndStatic.php 5 0 test/fixable/4.7.MethodAndFunctionCalls.php 11 0 -test/fixable/4.ClassesPropertiesAndMethods.php 32 0 -test/fixable/5.1.IfElseifElse.php 15 1 +test/fixable/4.ClassesPropertiesAndMethods.php 34 0 +test/fixable/5.1.IfElseifElse.php 13 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 +test/fixable/5.4.ForStructure.php 5 0 test/fixable/5.5.ForEachStructure.php 10 0 test/fixable/5.6.TryCatchFinally.php 9 0 test/fixable/5.ControlStructures.php 4 0 @@ -30,13 +30,14 @@ test/fixable/6.1.UnaryOperators.php 6 0 test/fixable/6.2.BinaryOperators.php 35 0 test/fixable/6.3.TernaryOperators.php 13 0 test/fixable/6.Operators.php 97 0 -test/fixable/7.Closures.php 2 0 +test/fixable/7.Closures.php 4 0 test/fixable/8.AnonymousClasses.php 1 0 -test/fixable/9.CommentingAndDocBlocks.php 21 0 +test/fixable/9.CommentingAndDocBlocks.php 17 0 +test/fixable/9.GenericTypeHintSyntax.php 4 0 ---------------------------------------------------------------------- -A TOTAL OF 567 ERRORS AND 2 WARNINGS WERE FOUND IN 30 FILES +A TOTAL OF 568 ERRORS AND 2 WARNINGS WERE FOUND IN 31 FILES ---------------------------------------------------------------------- -PHPCBF CAN FIX 487 OF THESE SNIFF VIOLATIONS AUTOMATICALLY +PHPCBF CAN FIX 484 OF THESE SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------- diff --git a/test/fixable/2.3.Lines.php b/test/fixable/2.3.Lines.php index eba4062..8f585ea 100644 --- a/test/fixable/2.3.Lines.php +++ b/test/fixable/2.3.Lines.php @@ -60,13 +60,13 @@ public function testThereMayNotBeAnyBlankLineFfterOpeningBracesAndBeforeClosingB // There MAY NOT be any blank line after opening braces and before // closing braces. - $noBlankLine = function () use ($noBlankLine) { + $noBlankLine = function () use ($noBlankLine): void { $noBlankLine = 1; }; - $closure = function () { + $closure = function (): void { $noBlankLine = 1; diff --git a/test/fixable/2.7.Arrays.php b/test/fixable/2.7.Arrays.php index 37b141a..0a6240f 100644 --- a/test/fixable/2.7.Arrays.php +++ b/test/fixable/2.7.Arrays.php @@ -27,7 +27,7 @@ public function testArrayFormatting(): void ]; $array2 = [ - 'one' => function () { + 'one' => function (): void { $foo = [1, 2, 3]; $barBar = [ 1, diff --git a/test/fixable/4.1.ExtendsAndImplements.php b/test/fixable/4.1.ExtendsAndImplements.php index 88770ef..46dede2 100644 --- a/test/fixable/4.1.ExtendsAndImplements.php +++ b/test/fixable/4.1.ExtendsAndImplements.php @@ -16,7 +16,7 @@ class ExtendsAndImplements ArrayAccess, Countable, Serializable { - public function testClassDeclaration() + public function testClassDeclaration(): void { // The extends and implements keywords MUST be declared on the same line // as the class name. diff --git a/test/fixable/4.4.MethodsAndFunctions.php b/test/fixable/4.4.MethodsAndFunctions.php index 820d577..e34bcec 100644 --- a/test/fixable/4.4.MethodsAndFunctions.php +++ b/test/fixable/4.4.MethodsAndFunctions.php @@ -19,7 +19,7 @@ public function testMethodsAndFunctions ($arg1, &$arg2, $arg3 = []) { // NOT be a space after the opening parenthesis, and there MUST NOT be a // space before the closing parenthesis. - function fooBar ( $arg1, &$arg2, $arg3 = [] ) { + function fooBar ( $arg1, &$arg2, $arg3 = [] ): void { // function body } @@ -27,7 +27,7 @@ function fooBar ( $arg1, &$arg2, $arg3 = [] ) { - public function testOneSingleLineBetweenMethods() + public function testOneSingleLineBetweenMethods(): void { // There MUST be a single empty line between methods in a class. } diff --git a/test/fixable/4.5.MethodAndFunctionArguments.php b/test/fixable/4.5.MethodAndFunctionArguments.php index c77b35f..184aa9d 100644 --- a/test/fixable/4.5.MethodAndFunctionArguments.php +++ b/test/fixable/4.5.MethodAndFunctionArguments.php @@ -74,7 +74,7 @@ public function testVariadicThreeDotOperator(string $foo, & ... $baz): void // When combining both the reference operator and the variadic three dot // operator, there MUST NOT be any space between the two of them. - function method($a, $b, ... $c) { + function method($a, $b, ... $c): void { if ($a < $b) { method(... func_get_args()); } diff --git a/test/fixable/6.Operators.php b/test/fixable/6.Operators.php index a30933b..f2c7450 100644 --- a/test/fixable/6.Operators.php +++ b/test/fixable/6.Operators.php @@ -65,7 +65,7 @@ public function testOperatorSpacing(): void $result*=4; } - public function testObjectOperatorSpacing() + public function testObjectOperatorSpacing(): void { // There MAY NOT be any white space around the object operator unless // multilines are used. diff --git a/test/fixable/7.Closures.php b/test/fixable/7.Closures.php index 78dd221..96fd3b4 100644 --- a/test/fixable/7.Closures.php +++ b/test/fixable/7.Closures.php @@ -37,11 +37,11 @@ public function testClosures(): void // MUST follow the use list closing parentheses with no spaces between // the two characters. - $closureWithArgs = function ($arg1, $arg2) { + $closureWithArgs = function ($arg1, $arg2): void { echo "$arg1, $arg2"; }; - $closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2) { + $closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2): void { echo "$arg1, $arg2, $var1, $var2"; }; diff --git a/test/fixable/9.GenericTypeHintSyntax.php b/test/fixable/9.GenericTypeHintSyntax.php new file mode 100644 index 0000000..10f4101 --- /dev/null +++ b/test/fixable/9.GenericTypeHintSyntax.php @@ -0,0 +1,36 @@ + */ + private $bar; + + /** + * @param IteratorAggregate $bar + */ + public function __construct(ArrayObject $bar) + { + $this->bar = $bar; + } + + /** + * @param array $config + */ + public function doSomethingWithArray(array $config): void + { + $this->config = $config; + } +} diff --git a/test/fixed/2.3.Lines.php b/test/fixed/2.3.Lines.php index 5686a09..3df12dc 100644 --- a/test/fixed/2.3.Lines.php +++ b/test/fixed/2.3.Lines.php @@ -50,11 +50,11 @@ public function testThereMayNotBeAnyBlankLineFfterOpeningBracesAndBeforeClosingB // There MAY NOT be any blank line after opening braces and before // closing braces. - $noBlankLine = function () use ($noBlankLine) { + $noBlankLine = function () use ($noBlankLine): void { $noBlankLine = 1; }; - $closure = function () { + $closure = function (): void { $noBlankLine = 1; }; diff --git a/test/fixed/2.7.Arrays.php b/test/fixed/2.7.Arrays.php index aa93e4a..a7f3903 100644 --- a/test/fixed/2.7.Arrays.php +++ b/test/fixed/2.7.Arrays.php @@ -27,7 +27,7 @@ public function testArrayFormatting(): void ]; $array2 = [ - 'one' => function () { + 'one' => function (): void { $foo = [1, 2, 3]; $barBar = [ 1, diff --git a/test/fixed/4.1.ExtendsAndImplements.php b/test/fixed/4.1.ExtendsAndImplements.php index 5a60615..6981cbe 100644 --- a/test/fixed/4.1.ExtendsAndImplements.php +++ b/test/fixed/4.1.ExtendsAndImplements.php @@ -14,7 +14,7 @@ class ExtendsAndImplements extends ParentClass implements Countable, Serializable { - public function testClassDeclaration() + public function testClassDeclaration(): void { // The extends and implements keywords MUST be declared on the same line // as the class name. diff --git a/test/fixed/4.4.MethodsAndFunctions.php b/test/fixed/4.4.MethodsAndFunctions.php index 186bfe2..fb3b7a1 100644 --- a/test/fixed/4.4.MethodsAndFunctions.php +++ b/test/fixed/4.4.MethodsAndFunctions.php @@ -6,7 +6,7 @@ class MethodsAndFunctions { - public function testMethodsAndFunctions($arg1, &$arg2, $arg3 = []) + public function testMethodsAndFunctions($arg1, &$arg2, $arg3 = []): void { // Visibility MUST be declared on all methods. // @@ -20,13 +20,13 @@ public function testMethodsAndFunctions($arg1, &$arg2, $arg3 = []) // NOT be a space after the opening parenthesis, and there MUST NOT be a // space before the closing parenthesis. - function fooBar($arg1, &$arg2, $arg3 = []) + function fooBar($arg1, &$arg2, $arg3 = []): void { // function body } } - public function testOneSingleLineBetweenMethods() + public function testOneSingleLineBetweenMethods(): void { // There MUST be a single empty line between methods in a class. } diff --git a/test/fixed/4.5.MethodAndFunctionArguments.php b/test/fixed/4.5.MethodAndFunctionArguments.php index ded96d0..9da0d45 100644 --- a/test/fixed/4.5.MethodAndFunctionArguments.php +++ b/test/fixed/4.5.MethodAndFunctionArguments.php @@ -74,7 +74,7 @@ public function testVariadicThreeDotOperator(string $foo, &...$baz): void // When combining both the reference operator and the variadic three dot // operator, there MUST NOT be any space between the two of them. - function method($a, $b, ...$c) + function method($a, $b, ...$c): void { if ($a < $b) { method(...func_get_args()); diff --git a/test/fixed/6.Operators.php b/test/fixed/6.Operators.php index 7e111ef..19fb810 100644 --- a/test/fixed/6.Operators.php +++ b/test/fixed/6.Operators.php @@ -65,7 +65,7 @@ public function testOperatorSpacing(): void $result *= 4; } - public function testObjectOperatorSpacing() + public function testObjectOperatorSpacing(): void { // There MAY NOT be any white space around the object operator unless // multilines are used. diff --git a/test/fixed/7.Closures.php b/test/fixed/7.Closures.php index ed05e72..966f2ed 100644 --- a/test/fixed/7.Closures.php +++ b/test/fixed/7.Closures.php @@ -37,11 +37,11 @@ public function testClosures(): void // MUST follow the use list closing parentheses with no spaces between // the two characters. - $closureWithArgs = function ($arg1, $arg2) { + $closureWithArgs = function ($arg1, $arg2): void { echo "$arg1, $arg2"; }; - $closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2) { + $closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2): void { echo "$arg1, $arg2, $var1, $var2"; }; @@ -65,7 +65,7 @@ public function testInheritedVariablesMustBeUsed(): void // Inherited variables passed via `use` MUST be used in closures. $message = 'world'; - $example = function ($arg) use ($message) { + $example = function ($arg) use ($message): void { echo "$arg $message"; }; $example('hello'); diff --git a/test/fixed/9.GenericTypeHintSyntax.php b/test/fixed/9.GenericTypeHintSyntax.php new file mode 100644 index 0000000..10f4101 --- /dev/null +++ b/test/fixed/9.GenericTypeHintSyntax.php @@ -0,0 +1,36 @@ + */ + private $bar; + + /** + * @param IteratorAggregate $bar + */ + public function __construct(ArrayObject $bar) + { + $this->bar = $bar; + } + + /** + * @param array $config + */ + public function doSomethingWithArray(array $config): void + { + $this->config = $config; + } +}