Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"phpstan/phpstan-mockery": "^1.1",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-webmozart-assert": "^1.2",
"psalm/phar": "^5.26"
"psalm/phar": "^5.26",
"shipmonk/dead-code-detector": "^0.5.1"
},
"autoload": {
"psr-4": {
Expand Down
71 changes: 70 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ parameters:
ignoreErrors:
- '#Method phpDocumentor\\Reflection\\DocBlock\\StandardTagFactory::createTag\(\) should return phpDocumentor\\Reflection\\DocBlock\\Tag but returns mixed#'
- '#Offset 2 on array\{string, 28, int\} on left side of \?\? always exists and is not nullable\.#'
-
path: src/DocBlockFactoryInterface.php
identifier: shipmonk.deadMethod
-
path: src/DocBlock/TagFactory.php
identifier: shipmonk.deadMethod
paths:
- src
- tests/unit
2 changes: 2 additions & 0 deletions src/DocBlock/StandardTagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ImplementsFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\MethodFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\MixinFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ParamFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory;
Expand Down Expand Up @@ -151,6 +152,7 @@ public static function createInstance(FqsenResolver $fqsenResolver): self
new PropertyReadFactory($typeResolver, $descriptionFactory),
new PropertyWriteFactory($typeResolver, $descriptionFactory),
new MethodFactory($typeResolver, $descriptionFactory),
new MixinFactory($typeResolver, $descriptionFactory),
new ImplementsFactory($typeResolver, $descriptionFactory),
new ExtendsFactory($typeResolver, $descriptionFactory),
new TemplateFactory($typeResolver, $descriptionFactory),
Expand Down
2 changes: 1 addition & 1 deletion src/DocBlock/Tags/Factory/MethodParameterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{
$method = 'format' . ucfirst(gettype($defaultValue));
if (method_exists($this, $method)) {
return ' = ' . $this->{$method}($defaultValue);
return $this->{$method}($defaultValue);
}

return '';
Expand All @@ -48,7 +48,7 @@
/**
* @param mixed $defaultValue
*/
private function formatNull($defaultValue): string

Check failure on line 51 in src/DocBlock/Tags/Factory/MethodParameterFactory.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Unused phpDocumentor\Reflection\DocBlock\Tags\Factory\MethodParameterFactory::formatNull
{
return 'null';
}
Expand Down
2 changes: 1 addition & 1 deletion src/DocBlock/Tags/MethodParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __toString(): string
'$' . $this->getName() .
(
$this->defaultValue !== self::NO_DEFAULT_VALUE ?
(new MethodParameterFactory())->format($this->defaultValue) :
' = ' . (new MethodParameterFactory())->format($this->defaultValue) :
''
);
}
Expand Down
44 changes: 0 additions & 44 deletions src/DocBlock/Tags/TagWithType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,10 @@

namespace phpDocumentor\Reflection\DocBlock\Tags;

use InvalidArgumentException;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\Exception\CannotCreateTag;
use phpDocumentor\Reflection\Type;

use function in_array;
use function sprintf;
use function strlen;
use function substr;
use function trim;

abstract class TagWithType extends BaseTag
{
/** @var ?Type */
Expand All @@ -42,43 +35,6 @@ final public static function create(string $body): Tag
throw new CannotCreateTag('Typed tag cannot be created');
}

/**
* @return string[]
*/
protected static function extractTypeFromBody(string $body): array
{
$type = '';
$nestingLevel = 0;
for ($i = 0, $iMax = strlen($body); $i < $iMax; $i++) {
$character = $body[$i];

if ($nestingLevel === 0 && trim($character) === '') {
break;
}

$type .= $character;
if (in_array($character, ['<', '(', '[', '{'])) {
$nestingLevel++;
continue;
}

if (in_array($character, ['>', ')', ']', '}'])) {
$nestingLevel--;
continue;
}
}

if ($nestingLevel < 0 || $nestingLevel > 0) {
throw new InvalidArgumentException(
sprintf('Could not find type in %s, please check for malformed notations', $body)
);
}

$description = trim(substr($body, strlen($type)));

return [$type, $description];
}

public function __toString(): string
{
if ($this->description) {
Expand Down
11 changes: 2 additions & 9 deletions src/DocBlock/Tags/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

namespace phpDocumentor\Reflection\DocBlock\Tags;

use Doctrine\Deprecations\Deprecation;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\Exception\CannotCreateTag;
use phpDocumentor\Reflection\Type;

/**
Expand Down Expand Up @@ -51,14 +51,7 @@ public function __construct(
*/
public static function create(string $body): ?Tag
{
Deprecation::trigger(
'phpdocumentor/reflection-docblock',
'https://github.com/phpDocumentor/ReflectionDocBlock/issues/361',
'Create using static factory is deprecated, this method should not be called directly
by library consumers',
);

return null;
throw new CannotCreateTag('Template tag cannot be created');
}

public function getTemplateName(): string
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/Assets/CustomParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@

final class CustomParam implements Tag
{
/** @var string|null */
public $myParam;

/** @var FqsenResolver|null */
public $fqsenResolver;

public function getName() : string
{
return 'spy';
}

public static function create($body, FqsenResolver $fqsenResolver = null, ?string $myParam = null)
public static function create(string $body, FqsenResolver $fqsenResolver = null, ?string $myParam = null)
{
$tag = new self();
$tag->fqsenResolver = $fqsenResolver;
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/Assets/CustomServiceClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
use phpDocumentor\Reflection\FqsenResolver;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\StaticMethod;

final class CustomServiceClass implements Tag
{
/** @var Formatter|null */
public $formatter;

public function getName() : string
{
return 'spy';
}

public static function create($body, PassthroughFormatter $formatter = null)
public static function create(string $body, PassthroughFormatter $formatter = null)
{
$tag = new self();
$tag->formatter = $formatter;
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/Assets/CustomServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

final class CustomServiceInterface implements Tag
{
/** @var Formatter|null */
public $formatter;

public function getName() : string
{
return 'spy';
}

public static function create($body, Formatter $formatter = null)
public static function create(string $body, Formatter $formatter = null)
{
$tag = new self();
$tag->formatter = $formatter;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Assets/CustomTagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

class CustomTagFactory implements Factory
{
/** @var CustomServiceClass|null */
public $class;

public function create(string $tagLine, ?Context $context = null, CustomServiceClass $class = null): Tag
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/DocBlock/DescriptionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace phpDocumentor\Reflection\DocBlock;

use Exception;
use Mockery as m;
use phpDocumentor\Reflection\DocBlock\Tags\InvalidTag;
use phpDocumentor\Reflection\DocBlock\Tags\Link as LinkTag;
Expand Down Expand Up @@ -216,7 +215,7 @@ public function testDescriptionWithBrokenInlineTags(): void
$tagFactory->shouldReceive('create')
->once()
->with('@see $name', $context)
->andReturn(InvalidTag::create('$name', 'see', new Exception()));
->andReturn(InvalidTag::create('$name', 'see'));

$factory = new DescriptionFactory($tagFactory);
$description = $factory->create($contents, $context);
Expand Down
Loading
Loading