[cs] add and apply psr2

This commit is contained in:
TomasVotruba
2017-11-12 21:23:54 +01:00
committed by Jaap van Otterdijk
parent 0294ce9b70
commit a872e515bb
20 changed files with 43 additions and 41 deletions
+1
View File
@@ -1,5 +1,6 @@
includes: includes:
- temp/ecs/config/clean-code.neon - temp/ecs/config/clean-code.neon
- temp/ecs/config/psr2-checkers.neon
parameters: parameters:
skip: skip:
+1 -2
View File
@@ -55,8 +55,7 @@ final class DocBlock
Location $location = null, Location $location = null,
$isTemplateStart = false, $isTemplateStart = false,
$isTemplateEnd = false $isTemplateEnd = false
) ) {
{
Assert::string($summary); Assert::string($summary);
Assert::boolean($isTemplateStart); Assert::boolean($isTemplateStart);
Assert::boolean($isTemplateEnd); Assert::boolean($isTemplateEnd);
+1
View File
@@ -98,6 +98,7 @@ class Description
foreach ($this->tags as $tag) { foreach ($this->tags as $tag) {
$tags[] = '{' . $formatter->format($tag) . '}'; $tags[] = '{' . $formatter->format($tag) . '}';
} }
return vsprintf($this->bodyTemplate, $tags); return vsprintf($this->bodyTemplate, $tags);
} }
-1
View File
@@ -188,5 +188,4 @@ class DescriptionFactory
return implode("\n", $lines); return implode("\n", $lines);
} }
} }
+2
View File
@@ -121,6 +121,7 @@ class Serializer
$text = wordwrap($text, $wrapLength); $text = wordwrap($text, $wrapLength);
return $text; return $text;
} }
return $text; return $text;
} }
@@ -138,6 +139,7 @@ class Serializer
if ($wrapLength !== null) { if ($wrapLength !== null) {
$tagText = wordwrap($tagText, $wrapLength); $tagText = wordwrap($tagText, $wrapLength);
} }
$tagText = str_replace("\n", "\n{$indent} * ", $tagText); $tagText = str_replace("\n", "\n{$indent} * ", $tagText);
$comment .= "{$indent} * {$tagText}\n"; $comment .= "{$indent} * {$tagText}\n";
+1 -2
View File
@@ -196,8 +196,7 @@ final class StandardTagFactory implements TagFactory
$arguments = $this->getArgumentsForParametersFromWiring( $arguments = $this->getArgumentsForParametersFromWiring(
$this->fetchParametersForHandlerFactoryMethod($handlerClassName), $this->fetchParametersForHandlerFactoryMethod($handlerClassName),
$this->getServiceLocatorWithDynamicParameters($context, $name, $body) $this->getServiceLocatorWithDynamicParameters($context, $name, $body)
) );
;
return call_user_func_array([$handlerClassName, 'create'], $arguments); return call_user_func_array([$handlerClassName, 'create'], $arguments);
} }
+1 -2
View File
@@ -49,8 +49,7 @@ final class Covers extends BaseTag implements Factory\StaticMethod
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
FqsenResolver $resolver = null, FqsenResolver $resolver = null,
TypeContext $context = null TypeContext $context = null
) ) {
{
Assert::string($body); Assert::string($body);
Assert::notEmpty($body); Assert::notEmpty($body);
+3 -1
View File
@@ -135,7 +135,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
if (is_string($arguments) && strlen($arguments) > 0) { if (is_string($arguments) && strlen($arguments) > 0) {
$arguments = explode(',', $arguments); $arguments = explode(',', $arguments);
foreach($arguments as &$argument) { foreach ($arguments as &$argument) {
$argument = explode(' ', self::stripRestArg(trim($argument)), 2); $argument = explode(' ', self::stripRestArg(trim($argument)), 2);
if ($argument[0][0] === '$') { if ($argument[0][0] === '$') {
$argumentName = substr($argument[0], 1); $argumentName = substr($argument[0], 1);
@@ -214,9 +214,11 @@ final class Method extends BaseTag implements Factory\StaticMethod
if (is_string($argument)) { if (is_string($argument)) {
$argument = [ 'name' => $argument ]; $argument = [ 'name' => $argument ];
} }
if (! isset($argument['type'])) { if (! isset($argument['type'])) {
$argument['type'] = new Void_(); $argument['type'] = new Void_();
} }
$keys = array_keys($argument); $keys = array_keys($argument);
sort($keys); sort($keys);
if ($keys !== [ 'name', 'type' ]) { if ($keys !== [ 'name', 'type' ]) {
+1 -1
View File
@@ -17,5 +17,5 @@ namespace phpDocumentor\Reflection\DocBlock\Tags\Reference;
*/ */
interface Reference interface Reference
{ {
public function __toString(); public function __toString();
} }
+1 -2
View File
@@ -43,8 +43,7 @@ final class Return_ extends BaseTag implements Factory\StaticMethod
TypeResolver $typeResolver = null, TypeResolver $typeResolver = null,
DescriptionFactory $descriptionFactory = null, DescriptionFactory $descriptionFactory = null,
TypeContext $context = null TypeContext $context = null
) ) {
{
Assert::string($body); Assert::string($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]); Assert::allNotNull([$typeResolver, $descriptionFactory]);
+1
View File
@@ -59,6 +59,7 @@ final class Source extends BaseTag implements Factory\StaticMethod
if (isset($matches[2]) && $matches[2] !== '') { if (isset($matches[2]) && $matches[2] !== '') {
$lineCount = (int)$matches[2]; $lineCount = (int)$matches[2];
} }
$description = $matches[3]; $description = $matches[3];
} }
+1 -1
View File
@@ -93,7 +93,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
return new DocBlock( return new DocBlock(
$summary, $summary,
$description ? $this->descriptionFactory->create($description, $context) : null, $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; return $tag instanceof Tag;
}), }),
$context, $context,
@@ -78,7 +78,8 @@ DESCRIPTION;
*/ */
include(__DIR__ . '/../../examples/playing-with-descriptions/02-escaping.php'); 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 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: }. 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 DESCRIPTION
, ,
$foundDescription $foundDescription
) );
;
} }
} }
@@ -12,7 +12,6 @@
namespace phpDocumentor\Reflection; namespace phpDocumentor\Reflection;
/** /**
* @coversNothing * @coversNothing
*/ */
@@ -73,8 +73,7 @@ class DescriptionFactoryTest extends \PHPUnit_Framework_TestCase
$tagFactory->shouldReceive('create') $tagFactory->shouldReceive('create')
->once() ->once()
->with('@link http://phpdoc.org/ description', $context) ->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); $factory = new DescriptionFactory($tagFactory);
$description = $factory->create($contents, $context); $description = $factory->create($contents, $context);
@@ -99,8 +98,7 @@ class DescriptionFactoryTest extends \PHPUnit_Framework_TestCase
$tagFactory->shouldReceive('create') $tagFactory->shouldReceive('create')
->once() ->once()
->with('@link http://phpdoc.org/ This', $context) ->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); $factory = new DescriptionFactory($tagFactory);
$description = $factory->create($contents, $context); $description = $factory->create($contents, $context);
+6 -12
View File
@@ -50,8 +50,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase
->shouldReceive('create') ->shouldReceive('create')
->once() ->once()
->with($expectedDescriptionText, $context) ->with($expectedDescriptionText, $context)
->andReturn($expectedDescription) ->andReturn($expectedDescription);
;
$tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class)); $tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class));
$tagFactory->addService($descriptionFactory, DescriptionFactory::class); $tagFactory->addService($descriptionFactory, DescriptionFactory::class);
@@ -99,8 +98,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase
->shouldReceive('resolve') ->shouldReceive('resolve')
->with('Tag', m::type(Context::class)) ->with('Tag', m::type(Context::class))
->andReturn(new Fqsen($fqsen)) ->andReturn(new Fqsen($fqsen))
->getMock() ->getMock();
;
$descriptionFactory = m::mock(DescriptionFactory::class); $descriptionFactory = m::mock(DescriptionFactory::class);
$descriptionFactory->shouldIgnoreMissing(); $descriptionFactory->shouldIgnoreMissing();
@@ -161,8 +159,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase
[FqsenResolver::class => $resolver, 'myParam' => 'myValue'], [FqsenResolver::class => $resolver, 'myParam' => 'myValue'],
'serviceLocator', 'serviceLocator',
$tagFactory $tagFactory
) );
;
} }
/** /**
@@ -181,8 +178,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase
[FqsenResolver::class => $resolver, PassthroughFormatter::class => $service], [FqsenResolver::class => $resolver, PassthroughFormatter::class => $service],
'serviceLocator', 'serviceLocator',
$tagFactory $tagFactory
) );
;
} }
/** /**
@@ -202,8 +198,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase
[FqsenResolver::class => $resolver, $interfaceName => $service], [FqsenResolver::class => $resolver, $interfaceName => $service],
'serviceLocator', 'serviceLocator',
$tagFactory $tagFactory
) );
;
} }
/** /**
@@ -340,8 +335,7 @@ class StandardTagFactoryTest extends \PHPUnit_Framework_TestCase
->shouldReceive('create') ->shouldReceive('create')
->once() ->once()
->with('', $context) ->with('', $context)
->andReturn(new Description('')) ->andReturn(new Description(''));
;
$typeResolver = new TypeResolver(); $typeResolver = new TypeResolver();
+5 -3
View File
@@ -342,7 +342,8 @@ class MethodTest extends \PHPUnit_Framework_TestCase
$expectedType, $expectedType,
$expectedValueType = null, $expectedValueType = null,
$expectedKeyType = null $expectedKeyType = null
) { $resolver = new TypeResolver(); ) {
$resolver = new TypeResolver();
$descriptionFactory = m::mock(DescriptionFactory::class); $descriptionFactory = m::mock(DescriptionFactory::class);
$descriptionFactory->shouldReceive('create')->with('', null)->andReturn(new Description('')); $descriptionFactory->shouldReceive('create')->with('', null)->andReturn(new Description(''));
@@ -540,7 +541,8 @@ class MethodTest extends \PHPUnit_Framework_TestCase
new Compound([ new Compound([
new Array_(new Object_(new Fqsen('\MyClass'))), new Array_(new Object_(new Fqsen('\MyClass'))),
new Array_(new Integer()), new Array_(new Integer()),
]) ]),
, $fixture->getReturnType()); $fixture->getReturnType()
);
} }
} }
@@ -140,8 +140,12 @@ class PropertyReadTest extends \PHPUnit_Framework_TestCase
$description = new Description('My Description'); $description = new Description('My Description');
$descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description);
$fixture = PropertyRead::create('string $myProperty My Description', $typeResolver, $descriptionFactory, $fixture = PropertyRead::create(
$context); 'string $myProperty My Description',
$typeResolver,
$descriptionFactory,
$context
);
$this->assertSame('string $myProperty My Description', (string)$fixture); $this->assertSame('string $myProperty My Description', (string)$fixture);
$this->assertSame('myProperty', $fixture->getVariableName()); $this->assertSame('myProperty', $fixture->getVariableName());
@@ -140,8 +140,12 @@ class PropertyWriteTest extends \PHPUnit_Framework_TestCase
$description = new Description('My Description'); $description = new Description('My Description');
$descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description); $descriptionFactory->shouldReceive('create')->with('My Description', $context)->andReturn($description);
$fixture = PropertyWrite::create('string $myProperty My Description', $typeResolver, $descriptionFactory, $fixture = PropertyWrite::create(
$context); 'string $myProperty My Description',
$typeResolver,
$descriptionFactory,
$context
);
$this->assertSame('string $myProperty My Description', (string)$fixture); $this->assertSame('string $myProperty My Description', (string)$fixture);
$this->assertSame('myProperty', $fixture->getVariableName()); $this->assertSame('myProperty', $fixture->getVariableName());
+1 -2
View File
@@ -125,8 +125,7 @@ class UsesTest extends \PHPUnit_Framework_TestCase
$description = new Description('My Description'); $description = new Description('My Description');
$descriptionFactory $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); $resolver->shouldReceive('resolve')->with('DateTime', $context)->andReturn($fqsen);
$fixture = Uses::create('DateTime My Description', $resolver, $descriptionFactory, $context); $fixture = Uses::create('DateTime My Description', $resolver, $descriptionFactory, $context);