apply coding standard to code

This commit is contained in:
TomasVotruba
2018-01-02 13:40:57 +01:00
parent 89a0935960
commit 1c8f795c0e
45 changed files with 212 additions and 216 deletions
+3 -3
View File
@@ -112,7 +112,7 @@ class DescriptionFactory
{
$count = count($tokens);
$tagCount = 0;
$tags = [];
$tags = [];
for ($i = 1; $i < $count; $i += 2) {
$tags[] = $this->tagFactory->create($tokens[$i], $context);
@@ -156,7 +156,7 @@ class DescriptionFactory
// determine how many whitespace characters need to be stripped
$startingSpaceCount = 9999999;
for ($i = 1; $i < count($lines); $i++) {
for ($i = 1; $i < count($lines); ++$i) {
// lines with a no length do not count as they are not indented at all
if (strlen(trim($lines[$i])) === 0) {
continue;
@@ -169,7 +169,7 @@ class DescriptionFactory
// strip the number of spaces from each line
if ($startingSpaceCount > 0) {
for ($i = 1; $i < count($lines); $i++) {
for ($i = 1; $i < count($lines); ++$i) {
$lines[$i] = substr($lines[$i], $startingSpaceCount);
}
}
+1 -1
View File
@@ -105,7 +105,7 @@ class Serializer
private function getSummaryAndDescriptionTextBlock(DocBlock $docblock, $wrapLength): string
{
$text = $docblock->getSummary() . ((string)$docblock->getDescription() ? "\n\n" . $docblock->getDescription()
$text = $docblock->getSummary() . ((string) $docblock->getDescription() ? "\n\n" . $docblock->getDescription()
: '');
if ($wrapLength !== null) {
$text = wordwrap($text, $wrapLength);
+22 -22
View File
@@ -45,25 +45,25 @@ final class StandardTagFactory implements TagFactory
* @var string[] An array with a tag as a key, and an FQCN to a class that handles it as an array value.
*/
private $tagHandlerMappings = [
'author' => '\phpDocumentor\Reflection\DocBlock\Tags\Author',
'covers' => '\phpDocumentor\Reflection\DocBlock\Tags\Covers',
'deprecated' => '\phpDocumentor\Reflection\DocBlock\Tags\Deprecated',
'author' => '\phpDocumentor\Reflection\DocBlock\Tags\Author',
'covers' => '\phpDocumentor\Reflection\DocBlock\Tags\Covers',
'deprecated' => '\phpDocumentor\Reflection\DocBlock\Tags\Deprecated',
// 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example',
'link' => '\phpDocumentor\Reflection\DocBlock\Tags\Link',
'method' => '\phpDocumentor\Reflection\DocBlock\Tags\Method',
'param' => '\phpDocumentor\Reflection\DocBlock\Tags\Param',
'property-read' => '\phpDocumentor\Reflection\DocBlock\Tags\PropertyRead',
'property' => '\phpDocumentor\Reflection\DocBlock\Tags\Property',
'link' => '\phpDocumentor\Reflection\DocBlock\Tags\Link',
'method' => '\phpDocumentor\Reflection\DocBlock\Tags\Method',
'param' => '\phpDocumentor\Reflection\DocBlock\Tags\Param',
'property-read' => '\phpDocumentor\Reflection\DocBlock\Tags\PropertyRead',
'property' => '\phpDocumentor\Reflection\DocBlock\Tags\Property',
'property-write' => '\phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite',
'return' => '\phpDocumentor\Reflection\DocBlock\Tags\Return_',
'see' => '\phpDocumentor\Reflection\DocBlock\Tags\See',
'since' => '\phpDocumentor\Reflection\DocBlock\Tags\Since',
'source' => '\phpDocumentor\Reflection\DocBlock\Tags\Source',
'throw' => '\phpDocumentor\Reflection\DocBlock\Tags\Throws',
'throws' => '\phpDocumentor\Reflection\DocBlock\Tags\Throws',
'uses' => '\phpDocumentor\Reflection\DocBlock\Tags\Uses',
'var' => '\phpDocumentor\Reflection\DocBlock\Tags\Var_',
'version' => '\phpDocumentor\Reflection\DocBlock\Tags\Version'
'return' => '\phpDocumentor\Reflection\DocBlock\Tags\Return_',
'see' => '\phpDocumentor\Reflection\DocBlock\Tags\See',
'since' => '\phpDocumentor\Reflection\DocBlock\Tags\Since',
'source' => '\phpDocumentor\Reflection\DocBlock\Tags\Source',
'throw' => '\phpDocumentor\Reflection\DocBlock\Tags\Throws',
'throws' => '\phpDocumentor\Reflection\DocBlock\Tags\Throws',
'uses' => '\phpDocumentor\Reflection\DocBlock\Tags\Uses',
'var' => '\phpDocumentor\Reflection\DocBlock\Tags\Var_',
'version' => '\phpDocumentor\Reflection\DocBlock\Tags\Version',
];
/**
@@ -186,7 +186,7 @@ final class StandardTagFactory implements TagFactory
private function createTag(string $body, string $name, TypeContext $context): ?Tag
{
$handlerClassName = $this->findHandlerClassName($name, $context);
$arguments = $this->getArgumentsForParametersFromWiring(
$arguments = $this->getArgumentsForParametersFromWiring(
$this->fetchParametersForHandlerFactoryMethod($handlerClassName),
$this->getServiceLocatorWithDynamicParameters($context, $name, $body)
);
@@ -254,7 +254,7 @@ final class StandardTagFactory implements TagFactory
private function fetchParametersForHandlerFactoryMethod(string $handlerClassName)
{
if (! isset($this->tagHandlerParameterCache[$handlerClassName])) {
$methodReflection = new \ReflectionMethod($handlerClassName, 'create');
$methodReflection = new \ReflectionMethod($handlerClassName, 'create');
$this->tagHandlerParameterCache[$handlerClassName] = $methodReflection->getParameters();
}
@@ -276,9 +276,9 @@ final class StandardTagFactory implements TagFactory
$locator = array_merge(
$this->serviceLocator,
[
'name' => $tagName,
'body' => $tagBody,
TypeContext::class => $context
'name' => $tagName,
'body' => $tagBody,
TypeContext::class => $context,
]
);
+1 -1
View File
@@ -36,7 +36,7 @@ final class Author extends BaseTag implements Factory\StaticMethod
throw new \InvalidArgumentException('The author tag does not have a valid e-mail address');
}
$this->authorName = $authorName;
$this->authorName = $authorName;
$this->authorEmail = $authorEmail;
}
+7 -7
View File
@@ -69,7 +69,7 @@ final class Example extends BaseTag
if ($this->isURI) {
$filePath = $this->isUriRelative($this->filePath)
? str_replace('%2F', '/', rawurlencode($this->filePath))
:$this->filePath;
: $this->filePath;
}
return trim($filePath . ' ' . parent::getDescription());
@@ -89,7 +89,7 @@ final class Example extends BaseTag
}
$filePath = null;
$fileUri = null;
$fileUri = null;
if ('' !== $matches[1]) {
$filePath = $matches[1];
} else {
@@ -97,17 +97,17 @@ final class Example extends BaseTag
}
$startingLine = 1;
$lineCount = null;
$description = null;
$lineCount = null;
$description = null;
if (array_key_exists(3, $matches)) {
$description = $matches[3];
// Starting line / Number of lines / Description
if (preg_match('/^([1-9]\d*)(?:\s+((?1))\s*)?(.*)$/sux', $matches[3], $contentMatches)) {
$startingLine = (int)$contentMatches[1];
$startingLine = (int) $contentMatches[1];
if (isset($contentMatches[2]) && $contentMatches[2] !== '') {
$lineCount = (int)$contentMatches[2];
$lineCount = (int) $contentMatches[2];
}
if (array_key_exists(3, $contentMatches)) {
@@ -117,7 +117,7 @@ final class Example extends BaseTag
}
return new static(
$filePath !== null?$filePath:$fileUri,
$filePath !== null ? $filePath : $fileUri,
$fileUri !== null,
$startingLine,
$lineCount,
@@ -39,6 +39,6 @@ class AlignFormatter implements Formatter
*/
public function format(Tag $tag): string
{
return '@' . $tag->getName() . str_repeat(' ', $this->maxLen - strlen($tag->getName()) + 1) . (string)$tag;
return '@' . $tag->getName() . str_repeat(' ', $this->maxLen - strlen($tag->getName()) + 1) . (string) $tag;
}
}
@@ -23,6 +23,6 @@ class PassthroughFormatter implements Formatter
*/
public function format(Tag $tag): string
{
return trim('@' . $tag->getName() . ' ' . (string)$tag);
return trim('@' . $tag->getName() . ' ' . (string) $tag);
}
}
+1 -1
View File
@@ -40,7 +40,7 @@ final class Link extends BaseTag implements Factory\StaticMethod
/**
* {@inheritdoc}
*/
public static function create(string $body, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null): Link
public static function create(string $body, ?DescriptionFactory $descriptionFactory = null, ?TypeContext $context = null): self
{
Assert::notNull($descriptionFactory);
+10 -10
View File
@@ -54,10 +54,10 @@ final class Method extends BaseTag implements Factory\StaticMethod
$returnType = new Void_();
}
$this->methodName = $methodName;
$this->arguments = $this->filterArguments($arguments);
$this->returnType = $returnType;
$this->isStatic = $static;
$this->methodName = $methodName;
$this->arguments = $this->filterArguments($arguments);
$this->returnType = $returnType;
$this->isStatic = $static;
$this->description = $description;
}
@@ -71,7 +71,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
?TypeContext $context = null
): ?self {
Assert::stringNotEmpty($body);
Assert::allNotNull([ $typeResolver, $descriptionFactory ]);
Assert::allNotNull([$typeResolver, $descriptionFactory]);
// 1. none or more whitespace
// 2. optionally the keyword "static" followed by whitespace
@@ -131,7 +131,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
$returnType = 'void';
}
$returnType = $typeResolver->resolve($returnType, $context);
$returnType = $typeResolver->resolve($returnType, $context);
$description = $descriptionFactory->create($description, $context);
if (is_string($arguments) && strlen($arguments) > 0) {
@@ -150,7 +150,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
}
}
$argument = [ 'name' => $argumentName, 'type' => $argumentType];
$argument = ['name' => $argumentName, 'type' => $argumentType];
}
} else {
$arguments = [];
@@ -198,7 +198,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
}
return trim(($this->isStatic() ? 'static ' : '')
. (string)$this->returnType . ' '
. (string) $this->returnType . ' '
. $this->methodName
. '(' . implode(', ', $arguments) . ')'
. ($this->description ? ' ' . $this->description->render() : ''));
@@ -208,7 +208,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
{
foreach ($arguments as &$argument) {
if (is_string($argument)) {
$argument = [ 'name' => $argument ];
$argument = ['name' => $argument];
}
if (! isset($argument['type'])) {
@@ -217,7 +217,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
$keys = array_keys($argument);
sort($keys);
if ($keys !== [ 'name', 'type' ]) {
if ($keys !== ['name', 'type']) {
throw new \InvalidArgumentException(
'Arguments can only have the "name" and "type" fields, found: ' . var_export($keys, true)
);
+1 -1
View File
@@ -38,6 +38,6 @@ final class Fqsen implements Reference
*/
public function __toString(): string
{
return (string)$this->fqsen;
return (string) $this->fqsen;
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ class See extends BaseTag implements Factory\StaticMethod
) {
Assert::allNotNull([$resolver, $descriptionFactory]);
$parts = preg_split('/\s+/Su', $body, 2);
$parts = preg_split('/\s+/Su', $body, 2);
$description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
// https://tools.ietf.org/html/rfc2396#section-3
+1 -1
View File
@@ -49,7 +49,7 @@ final class Since extends BaseTag implements Factory\StaticMethod
{
Assert::nullOrStringNotEmpty($version);
$this->version = $version;
$this->version = $version;
$this->description = $description;
}
+7 -7
View File
@@ -37,9 +37,9 @@ final class Source extends BaseTag implements Factory\StaticMethod
Assert::integerish($startingLine);
Assert::nullOrIntegerish($lineCount);
$this->startingLine = (int)$startingLine;
$this->lineCount = $lineCount !== null ? (int)$lineCount : null;
$this->description = $description;
$this->startingLine = (int) $startingLine;
$this->lineCount = $lineCount !== null ? (int) $lineCount : null;
$this->description = $description;
}
/**
@@ -54,14 +54,14 @@ final class Source extends BaseTag implements Factory\StaticMethod
Assert::notNull($descriptionFactory);
$startingLine = 1;
$lineCount = null;
$description = null;
$lineCount = null;
$description = null;
// Starting line / Number of lines / Description
if (preg_match('/^([1-9]\d*)\s*(?:((?1))\s+)?(.*)$/sux', $body, $matches)) {
$startingLine = (int)$matches[1];
$startingLine = (int) $matches[1];
if (isset($matches[2]) && $matches[2] !== '') {
$lineCount = (int)$matches[2];
$lineCount = (int) $matches[2];
}
$description = $matches[3];
+2 -2
View File
@@ -32,7 +32,7 @@ final class Throws extends BaseTag implements Factory\StaticMethod
public function __construct(Type $type, ?Description $description = null)
{
$this->type = $type;
$this->type = $type;
$this->description = $description;
}
@@ -49,7 +49,7 @@ final class Throws extends BaseTag implements Factory\StaticMethod
$parts = preg_split('/\s+/Su', $body, 2);
$type = $typeResolver->resolve($parts[0] ?? '', $context);
$type = $typeResolver->resolve($parts[0] ?? '', $context);
$description = $descriptionFactory->create($parts[1] ?? '', $context);
return new static($type, $description);
+1 -1
View File
@@ -35,7 +35,7 @@ final class Uses extends BaseTag implements Factory\StaticMethod
*/
public function __construct(Fqsen $refers, ?Description $description = null)
{
$this->refers = $refers;
$this->refers = $refers;
$this->description = $description;
}
+4 -4
View File
@@ -37,8 +37,8 @@ class Var_ extends BaseTag implements Factory\StaticMethod
public function __construct(string $variableName, ?Type $type = null, ?Description $description = null)
{
$this->variableName = $variableName;
$this->type = $type;
$this->description = $description;
$this->type = $type;
$this->description = $description;
}
/**
@@ -53,8 +53,8 @@ class Var_ extends BaseTag implements Factory\StaticMethod
Assert::stringNotEmpty($body);
Assert::allNotNull([$typeResolver, $descriptionFactory]);
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
$type = null;
$parts = preg_split('/(\s+)/Su', $body, 3, PREG_SPLIT_DELIM_CAPTURE);
$type = null;
$variableName = '';
// if the first item that is encountered is not a variable; it is a type
+1 -1
View File
@@ -41,7 +41,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
*
* @param string[] $additionalTags
*/
public static function createInstance(array $additionalTags = []): DocBlockFactory
public static function createInstance(array $additionalTags = []): self
{
$fqsenResolver = new FqsenResolver();
$tagFactory = new StandardTagFactory($fqsenResolver);