From a872e515bb391e76c5efd86019a11f22a7b1dc9d Mon Sep 17 00:00:00 2001 From: TomasVotruba Date: Sat, 11 Nov 2017 10:27:25 +0100 Subject: [PATCH] [cs] add and apply psr2 --- easy-coding-standard.neon | 1 + src/DocBlock.php | 3 +-- src/DocBlock/Description.php | 1 + src/DocBlock/DescriptionFactory.php | 1 - src/DocBlock/Serializer.php | 2 ++ src/DocBlock/StandardTagFactory.php | 3 +-- src/DocBlock/Tags/Covers.php | 3 +-- src/DocBlock/Tags/Method.php | 4 +++- src/DocBlock/Tags/Reference/Reference.php | 2 +- src/DocBlock/Tags/Return_.php | 3 +-- src/DocBlock/Tags/Source.php | 1 + src/DocBlockFactory.php | 2 +- .../integration/InterpretingDocBlocksTest.php | 6 +++--- .../ReconstitutingADocBlockTest.php | 1 - tests/unit/DocBlock/DescriptionFactoryTest.php | 6 ++---- tests/unit/DocBlock/StandardTagFactoryTest.php | 18 ++++++------------ tests/unit/DocBlock/Tags/MethodTest.php | 8 +++++--- tests/unit/DocBlock/Tags/PropertyReadTest.php | 8 ++++++-- tests/unit/DocBlock/Tags/PropertyWriteTest.php | 8 ++++++-- tests/unit/DocBlock/Tags/UsesTest.php | 3 +-- 20 files changed, 43 insertions(+), 41 deletions(-) diff --git a/easy-coding-standard.neon b/easy-coding-standard.neon index 435ae90..d41ddef 100644 --- a/easy-coding-standard.neon +++ b/easy-coding-standard.neon @@ -1,5 +1,6 @@ includes: - temp/ecs/config/clean-code.neon + - temp/ecs/config/psr2-checkers.neon parameters: skip: diff --git a/src/DocBlock.php b/src/DocBlock.php index 779fcf0..7e7ef3c 100644 --- a/src/DocBlock.php +++ b/src/DocBlock.php @@ -55,8 +55,7 @@ final class DocBlock Location $location = null, $isTemplateStart = false, $isTemplateEnd = false - ) - { + ) { Assert::string($summary); Assert::boolean($isTemplateStart); Assert::boolean($isTemplateEnd); diff --git a/src/DocBlock/Description.php b/src/DocBlock/Description.php index c63cae5..70fd131 100644 --- a/src/DocBlock/Description.php +++ b/src/DocBlock/Description.php @@ -98,6 +98,7 @@ class Description foreach ($this->tags as $tag) { $tags[] = '{' . $formatter->format($tag) . '}'; } + return vsprintf($this->bodyTemplate, $tags); } diff --git a/src/DocBlock/DescriptionFactory.php b/src/DocBlock/DescriptionFactory.php index f34d0f7..48f9c21 100644 --- a/src/DocBlock/DescriptionFactory.php +++ b/src/DocBlock/DescriptionFactory.php @@ -188,5 +188,4 @@ class DescriptionFactory return implode("\n", $lines); } - } diff --git a/src/DocBlock/Serializer.php b/src/DocBlock/Serializer.php index e0faacb..007c939 100644 --- a/src/DocBlock/Serializer.php +++ b/src/DocBlock/Serializer.php @@ -121,6 +121,7 @@ class Serializer $text = wordwrap($text, $wrapLength); return $text; } + return $text; } @@ -138,6 +139,7 @@ class Serializer if ($wrapLength !== null) { $tagText = wordwrap($tagText, $wrapLength); } + $tagText = str_replace("\n", "\n{$indent} * ", $tagText); $comment .= "{$indent} * {$tagText}\n"; diff --git a/src/DocBlock/StandardTagFactory.php b/src/DocBlock/StandardTagFactory.php index 5fc1f0a..5a8143c 100644 --- a/src/DocBlock/StandardTagFactory.php +++ b/src/DocBlock/StandardTagFactory.php @@ -196,8 +196,7 @@ final class StandardTagFactory implements TagFactory $arguments = $this->getArgumentsForParametersFromWiring( $this->fetchParametersForHandlerFactoryMethod($handlerClassName), $this->getServiceLocatorWithDynamicParameters($context, $name, $body) - ) - ; + ); return call_user_func_array([$handlerClassName, 'create'], $arguments); } diff --git a/src/DocBlock/Tags/Covers.php b/src/DocBlock/Tags/Covers.php index e540bfb..8d65403 100644 --- a/src/DocBlock/Tags/Covers.php +++ b/src/DocBlock/Tags/Covers.php @@ -49,8 +49,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod DescriptionFactory $descriptionFactory = null, FqsenResolver $resolver = null, TypeContext $context = null - ) - { + ) { Assert::string($body); Assert::notEmpty($body); diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 15998ed..7522529 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -135,7 +135,7 @@ final class Method extends BaseTag implements Factory\StaticMethod if (is_string($arguments) && strlen($arguments) > 0) { $arguments = explode(',', $arguments); - foreach($arguments as &$argument) { + foreach ($arguments as &$argument) { $argument = explode(' ', self::stripRestArg(trim($argument)), 2); if ($argument[0][0] === '$') { $argumentName = substr($argument[0], 1); @@ -214,9 +214,11 @@ final class Method extends BaseTag implements Factory\StaticMethod if (is_string($argument)) { $argument = [ 'name' => $argument ]; } + if (! isset($argument['type'])) { $argument['type'] = new Void_(); } + $keys = array_keys($argument); sort($keys); if ($keys !== [ 'name', 'type' ]) { diff --git a/src/DocBlock/Tags/Reference/Reference.php b/src/DocBlock/Tags/Reference/Reference.php index 5bf27d3..a3ffd24 100644 --- a/src/DocBlock/Tags/Reference/Reference.php +++ b/src/DocBlock/Tags/Reference/Reference.php @@ -17,5 +17,5 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Reference; */ interface Reference { - public function __toString(); + public function __toString(); } diff --git a/src/DocBlock/Tags/Return_.php b/src/DocBlock/Tags/Return_.php index 09a5870..ca5bda7 100644 --- a/src/DocBlock/Tags/Return_.php +++ b/src/DocBlock/Tags/Return_.php @@ -43,8 +43,7 @@ final class Return_ extends BaseTag implements Factory\StaticMethod TypeResolver $typeResolver = null, DescriptionFactory $descriptionFactory = null, TypeContext $context = null - ) - { + ) { Assert::string($body); Assert::allNotNull([$typeResolver, $descriptionFactory]); diff --git a/src/DocBlock/Tags/Source.php b/src/DocBlock/Tags/Source.php index b0646b9..247b1b3 100644 --- a/src/DocBlock/Tags/Source.php +++ b/src/DocBlock/Tags/Source.php @@ -59,6 +59,7 @@ final class Source extends BaseTag implements Factory\StaticMethod if (isset($matches[2]) && $matches[2] !== '') { $lineCount = (int)$matches[2]; } + $description = $matches[3]; } diff --git a/src/DocBlockFactory.php b/src/DocBlockFactory.php index 4683fb4..880cc05 100644 --- a/src/DocBlockFactory.php +++ b/src/DocBlockFactory.php @@ -93,7 +93,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface return new DocBlock( $summary, $description ? $this->descriptionFactory->create($description, $context) : null, - array_filter($this->parseTagBlock($tags, $context), function($tag) { + array_filter($this->parseTagBlock($tags, $context), function ($tag) { return $tag instanceof Tag; }), $context, diff --git a/tests/integration/InterpretingDocBlocksTest.php b/tests/integration/InterpretingDocBlocksTest.php index 91b8eb3..5f4c84e 100644 --- a/tests/integration/InterpretingDocBlocksTest.php +++ b/tests/integration/InterpretingDocBlocksTest.php @@ -78,7 +78,8 @@ DESCRIPTION; */ include(__DIR__ . '/../../examples/playing-with-descriptions/02-escaping.php'); - $this->assertSame(<<<'DESCRIPTION' + $this->assertSame( + <<<'DESCRIPTION' You can escape the @-sign by surrounding it with braces, for example: @. And escape a closing brace within an inline tag by adding an opening brace in front of it like this: }. @@ -91,7 +92,6 @@ Do note that an {@internal inline tag that has an opening brace ({) does not bre DESCRIPTION , $foundDescription - ) - ; + ); } } diff --git a/tests/integration/ReconstitutingADocBlockTest.php b/tests/integration/ReconstitutingADocBlockTest.php index 008b221..f915826 100644 --- a/tests/integration/ReconstitutingADocBlockTest.php +++ b/tests/integration/ReconstitutingADocBlockTest.php @@ -12,7 +12,6 @@ namespace phpDocumentor\Reflection; - /** * @coversNothing */ diff --git a/tests/unit/DocBlock/DescriptionFactoryTest.php b/tests/unit/DocBlock/DescriptionFactoryTest.php index d3043f9..10a6f03 100644 --- a/tests/unit/DocBlock/DescriptionFactoryTest.php +++ b/tests/unit/DocBlock/DescriptionFactoryTest.php @@ -73,8 +73,7 @@ class DescriptionFactoryTest extends \PHPUnit_Framework_TestCase $tagFactory->shouldReceive('create') ->once() ->with('@link http://phpdoc.org/ description', $context) - ->andReturn(new Link('http://phpdoc.org/', new Description('description'))) - ; + ->andReturn(new Link('http://phpdoc.org/', new Description('description'))); $factory = new DescriptionFactory($tagFactory); $description = $factory->create($contents, $context); @@ -99,8 +98,7 @@ class DescriptionFactoryTest extends \PHPUnit_Framework_TestCase $tagFactory->shouldReceive('create') ->once() ->with('@link http://phpdoc.org/ This', $context) - ->andReturn(new Link('http://phpdoc.org/', new Description('This'))) - ; + ->andReturn(new Link('http://phpdoc.org/', new Description('This'))); $factory = new DescriptionFactory($tagFactory); $description = $factory->create($contents, $context); diff --git a/tests/unit/DocBlock/StandardTagFactoryTest.php b/tests/unit/DocBlock/StandardTagFactoryTest.php index a5ace16..51e7633 100644 --- a/tests/unit/DocBlock/StandardTagFactoryTest.php +++ b/tests/unit/DocBlock/StandardTagFactoryTest.php @@ -50,8 +50,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase ->shouldReceive('create') ->once() ->with($expectedDescriptionText, $context) - ->andReturn($expectedDescription) - ; + ->andReturn($expectedDescription); $tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class)); $tagFactory->addService($descriptionFactory, DescriptionFactory::class); @@ -99,8 +98,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase ->shouldReceive('resolve') ->with('Tag', m::type(Context::class)) ->andReturn(new Fqsen($fqsen)) - ->getMock() - ; + ->getMock(); $descriptionFactory = m::mock(DescriptionFactory::class); $descriptionFactory->shouldIgnoreMissing(); @@ -161,8 +159,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase [FqsenResolver::class => $resolver, 'myParam' => 'myValue'], 'serviceLocator', $tagFactory - ) - ; + ); } /** @@ -181,8 +178,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase [FqsenResolver::class => $resolver, PassthroughFormatter::class => $service], 'serviceLocator', $tagFactory - ) - ; + ); } /** @@ -202,8 +198,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase [FqsenResolver::class => $resolver, $interfaceName => $service], 'serviceLocator', $tagFactory - ) - ; + ); } /** @@ -340,8 +335,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase ->shouldReceive('create') ->once() ->with('', $context) - ->andReturn(new Description('')) - ; + ->andReturn(new Description('')); $typeResolver = new TypeResolver(); diff --git a/tests/unit/DocBlock/Tags/MethodTest.php b/tests/unit/DocBlock/Tags/MethodTest.php index 5860abd..6a1f4c7 100644 --- a/tests/unit/DocBlock/Tags/MethodTest.php +++ b/tests/unit/DocBlock/Tags/MethodTest.php @@ -342,7 +342,8 @@ class MethodTest extends \PHPUnit_Framework_TestCase $expectedType, $expectedValueType = null, $expectedKeyType = null - ) { $resolver = new TypeResolver(); + ) { + $resolver = new TypeResolver(); $descriptionFactory = m::mock(DescriptionFactory::class); $descriptionFactory->shouldReceive('create')->with('', null)->andReturn(new Description('')); @@ -540,7 +541,8 @@ class MethodTest extends \PHPUnit_Framework_TestCase new Compound([ new Array_(new Object_(new Fqsen('\MyClass'))), new Array_(new Integer()), - ]) - , $fixture->getReturnType()); + ]), + $fixture->getReturnType() + ); } } diff --git a/tests/unit/DocBlock/Tags/PropertyReadTest.php b/tests/unit/DocBlock/Tags/PropertyReadTest.php index c3fb770..582479c 100644 --- a/tests/unit/DocBlock/Tags/PropertyReadTest.php +++ b/tests/unit/DocBlock/Tags/PropertyReadTest.php @@ -140,8 +140,12 @@ class PropertyReadTest extends \PHPUnit_Framework_TestCase $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); - $fixture = PropertyRead::create('string $myProperty My Description', $typeResolver, $descriptionFactory, - $context); + $fixture = PropertyRead::create( + 'string $myProperty My Description', + $typeResolver, + $descriptionFactory, + $context + ); $this->assertSame('string $myProperty My Description', (string)$fixture); $this->assertSame('myProperty', $fixture->getVariableName()); diff --git a/tests/unit/DocBlock/Tags/PropertyWriteTest.php b/tests/unit/DocBlock/Tags/PropertyWriteTest.php index 5ea6524..d0f8a13 100644 --- a/tests/unit/DocBlock/Tags/PropertyWriteTest.php +++ b/tests/unit/DocBlock/Tags/PropertyWriteTest.php @@ -140,8 +140,12 @@ class PropertyWriteTest extends \PHPUnit_Framework_TestCase $description = new Description('My Description'); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); - $fixture = PropertyWrite::create('string $myProperty My Description', $typeResolver, $descriptionFactory, - $context); + $fixture = PropertyWrite::create( + 'string $myProperty My Description', + $typeResolver, + $descriptionFactory, + $context + ); $this->assertSame('string $myProperty My Description', (string)$fixture); $this->assertSame('myProperty', $fixture->getVariableName()); diff --git a/tests/unit/DocBlock/Tags/UsesTest.php b/tests/unit/DocBlock/Tags/UsesTest.php index 419f7e3..9fbe5f7 100644 --- a/tests/unit/DocBlock/Tags/UsesTest.php +++ b/tests/unit/DocBlock/Tags/UsesTest.php @@ -125,8 +125,7 @@ class UsesTest extends \PHPUnit_Framework_TestCase $description = new Description('My Description'); $descriptionFactory - ->shouldReceive('create')->with('My Description', $context)->andReturn($description) - ; + ->shouldReceive('create')->with('My Description', $context)->andReturn($description); $resolver->shouldReceive('resolve')->with('DateTime', $context)->andReturn($fqsen); $fixture = Uses::create('DateTime My Description', $resolver, $descriptionFactory, $context);