Conditions | 7 |
Paths | 4 |
Total Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
20 | public function getConfigTreeBuilder() |
||
21 | { |
||
22 | $treeBuilder = new TreeBuilder('elao_enum'); |
||
23 | $rootNode = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('elao_enum'); |
||
|
|||
24 | |||
25 | $rootNode->children() |
||
26 | ->arrayNode('argument_value_resolver')->canBeDisabled()->end() |
||
27 | ->arrayNode('doctrine') |
||
28 | ->fixXmlConfig('type') |
||
29 | ->children() |
||
30 | ->arrayNode('types') |
||
31 | ->validate() |
||
32 | ->ifTrue(static function (array $v): bool { |
||
33 | $classes = array_keys($v); |
||
34 | foreach ($classes as $class) { |
||
35 | if (!is_a($class, EnumInterface::class, true)) { |
||
36 | return true; |
||
37 | } |
||
38 | } |
||
39 | |||
40 | return false; |
||
41 | }) |
||
42 | ->then(static function (array $v) { |
||
43 | $classes = array_keys($v); |
||
44 | $invalids = []; |
||
45 | foreach ($classes as $class) { |
||
46 | if (!is_a($class, EnumInterface::class, true)) { |
||
47 | $invalids[] = $class; |
||
48 | } |
||
49 | } |
||
50 | |||
51 | throw new \InvalidArgumentException(sprintf( |
||
52 | 'Invalid classes %s. Expected instances of "%s"', |
||
53 | json_encode($invalids), |
||
54 | EnumInterface::class) |
||
55 | ); |
||
56 | }) |
||
57 | ->end() |
||
58 | ->useAttributeAsKey('class') |
||
59 | ->arrayPrototype() |
||
60 | ->beforeNormalization() |
||
61 | ->ifString()->then(static function (string $v): array { return ['name' => $v]; }) |
||
62 | ->end() |
||
63 | ->children() |
||
64 | ->scalarNode('name')->cannotBeEmpty()->end() |
||
65 | ->enumNode('type')->values(['string', 'int'])->cannotBeEmpty()->defaultValue('string')->end() |
||
66 | ->end() |
||
67 | ->end() |
||
68 | ->end() |
||
69 | ->end() |
||
70 | ->end() |
||
71 | ->arrayNode('serializer') |
||
72 | ->{interface_exists(SerializerInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}() |
||
73 | ->end() |
||
74 | ->end(); |
||
75 | |||
76 | return $treeBuilder; |
||
77 | } |
||
78 | } |
||
79 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.