These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Sylius package. |
||
5 | * |
||
6 | * (c) Paweł Jędrzejewski |
||
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 | declare(strict_types=1); |
||
13 | |||
14 | namespace Sylius\Bundle\ReviewBundle\DependencyInjection; |
||
15 | |||
16 | use Sylius\Bundle\ResourceBundle\Controller\ResourceController; |
||
17 | use Sylius\Bundle\ResourceBundle\SyliusResourceBundle; |
||
18 | use Sylius\Bundle\ReviewBundle\Form\Type\ReviewType; |
||
19 | use Sylius\Component\Resource\Factory\Factory; |
||
20 | use Sylius\Component\Review\Model\ReviewerInterface; |
||
21 | use Sylius\Component\Review\Model\ReviewInterface; |
||
22 | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
||
23 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
||
24 | use Symfony\Component\Config\Definition\ConfigurationInterface; |
||
25 | |||
26 | final class Configuration implements ConfigurationInterface |
||
27 | { |
||
28 | /** |
||
29 | * {@inheritdoc} |
||
30 | */ |
||
31 | public function getConfigTreeBuilder(): TreeBuilder |
||
32 | { |
||
33 | $treeBuilder = new TreeBuilder(); |
||
34 | $rootNode = $treeBuilder->root('sylius_review'); |
||
35 | |||
36 | $rootNode |
||
37 | ->addDefaultsIfNotSet() |
||
38 | ->children() |
||
39 | ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end() |
||
40 | ->end() |
||
41 | ; |
||
42 | |||
43 | $this->addResourcesSection($rootNode); |
||
44 | |||
45 | return $treeBuilder; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param ArrayNodeDefinition $node |
||
50 | */ |
||
51 | private function addResourcesSection(ArrayNodeDefinition $node): void |
||
52 | { |
||
53 | $node |
||
0 ignored issues
–
show
|
|||
54 | ->children() |
||
55 | ->arrayNode('resources') |
||
56 | ->useAttributeAsKey('name') |
||
57 | ->prototype('array') |
||
58 | ->children() |
||
59 | ->scalarNode('subject')->isRequired()->end() |
||
60 | ->arrayNode('review') |
||
61 | ->isRequired() |
||
62 | ->addDefaultsIfNotSet() |
||
63 | ->children() |
||
64 | ->variableNode('options')->end() |
||
65 | ->arrayNode('classes') |
||
66 | ->addDefaultsIfNotSet() |
||
67 | ->children() |
||
68 | ->scalarNode('model')->isRequired()->end() |
||
69 | ->scalarNode('interface')->defaultValue(ReviewInterface::class)->cannotBeEmpty()->end() |
||
70 | ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end() |
||
71 | ->scalarNode('repository')->cannotBeEmpty()->end() |
||
72 | ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() |
||
73 | ->scalarNode('form')->defaultValue(ReviewType::class)->cannotBeEmpty()->end() |
||
74 | ->end() |
||
75 | ->end() |
||
76 | ->end() |
||
77 | ->end() |
||
78 | ->arrayNode('reviewer') |
||
79 | ->addDefaultsIfNotSet() |
||
80 | ->children() |
||
81 | ->variableNode('options')->end() |
||
82 | ->arrayNode('classes') |
||
83 | ->addDefaultsIfNotSet() |
||
84 | ->children() |
||
85 | ->scalarNode('model')->isRequired()->end() |
||
86 | ->scalarNode('interface')->defaultValue(ReviewerInterface::class)->cannotBeEmpty()->end() |
||
87 | ->scalarNode('repository')->cannotBeEmpty()->end() |
||
88 | ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end() |
||
89 | ->end() |
||
90 | ->end() |
||
91 | ->end() |
||
92 | ->end() |
||
93 | ->end() |
||
94 | ->end() |
||
95 | ->end() |
||
96 | ; |
||
97 | } |
||
98 | } |
||
99 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: