Skip to content

Commit 9447886

Browse files
author
Jeremiah VALERIE
committed
Fix static analyse build
1 parent 5e3d1d0 commit 9447886

File tree

16 files changed

+317
-144
lines changed

16 files changed

+317
-144
lines changed

phpstan-baseline.neon

Lines changed: 265 additions & 125 deletions
Large diffs are not rendered by default.

src/Config/Parser/AttributeParser.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public static function getMetadatas(Reflector $reflector): array
2525
case $reflector instanceof ReflectionMethod:
2626
case $reflector instanceof ReflectionProperty:
2727
case $reflector instanceof ReflectionClassConstant:
28-
$attributes = $reflector->getAttributes();
28+
if (is_callable([$reflector, 'getAttributes'])) {
29+
$attributes = $reflector->getAttributes();
30+
}
2931
}
3032

3133
// @phpstan-ignore-next-line

src/Config/Parser/GraphQLParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class GraphQLParser implements ParserInterface
4242
public static function parse(SplFileInfo $file, ContainerBuilder $container, array $configs = []): array
4343
{
4444
$container->addResource(new FileResource($file->getRealPath()));
45-
$content = trim(file_get_contents($file->getPathname()));
45+
$content = trim((string) file_get_contents($file->getPathname()));
4646
$typesConfig = [];
4747

4848
// allow empty files

src/DependencyInjection/Compiler/AliasedPass.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Symfony\Component\DependencyInjection\ContainerBuilder;
1414
use Symfony\Component\DependencyInjection\Definition;
1515
use function array_filter;
16-
use function call_user_func;
1716
use function is_subclass_of;
1817

1918
final class AliasedPass implements CompilerPassInterface
@@ -65,7 +64,11 @@ private function filterDefinitions(array $definitions): array
6564

6665
private function addDefinitionTagsFromAliases(Definition $definition): void
6766
{
68-
$aliases = call_user_func([$definition->getClass(), 'getAliases']);
67+
/**
68+
* @var class-string<AliasedInterface> $class
69+
*/
70+
$class = (string) $definition->getClass();
71+
$aliases = $class::getAliases();
6972
/** @var string $tagName */
7073
$tagName = $this->guessTagName($definition);
7174
$withMethod = TypeTaggedServiceMappingPass::TAG_NAME !== $tagName;

src/DependencyInjection/Compiler/ConfigParserPass.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use function array_map;
2828
use function array_merge;
2929
use function array_replace_recursive;
30-
use function call_user_func;
3130
use function dirname;
3231
use function implode;
3332
use function is_a;
@@ -43,6 +42,9 @@ class ConfigParserPass implements CompilerPassInterface
4342
'attribute' => 'php',
4443
];
4544

45+
/**
46+
* @var array<string, class-string<PreParserInterface>>
47+
*/
4648
public const PARSERS = [
4749
'yaml' => YamlParser::class,
4850
'graphql' => GraphQLParser::class,
@@ -143,7 +145,10 @@ private function parseTypeConfigFiles(string $type, iterable $files, ContainerBu
143145
continue;
144146
}
145147

146-
$config[] = call_user_func([self::PARSERS[$type], $method], $file, $container, $configs);
148+
$parser = [self::PARSERS[$type], $method];
149+
if (is_callable($parser)) {
150+
$config[] = ($parser)($file, $container, $configs);
151+
}
147152
$treatedFiles[$file->getRealPath()] = true;
148153
}
149154

src/Error/ErrorHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ private function treatExceptions(array $errors, bool $throwRawException): array
9595
continue;
9696
}
9797

