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\GridBundle\DependencyInjection; |
||
15 | |||
16 | use Sylius\Bundle\GridBundle\Doctrine\ORM\Driver as DoctrineORMDriver; |
||
17 | use Sylius\Bundle\GridBundle\SyliusGridBundle; |
||
18 | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
||
19 | use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
||
20 | use Symfony\Component\Config\Definition\ConfigurationInterface; |
||
21 | |||
22 | final class Configuration implements ConfigurationInterface |
||
23 | { |
||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | public function getConfigTreeBuilder(): TreeBuilder |
||
28 | { |
||
29 | $treeBuilder = new TreeBuilder(); |
||
30 | $rootNode = $treeBuilder->root('sylius_grid'); |
||
31 | |||
32 | $this->addDriversSection($rootNode); |
||
33 | $this->addTemplatesSection($rootNode); |
||
34 | $this->addGridsSection($rootNode); |
||
35 | |||
36 | return $treeBuilder; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @param ArrayNodeDefinition $node |
||
41 | */ |
||
42 | private function addDriversSection(ArrayNodeDefinition $node): void |
||
43 | { |
||
44 | $node |
||
0 ignored issues
–
show
|
|||
45 | ->children() |
||
46 | ->arrayNode('drivers') |
||
47 | ->defaultValue([SyliusGridBundle::DRIVER_DOCTRINE_ORM]) |
||
48 | ->prototype('enum')->values(SyliusGridBundle::getAvailableDrivers())->end() |
||
49 | ->end() |
||
50 | ->end() |
||
51 | ; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param ArrayNodeDefinition $node |
||
56 | */ |
||
57 | private function addTemplatesSection(ArrayNodeDefinition $node): void |
||
58 | { |
||
59 | $node |
||
60 | ->children() |
||
61 | ->arrayNode('templates') |
||
62 | ->addDefaultsIfNotSet() |
||
63 | ->children() |
||
64 | ->arrayNode('filter') |
||
65 | ->useAttributeAsKey('name') |
||
66 | ->prototype('scalar')->end() |
||
67 | ->end() |
||
68 | ->arrayNode('action') |
||
69 | ->useAttributeAsKey('name') |
||
70 | ->prototype('scalar')->end() |
||
71 | ->end() |
||
72 | ->arrayNode('bulk_action') |
||
73 | ->useAttributeAsKey('name') |
||
74 | ->prototype('scalar')->end() |
||
75 | ->end() |
||
76 | ->end() |
||
77 | ->end() |
||
78 | ->end() |
||
79 | ; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param ArrayNodeDefinition $node |
||
84 | */ |
||
85 | private function addGridsSection(ArrayNodeDefinition $node): void |
||
86 | { |
||
87 | $node |
||
88 | ->children() |
||
89 | ->arrayNode('grids') |
||
90 | ->useAttributeAsKey('code') |
||
91 | ->prototype('array') |
||
92 | ->children() |
||
93 | ->scalarNode('extends')->cannotBeEmpty()->end() |
||
94 | ->arrayNode('driver') |
||
95 | ->addDefaultsIfNotSet() |
||
96 | ->children() |
||
97 | ->scalarNode('name')->cannotBeEmpty()->defaultValue(DoctrineORMDriver::NAME)->end() |
||
98 | ->arrayNode('options') |
||
99 | ->performNoDeepMerging() |
||
100 | ->prototype('variable')->end() |
||
101 | ->defaultValue([]) |
||
102 | ->end() |
||
103 | ->end() |
||
104 | ->end() |
||
105 | ->arrayNode('sorting') |
||
106 | ->performNoDeepMerging() |
||
107 | ->useAttributeAsKey('name') |
||
108 | ->prototype('enum')->values(['asc', 'desc'])->cannotBeEmpty()->end() |
||
109 | ->end() |
||
110 | ->arrayNode('limits') |
||
111 | ->performNoDeepMerging() |
||
112 | ->prototype('integer')->end() |
||
113 | ->defaultValue([10, 25, 50]) |
||
114 | ->end() |
||
115 | ->arrayNode('fields') |
||
116 | ->useAttributeAsKey('name') |
||
117 | ->prototype('array') |
||
118 | ->children() |
||
119 | ->scalarNode('type')->isRequired()->cannotBeEmpty()->end() |
||
120 | ->scalarNode('label')->cannotBeEmpty()->end() |
||
121 | ->scalarNode('path')->cannotBeEmpty()->end() |
||
122 | ->scalarNode('sortable')->end() |
||
123 | ->scalarNode('enabled')->defaultTrue()->end() |
||
124 | ->scalarNode('position')->defaultValue(100)->end() |
||
125 | ->arrayNode('options') |
||
126 | ->performNoDeepMerging() |
||
127 | ->prototype('variable')->end() |
||
128 | ->end() |
||
129 | ->end() |
||
130 | ->end() |
||
131 | ->end() |
||
132 | ->arrayNode('filters') |
||
133 | ->useAttributeAsKey('name') |
||
134 | ->prototype('array') |
||
135 | ->children() |
||
136 | ->scalarNode('type')->isRequired()->cannotBeEmpty()->end() |
||
137 | ->scalarNode('label')->cannotBeEmpty()->end() |
||
138 | ->scalarNode('enabled')->defaultTrue()->end() |
||
139 | ->scalarNode('template')->end() |
||
140 | ->scalarNode('position')->defaultValue(100)->end() |
||
141 | ->arrayNode('options') |
||
142 | ->performNoDeepMerging() |
||
143 | ->prototype('variable')->end() |
||
144 | ->end() |
||
145 | ->arrayNode('form_options') |
||
146 | ->performNoDeepMerging() |
||
147 | ->prototype('variable')->end() |
||
148 | ->end() |
||
149 | ->variableNode('default_value')->end() |
||
150 | ->end() |
||
151 | ->end() |
||
152 | ->end() |
||
153 | ->arrayNode('actions') |
||
154 | ->useAttributeAsKey('name') |
||
155 | ->prototype('array') |
||
156 | ->useAttributeAsKey('name') |
||
157 | ->prototype('array') |
||
158 | ->children() |
||
159 | ->scalarNode('type')->isRequired()->end() |
||
160 | ->scalarNode('label')->end() |
||
161 | ->scalarNode('enabled')->defaultTrue()->end() |
||
162 | ->scalarNode('icon')->end() |
||
163 | ->scalarNode('position')->defaultValue(100)->end() |
||
164 | ->arrayNode('options') |
||
165 | ->performNoDeepMerging() |
||
166 | ->prototype('variable')->end() |
||
167 | ->end() |
||
168 | ->end() |
||
169 | ->end() |
||
170 | ->end() |
||
171 | ->end() |
||
172 | ->end() |
||
173 | ->end() |
||
174 | ->end() |
||
175 | ->end() |
||
176 | ; |
||
177 | } |
||
178 | } |
||
179 |
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: