diff --git a/composer.json b/composer.json index 09dd21b..9b33d6b 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": { "php": "^7.2", "dealerdirect/phpcodesniffer-composer-installer": "^0.4 || ^0.5", - "slevomat/coding-standard": "^5.0", + "slevomat/coding-standard": "dev-master", "squizlabs/php_codesniffer": "^3.3.2" }, "require-dev": { diff --git a/src/Libero/Sniffs/WhiteSpace/ObjectStaticOperatorSpacingSniff.php b/src/Libero/Sniffs/WhiteSpace/ObjectStaticOperatorSpacingSniff.php index c1cf95b..78752dd 100644 --- a/src/Libero/Sniffs/WhiteSpace/ObjectStaticOperatorSpacingSniff.php +++ b/src/Libero/Sniffs/WhiteSpace/ObjectStaticOperatorSpacingSniff.php @@ -11,7 +11,10 @@ final class ObjectStaticOperatorSpacingSniff extends BaseObjectOperatorSpacingSniff { - public function register() + /** + * @return array + */ + public function register() : array { return [T_DOUBLE_COLON]; } diff --git a/src/Libero/ruleset.xml b/src/Libero/ruleset.xml index 3393832..3e46c06 100644 --- a/src/Libero/ruleset.xml +++ b/src/Libero/ruleset.xml @@ -27,10 +27,12 @@ + + @@ -54,6 +56,7 @@ + @@ -61,6 +64,15 @@ + + + + + + + + + diff --git a/tests/RulesetTests.php b/tests/RulesetTests.php index e323d15..4d16539 100644 --- a/tests/RulesetTests.php +++ b/tests/RulesetTests.php @@ -38,7 +38,7 @@ final class RulesetTests extends TestCase /** @var Runner */ private static $codeSniffer; - public static function setUpBeforeClass() + public static function setUpBeforeClass() : void { self::$codeSniffer = new Runner(); self::$codeSniffer->config = new Config(['--standard=Libero']); @@ -48,6 +48,9 @@ public static function setUpBeforeClass() /** * @test * @dataProvider cases + * + * @param array $messages + * @param array $ignoreMessages */ public function it_finds_and_fixes_violations( string $filename, @@ -71,6 +74,9 @@ public function it_finds_and_fixes_violations( $this->assertSame($fixed, $file->fixer->getContents()); } + /** + * @return iterable> + */ public function cases() : iterable { $files = Finder::create()->files()->in(__DIR__.'/cases'); @@ -174,6 +180,9 @@ private function createFile(string $filename, string $content) : File return $file; } + /** + * @return iterable + */ private function getMessages(File $file) : iterable { foreach ([$file->getErrors(), $file->getWarnings()] as $messages) { diff --git a/tests/cases/classes/method-argument-type b/tests/cases/classes/method-argument-type new file mode 100644 index 0000000..54078f5 --- /dev/null +++ b/tests/cases/classes/method-argument-type @@ -0,0 +1,45 @@ +---DESCRIPTION--- +Method argument types must be declared +---FILENAME--- +Foo.php +---CONTENTS--- + + */ + public function grault() : array + { + } + + /** + * @return iterable + */ + public function garply() : iterable + { + } + + public function waldo() : ArrayObject + { + } +} + +---MESSAGES--- +26:12 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint +31:12 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +35:12 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +53:12 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +--- diff --git a/tests/cases/classes/method-type-case b/tests/cases/classes/method-type-case index 00bd37e..d8286cf 100644 --- a/tests/cases/classes/method-type-case +++ b/tests/cases/classes/method-type-case @@ -11,10 +11,16 @@ namespace Vendor; abstract class Foo { + /** + * @param array $qux + */ public function bar(String $baz, ARRAY $qux) : vOiD { } + /** + * @return iterable + */ abstract public function quux(Bool $quuz, OBJECT $corge) : iTeRaBlE; } @@ -27,10 +33,16 @@ namespace Vendor; abstract class Foo { + /** + * @param array $qux + */ public function bar(string $baz, array $qux) : void { } + /** + * @return iterable + */ abstract public function quux(bool $quuz, object $corge) : iterable; } diff --git a/tests/cases/classes/property-single b/tests/cases/classes/property-single index df3adb9..b2f9661 100644 --- a/tests/cases/classes/property-single +++ b/tests/cases/classes/property-single @@ -11,9 +11,10 @@ namespace Vendor; class Foo { + /** @var string */ public $bar, $baz; } ---MESSAGES--- -9:12 PSR2.Classes.PropertyDeclaration.Multiple +10:12 PSR2.Classes.PropertyDeclaration.Multiple --- diff --git a/tests/cases/classes/property-type b/tests/cases/classes/property-type new file mode 100644 index 0000000..c87c2dd --- /dev/null +++ b/tests/cases/classes/property-type @@ -0,0 +1,64 @@ +---DESCRIPTION--- +Property types must be declared +---FILENAME--- +Foo.php +---CONTENTS--- + + */ +function grault() : array +{ +} + +/** + * @return iterable + */ +function garply() : iterable +{ +} + +function waldo() : ArrayObject +{ +} + +---MESSAGES--- +20:1 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint +25:1 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +29:1 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +47:1 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +--- diff --git a/tests/cases/functions/type-case b/tests/cases/functions/type-case index f304a6f..cb1e4d5 100644 --- a/tests/cases/functions/type-case +++ b/tests/cases/functions/type-case @@ -5,10 +5,16 @@ Primitive types must be in lower case declare(strict_types=1); +/** + * @param array $baz + */ function foo(String $bar, ARRAY $baz) : vOiD { } +/** + * @return iterable + */ function qux(Bool $quux, OBJECT $quuz) : iTeRaBlE { } @@ -18,10 +24,16 @@ function qux(Bool $quux, OBJECT $quuz) : iTeRaBlE declare(strict_types=1); +/** + * @param array $baz + */ function foo(string $bar, array $baz) : void { } +/** + * @return iterable + */ function qux(bool $quux, object $quuz) : iterable { } diff --git a/tests/cases/interfaces/method-argument-type b/tests/cases/interfaces/method-argument-type new file mode 100644 index 0000000..ca37432 --- /dev/null +++ b/tests/cases/interfaces/method-argument-type @@ -0,0 +1,35 @@ +---DESCRIPTION--- +Method argument types must be declared +---FILENAME--- +Foo.php +---CONTENTS--- + + */ + public function corge() : array; + + /** + * @return iterable + */ + public function grault() : iterable; + + public function garply() : ArrayObject; +} + +---MESSAGES--- +20:12 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +22:12 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +34:12 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +--- diff --git a/tests/cases/interfaces/method-type-case b/tests/cases/interfaces/method-type-case index 4d143c8..2eeda17 100644 --- a/tests/cases/interfaces/method-type-case +++ b/tests/cases/interfaces/method-type-case @@ -11,8 +11,14 @@ namespace Vendor; interface Foo { + /** + * @param array $qux + */ public function bar(String $baz, ARRAY $qux) : vOiD; + /** + * @return iterable + */ public function quux(Bool $quuz, OBJECT $corge) : iTeRaBlE; } @@ -25,8 +31,14 @@ namespace Vendor; interface Foo { + /** + * @param array $qux + */ public function bar(string $baz, array $qux) : void; + /** + * @return iterable + */ public function quux(bool $quuz, object $corge) : iterable; } diff --git a/tests/cases/php/short-arrays b/tests/cases/php/short-arrays index 04d3fd5..4c7465d 100644 --- a/tests/cases/php/short-arrays +++ b/tests/cases/php/short-arrays @@ -11,7 +11,7 @@ $baz = array( 'qux', ); -$quux = function (array $quuz = array()) { +$quux = function (array $quuz = array()) : void { }; ---FIXED--- @@ -25,7 +25,7 @@ $baz = [ 'qux', ]; -$quux = function (array $quuz = []) { +$quux = function (array $quuz = []) : void { }; --- diff --git a/tests/cases/trait/method-argument-type b/tests/cases/trait/method-argument-type new file mode 100644 index 0000000..9657113 --- /dev/null +++ b/tests/cases/trait/method-argument-type @@ -0,0 +1,45 @@ +---DESCRIPTION--- +Method argument types must be declared +---FILENAME--- +Foo.php +---CONTENTS--- + + */ + public function grault() : array + { + } + + /** + * @return iterable + */ + public function garply() : iterable + { + } + + public function waldo() : ArrayObject + { + } +} + +---MESSAGES--- +26:12 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint +31:12 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +35:12 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +53:12 SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification +--- diff --git a/tests/cases/trait/method-type-case b/tests/cases/trait/method-type-case index ab93bb2..a167c75 100644 --- a/tests/cases/trait/method-type-case +++ b/tests/cases/trait/method-type-case @@ -11,10 +11,16 @@ namespace Vendor; trait Foo { + /** + * @param array $qux + */ public function bar(String $baz, ARRAY $qux) : vOiD { } + /** + * @return iterable + */ abstract public function quux(Bool $quuz, OBJECT $corge) : iTeRaBlE; } @@ -27,10 +33,16 @@ namespace Vendor; trait Foo { + /** + * @param array $qux + */ public function bar(string $baz, array $qux) : void { } + /** + * @return iterable + */ abstract public function quux(bool $quuz, object $corge) : iterable; } diff --git a/tests/cases/trait/property-single b/tests/cases/trait/property-single index e2d53c5..60ac03d 100644 --- a/tests/cases/trait/property-single +++ b/tests/cases/trait/property-single @@ -11,9 +11,10 @@ namespace Vendor; trait Foo { + /** @var string */ public $bar, $baz; } ---MESSAGES--- -9:12 PSR2.Classes.PropertyDeclaration.Multiple +10:12 PSR2.Classes.PropertyDeclaration.Multiple --- diff --git a/tests/cases/trait/property-type b/tests/cases/trait/property-type new file mode 100644 index 0000000..2fc8e1b --- /dev/null +++ b/tests/cases/trait/property-type @@ -0,0 +1,64 @@ +---DESCRIPTION--- +Property types must be declared +---FILENAME--- +Foo.php +---CONTENTS--- +