Codestyle fixes and static analysis

This commit is contained in:
Jaapio
2022-11-11 14:24:45 +01:00
parent 6a92bc3ce9
commit 1f95f3b735
11 changed files with 76 additions and 19 deletions
+1 -1
View File
@@ -177,7 +177,7 @@ final class StandardTagFactory implements TagFactory
}
if (is_object($handler)) {
Assert::implementsInterface($handler, Factory::class);
Assert::isInstanceOf($handler, Factory::class);
$this->tagHandlerMappings[$tagName] = $handler;
return;
+9 -2
View File
@@ -51,7 +51,10 @@ final class MethodFactory implements PHPStanFactory
function (MethodTagValueParameterNode $param) use ($context) {
return new MethodParameter(
trim($param->parameterName, '$'),
$this->typeResolver->createType($param->type, $context) ?? new Mixed_(),
$param->type === null ? new Mixed_() : $this->typeResolver->createType(
$param->type,
$context
),
$param->isReference,
$param->isVariadic,
(string) $param->defaultValue
@@ -69,6 +72,10 @@ final class MethodFactory implements PHPStanFactory
private function createReturnType(MethodTagValueNode $tagValue, Context $context): Type
{
return $this->typeResolver->createType($tagValue->returnType, $context) ?? new Void_();
if ($tagValue->returnType === null) {
return new Void_();
}
return $this->typeResolver->createType($tagValue->returnType, $context);
}
}
+7 -1
View File
@@ -63,6 +63,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
/**
* @param array<int, array<string, Type|string>> $arguments
* @param MethodParameter[] $parameters
* @phpstan-param array<int, array{name: string, type: Type}|string> $arguments
*/
public function __construct(
@@ -90,6 +91,10 @@ final class Method extends BaseTag implements Factory\StaticMethod
$this->parameters = $parameters ?? $this->fromLegacyArguments($arguments);
}
/**
* @deprecated Create using static factory is deprecated,
* this method should not be called directly by library consumers
*/
public static function create(
string $body,
?TypeResolver $typeResolver = null,
@@ -261,7 +266,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
{
$arguments = [];
foreach ($this->parameters as $parameter) {
$arguments[] = ($parameter->getType() ?? new Mixed_()) . ' ' .
$arguments[] = $parameter->getType() . ' ' .
($parameter->isReference() ? '&' : '') .
($parameter->isVariadic() ? '...' : '') .
'$' . $parameter->getName();
@@ -334,6 +339,7 @@ final class Method extends BaseTag implements Factory\StaticMethod
/**
* @param array{name: string, type: Type} $arguments
* @phpstan-param array<int, array{name: string, type: Type}> $arguments
*
* @return MethodParameter[]
*/
+7 -2
View File
@@ -61,7 +61,8 @@ final class Param extends TagWithType implements Factory\StaticMethod
}
/**
* @deprecated Create using static factory is deprecated, this method should not be called directly by library consumers
* @deprecated Create using static factory is deprecated,
* this method should not be called directly by library consumers
*/
public static function create(
string $body,
@@ -69,7 +70,11 @@ final class Param extends TagWithType implements Factory\StaticMethod
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
trigger_error(
'Create using static factory is deprecated, this method should not be called directly
by library consumers',
E_USER_DEPRECATED
);
Assert::stringNotEmpty($body);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
+9 -1
View File
@@ -49,13 +49,21 @@ final class Property extends TagWithType implements Factory\StaticMethod
$this->description = $description;
}
/**
* @deprecated Create using static factory is deprecated,
* this method should not be called directly by library consumers
*/
public static function create(
string $body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
trigger_error(
'Create using static factory is deprecated, this method should not be called directly
by library consumers',
E_USER_DEPRECATED
);
Assert::stringNotEmpty($body);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
+9 -1
View File
@@ -49,13 +49,21 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod
$this->description = $description;
}
/**
* @deprecated Create using static factory is deprecated,
* this method should not be called directly by library consumers
*/
public static function create(
string $body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
trigger_error(
'Create using static factory is deprecated, this method should not be called directly
by library consumers',
E_USER_DEPRECATED
);
Assert::stringNotEmpty($body);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
+9 -1
View File
@@ -49,13 +49,21 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod
$this->description = $description;
}
/**
* @deprecated Create using static factory is deprecated,
* this method should not be called directly by library consumers
*/
public static function create(
string $body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
trigger_error(
'Create using static factory is deprecated, this method should not be called directly
by library consumers',
E_USER_DEPRECATED
);
Assert::stringNotEmpty($body);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
+9 -1
View File
@@ -36,13 +36,21 @@ final class Return_ extends TagWithType implements Factory\StaticMethod
$this->description = $description;
}
/**
* @deprecated Create using static factory is deprecated,
* this method should not be called directly by library consumers
*/
public static function create(
string $body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
trigger_error(
'Create using static factory is deprecated, this method should not be called directly
by library consumers',
E_USER_DEPRECATED
);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
+9 -1
View File
@@ -49,13 +49,21 @@ final class Var_ extends TagWithType implements Factory\StaticMethod
$this->description = $description;
}
/**
* @deprecated Create using static factory is deprecated,
* this method should not be called directly by library consumers
*/
public static function create(
string $body,
?TypeResolver $typeResolver = null,
?DescriptionFactory $descriptionFactory = null,
?TypeContext $context = null
): self {
trigger_error('Create using static factory is deprecated, this method should not be called directly by library consumers', E_USER_DEPRECATED);
trigger_error(
'Create using static factory is deprecated, this method should not be called directly
by library consumers',
E_USER_DEPRECATED
);
Assert::stringNotEmpty($body);
Assert::notNull($typeResolver);
Assert::notNull($descriptionFactory);
+1 -2
View File
@@ -26,7 +26,6 @@ use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyReadFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\PropertyWriteFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ReturnFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\TypeFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\VarFactory;
use Webmozart\Assert\Assert;
@@ -64,7 +63,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
*
* @param array<string, class-string<Tag>|Factory> $additionalTags
*/
public static function createInstance(array $additionalTags = []): self
public static function createInstance(array $additionalTags = []): DocBlockFactoryInterface
{
$fqsenResolver = new FqsenResolver();
$tagFactory = new StandardTagFactory($fqsenResolver);