Skip to content

Commit af02498

Browse files
authored
ci: fix phpstan & code-style (#2681)
## Description ~Fixes CI currently failing on warnings coming from api-platform. Fixed in api-platform/core#7694 Fixes failing PHPStan & code-style ## What type of PR is this? (check all applicable) - [ ] Bug Fix - [ ] Feature - [ ] Refactor - [ ] Deprecation - [ ] Breaking Change - [ ] Documentation Update - [x] CI ## Checklist - [ ] I have made corresponding changes to the documentation (`docs/`)
1 parent 65dfa87 commit af02498

19 files changed

Lines changed: 61 additions & 55 deletions

config/routing/swaggerui.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
1313
use Symfony\Component\Routing\Loader\XmlFileLoader;
1414

15-
return function (RoutingConfigurator $routes): void {
15+
return static function (RoutingConfigurator $routes): void {
1616
foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT) as $trace) {
1717
if (isset($trace['object']) && $trace['object'] instanceof XmlFileLoader && 'doImport' === $trace['function']) {
1818
if (__DIR__ === dirname(realpath($trace['args'][3]))) {

src/DependencyInjection/Configuration.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getConfigTreeBuilder(): TreeBuilder
5151
->end()
5252
->arrayNode('cache')
5353
->validate()
54-
->ifTrue(function ($v) { return null !== $v['item_id'] && null === $v['pool']; })
54+
->ifTrue(static function ($v) { return null !== $v['item_id'] && null === $v['pool']; })
5555
->thenInvalid('Can not set cache.item_id if cache.pool is null')
5656
->end()
5757
->children()
@@ -121,15 +121,15 @@ public function getConfigTreeBuilder(): TreeBuilder
121121
]
122122
)
123123
->beforeNormalization()
124-
->ifTrue(function ($v) {
124+
->ifTrue(static function ($v) {
125125
return 0 === \count($v) || isset($v['path_patterns']) || isset($v['host_patterns']) || isset($v['documentation']);
126126
})
127-
->then(function ($v): array {
127+
->then(static function ($v): array {
128128
return ['default' => $v];
129129
})
130130
->end()
131131
->validate()
132-
->ifTrue(function ($v) {
132+
->ifTrue(static function ($v) {
133133
return !isset($v['default']);
134134
})
135135
->thenInvalid('You must specify a `default` area under `nelmio_api_doc.areas`.')
@@ -229,14 +229,14 @@ public function getConfigTreeBuilder(): TreeBuilder
229229
->variableNode('groups')
230230
->defaultValue(null)
231231
->validate()
232-
->ifTrue(function ($v) { return null !== $v && !\is_array($v); })
232+
->ifTrue(static function ($v) { return null !== $v && !\is_array($v); })
233233
->thenInvalid('Model groups must be either `null` or an array.')
234234
->end()
235235
->end()
236236
->variableNode('options')
237237
->defaultValue(null)
238238
->validate()
239-
->ifTrue(function ($v) { return null !== $v && !\is_array($v); })
239+
->ifTrue(static function ($v) { return null !== $v && !\is_array($v); })
240240
->thenInvalid('Model options must be either `null` or an array.')
241241
->end()
242242
->end()

src/DependencyInjection/NelmioApiDocExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function load(array $configs, ContainerBuilder $container): void
173173
->addTag('container.service_locator')
174174
->addArgument(array_combine(
175175
array_keys($config['areas']),
176-
array_map(function ($area) { return new Reference(\sprintf('nelmio_api_doc.generator.%s', $area)); }, array_keys($config['areas']))
176+
array_map(static function ($area) { return new Reference(\sprintf('nelmio_api_doc.generator.%s', $area)); }, array_keys($config['areas']))
177177
));
178178

179179
if (true === $config['type_info']) {
@@ -294,7 +294,7 @@ public function load(array $configs, ContainerBuilder $container): void
294294
*/
295295
private function findNameAliases(array $names, string $area): array
296296
{
297-
$nameAliases = array_filter($names, function (array $aliasInfo) use ($area) {
297+
$nameAliases = array_filter($names, static function (array $aliasInfo) use ($area) {
298298
return [] === $aliasInfo['areas'] || \in_array($area, $aliasInfo['areas'], true);
299299
});
300300

src/Describer/ApiPlatformDescriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(object $documentation, NormalizerInterface $normaliz
2727
throw new \InvalidArgumentException(\sprintf('Argument 2 passed to %s() must implement %s and support normalization of %s. The normalizer provided is an instance of %s.', __METHOD__, NormalizerInterface::class, DocumentationInterface::class, $normalizer::class));
2828
}
2929

30-
parent::__construct(function () use ($documentation, $normalizer) {
30+
parent::__construct(static function () use ($documentation, $normalizer) {
3131
$documentation = (array) $normalizer->normalize(
3232
$documentation,
3333
null,

src/Model/ModelRegistry.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ private function typeToString(LegacyType|Type $type): string
287287
} elseif ($type->isCollection()) {
288288
if (null !== $collectionType = ($type->getCollectionValueTypes()[0] ?? null)) {
289289
return $this->typeToString($collectionType).'[]';
290-
} else {
291-
return 'mixed[]';
292290
}
291+
292+
return 'mixed[]';
293293
}
294294

295295
return $type->getBuiltinType();

src/ModelDescriber/JMSModelDescriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private function computeGroups(Context $context, ?array $type = null): ?array
250250
}
251251

252252
$groupsExclusion = $context->getExclusionStrategy();
253-
if (!($groupsExclusion instanceof GroupsExclusionStrategy)) {
253+
if (!$groupsExclusion instanceof GroupsExclusionStrategy) {
254254
return null;
255255
}
256256

src/OpenApiPhp/Util.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@
2626
* of swagger Annotation classes with the following convenience methods
2727
* to get or create the respective Annotation instances if not found
2828
*
29-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getPath()
30-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getSchema()
31-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getProperty()
32-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getOperation()
33-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getOperationParameter()
29+
* @see Util::getPath()
30+
* @see Util::getSchema()
31+
* @see Util::getProperty()
32+
* @see Util::getOperation()
33+
* @see Util::getOperationParameter()
3434
*
3535
* which in turn get or create the Annotation instances through the following more general methods
36-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getChild()
37-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getCollectionItem()
38-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::getIndexedCollectionItem()
36+
* @see Util::getChild()
37+
* @see Util::getCollectionItem()
38+
* @see Util::getIndexedCollectionItem()
3939
*
4040
* which then searches for an existing Annotation through
41-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::searchCollectionItem()
42-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::searchIndexedCollectionItem()
41+
* @see Util::searchCollectionItem()
42+
* @see Util::searchIndexedCollectionItem()
4343
*
4444
* and if not found the Annotation creates it through
45-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::createCollectionItem()
46-
* @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::createContext()
45+
* @see Util::createCollectionItem()
46+
* @see Util::createContext()
4747
*
4848
* The merge method @see \Nelmio\ApiDocBundle\OpenApiPhp\Util::merge() has the main purpose to be able
4949
* to merge properties from an deeply nested array of Annotation properties in the structure of a
@@ -617,7 +617,7 @@ private static function mergeProperty(OA\AbstractAnnotation $annotation, string
617617
*/
618618
private static function getNestingIndexes(string $class): array
619619
{
620-
return array_map(function ($property) {
620+
return array_map(static function ($property) {
621621
return \is_array($property) ? $property[0] : $property;
622622
}, $class::$_nested);
623623
}

src/Render/Html/GetNelmioAsset.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public function __invoke(string $defaultAssetsMode, string $asset): string
4646
return $this->renderJavascript($resource, $isInline);
4747
} elseif ('css' === $extension) {
4848
return $this->renderCss($resource, $isInline);
49-
} else {
50-
return $resource;
5149
}
50+
51+
return $resource;
5252
}
5353

5454
/**
@@ -61,9 +61,9 @@ private function getExtension(string $assetsMode, string $asset): array
6161
return ['js', $assetsMode];
6262
} elseif ('png' === $extension) {
6363
return ['png', AssetsMode::OFFLINE === $assetsMode ? AssetsMode::CDN : $assetsMode];
64-
} else {
65-
return ['css', $assetsMode];
6664
}
65+
66+
return ['css', $assetsMode];
6767
}
6868

6969
/**
@@ -77,26 +77,26 @@ private function getResource(string $asset, string $mode): array
7777
return [file_get_contents($this->resourcesDir.'/'.$asset), true];
7878
} elseif (AssetsMode::CDN === $mode) {
7979
return [$this->cdnUrl.'/'.$asset, false];
80-
} else {
81-
return [$this->assetExtension->getAssetUrl(\sprintf('bundles/nelmioapidoc/%s', $asset)), false];
8280
}
81+
82+
return [$this->assetExtension->getAssetUrl(\sprintf('bundles/nelmioapidoc/%s', $asset)), false];
8383
}
8484

8585
private function renderJavascript(string $script, bool $isInline): string
8686
{
8787
if ($isInline) {
8888
return \sprintf('<script>%s</script>', $script);
89-
} else {
90-
return \sprintf('<script src="%s"></script>', $script);
9189
}
90+
91+
return \sprintf('<script src="%s"></script>', $script);
9292
}
9393

9494
private function renderCss(string $stylesheet, bool $isInline): string
9595
{
9696
if ($isInline) {
9797
return \sprintf('<style>%s</style>', $stylesheet);
98-
} else {
99-
return \sprintf('<link rel="stylesheet" href="%s">', $stylesheet);
10098
}
99+
100+
return \sprintf('<link rel="stylesheet" href="%s">', $stylesheet);
101101
}
102102
}

src/RouteDescriber/FosRestDescriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private function getFormat(mixed $requirements): ?string
135135
*/
136136
private function getEnum(mixed $requirements, \ReflectionMethod $reflectionMethod): ?array
137137
{
138-
if (!($requirements instanceof Choice)) {
138+
if (!$requirements instanceof Choice) {
139139
return null;
140140
}
141141

src/RouteDescriber/RouteMetadataDescriber.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ private function getPossibleEnumValues(string $reqPattern): array
127127
if ('' === $part || 0 === preg_match(self::ALPHANUM_EXPANDED_REGEX, $part)) {
128128
// we check a complex regex expression containing | - abort in that case
129129
return [];
130-
} else {
131-
$requirements[] = $part;
132130
}
131+
$requirements[] = $part;
133132
}
134133
}
135134

0 commit comments

Comments
 (0)