98-
// recreate a error with converted exception
98+
// recreate an error with converted exception
9999
$errorWithConvertedException = new GraphQLError(
100100
$error->getMessage(),
101-
$error->nodes,
101+
$error->nodes, // @phpstan-ignore-line
102102
$error->getSource(),
103103
$error->getPositions(),
104104
$error->path,

src/ExpressionLanguage/ExpressionLanguage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public static function stringHasTrigger(string $maybeExpression): bool
139139
*/
140140
public static function unprefixExpression(string $expression)
141141
{
142-
$string = substr($expression, strlen(self::EXPRESSION_TRIGGER));
142+
$string = substr($expression, strlen(self::EXPRESSION_TRIGGER)) ?: '';
143143

144144
return '' !== $string ? $string : $expression;
145145
}

src/Validator/InputValidator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function validate($groups = null, bool $throw = true): ?ConstraintViolati
7777

7878
$this->buildValidationTree(
7979
$rootNode,
80-
$this->info->fieldDefinition->config['args'],
80+
$this->info->fieldDefinition->config['args'] ?? [],
8181
$classMapping,
8282
$this->resolverArgs->args->getArrayCopy()
8383
);
@@ -95,7 +95,9 @@ public function validate($groups = null, bool $throw = true): ?ConstraintViolati
9595

9696
private function mergeClassValidation(): array
9797
{
98+
/** @phpstan-ignore-next-line */
9899
$common = static::normalizeConfig($this->info->parentType->config['validation'] ?? []);
100+
/** @phpstan-ignore-next-line */
99101
$specific = static::normalizeConfig($this->info->fieldDefinition->config['validation'] ?? []);
100102

101103
return array_filter([
@@ -127,7 +129,7 @@ private function createValidator(MetadataFactory $metadataFactory): ValidatorInt
127129
* Creates a composition of ValidationNode objects from args
128130
* and simultaneously applies to them validation constraints.
129131
*/
130-
protected function buildValidationTree(ValidationNode $rootObject, array $fields, array $classValidation, array $inputData): ValidationNode
132+
private function buildValidationTree(ValidationNode $rootObject, iterable $fields, array $classValidation, array $inputData): ValidationNode
131133
{
132134
$metadata = new ObjectMetadata($rootObject);
133135

@@ -171,6 +173,7 @@ protected function buildValidationTree(ValidationNode $rootObject, array $fields
171173
[$fqcn, $property, $type] = $value;
172174

173175
if (!in_array($fqcn, $this->cachedMetadata)) {
176+
/** @phpstan-ignore-next-line */
174177
$this->cachedMetadata[$fqcn] = $this->defaultValidator->getMetadataFor($fqcn);
175178
}
176179

@@ -238,6 +241,7 @@ private function createCollectionNode(array $values, $type, ValidationNode $pare
238241
*/
239242
private function createObjectNode(array $value, $type, ValidationNode $parent): ValidationNode
240243
{
244+
/** @phpstan-ignore-next-line */
241245
$classValidation = static::normalizeConfig($type->config['validation'] ?? []);
242246

243247
return $this->buildValidationTree(

src/Validator/Mapping/MetadataFactory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ public function __construct()
1717
$this->metadataPool = [];
1818
}
1919

20+
/**
21+
* @param mixed $object
22+
*/
2023
public function getMetadataFor($object): ObjectMetadata
2124
{
2225
if ($object instanceof ValidationNode) {
@@ -26,6 +29,9 @@ public function getMetadataFor($object): ObjectMetadata
2629
throw new NoSuchMetadataException();
2730
}
2831

32+
/**
33+
* @param mixed $object
34+
*/
2935
public function hasMetadataFor($object): bool
3036
{
3137
if ($object instanceof ValidationNode) {

src/Validator/Mapping/ObjectMetadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function __construct(ValidationNode $object)
2121
*
2222
* @return $this|ObjectMetadata
2323
*/
24-
public function addPropertyConstraint($property, Constraint $constraint)
24+
public function addPropertyConstraint($property, Constraint $constraint): self
2525
{
2626
if (!isset($this->properties[$property])) {
2727
$this->properties[$property] = new PropertyMetadata($property);

0 commit comments

Comments
 (0)