These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * (c) Christian Gripp <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Core23\SitemapBundle\DependencyInjection; |
||
13 | |||
14 | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
||
15 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
||
16 | use Symfony\Component\Config\Definition\ConfigurationInterface; |
||
17 | |||
18 | final class Configuration implements ConfigurationInterface |
||
19 | { |
||
20 | /** |
||
21 | * {@inheritdoc} |
||
22 | */ |
||
23 | public function getConfigTreeBuilder() |
||
24 | { |
||
25 | $treeBuilder = new TreeBuilder('core23_sitemap'); |
||
26 | |||
27 | /* @var ArrayNodeDefinition $rootNode */ |
||
28 | // Keep compatibility with symfony/config < 4.2 |
||
29 | if (!\method_exists($treeBuilder, 'getRootNode')) { |
||
30 | $rootNode = $treeBuilder->root('core23_sitemap'); |
||
31 | } else { |
||
32 | $rootNode = $treeBuilder->getRootNode(); |
||
33 | } |
||
34 | |||
35 | $this->addStaticUrlsSection($rootNode); |
||
0 ignored issues
–
show
|
|||
36 | $this->addCacheSection($rootNode); |
||
0 ignored issues
–
show
$rootNode of type object<Symfony\Component...Builder\NodeDefinition> is not a sub-type of object<Symfony\Component...er\ArrayNodeDefinition> . It seems like you assume a child class of the class Symfony\Component\Config...\Builder\NodeDefinition to be always present.
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass. Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type. ![]() |
|||
37 | |||
38 | return $treeBuilder; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * @param ArrayNodeDefinition $node |
||
43 | */ |
||
44 | private function addCacheSection(ArrayNodeDefinition $node): void |
||
45 | { |
||
46 | $node |
||
47 | ->children() |
||
48 | ->arrayNode('cache') |
||
49 | ->addDefaultsIfNotSet() |
||
50 | ->children() |
||
51 | ->scalarNode('service')->defaultNull()->end() |
||
52 | ->end() |
||
53 | ->end() |
||
54 | ->end() |
||
55 | ; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @param ArrayNodeDefinition $node |
||
60 | */ |
||
61 | private function addStaticUrlsSection(ArrayNodeDefinition $node): void |
||
62 | { |
||
63 | $node |
||
64 | ->children() |
||
65 | ->arrayNode('static') |
||
66 | ->defaultValue([]) |
||
67 | ->prototype('array') |
||
68 | ->children() |
||
69 | ->scalarNode('url')->end() |
||
70 | ->integerNode('priority')->defaultNull()->end() |
||
71 | ->scalarNode('changefreq')->defaultNull()->end() |
||
72 | ->end() |
||
73 | ->end() |
||
74 | ->end() |
||
75 | ->end() |
||
76 | ; |
||
77 | } |
||
78 | } |
||
79 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.