Conditions | 6 |
Paths | 1 |
Total Lines | 73 |
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 |
||
40 | private function addDoctrineSection(ArrayNodeDefinition $rootNode) |
||
41 | { |
||
42 | $rootNode->children() |
||
43 | ->arrayNode('doctrine') |
||
44 | ->addDefaultsIfNotSet() |
||
45 | ->fixXmlConfig('type') |
||
46 | ->children() |
||
47 | ->booleanNode('enum_sql_declaration') |
||
48 | ->defaultValue(false) |
||
49 | ->info('If true, by default for string enumerations, generate DBAL types with an ENUM SQL declaration with enum values instead of a VARCHAR (Your platform must support it)') |
||
50 | ->end() |
||
51 | ->arrayNode('types') |
||
52 | ->beforeNormalization() |
||
53 | ->always(function ($values) { |
||
54 | $legacyFormat = false; |
||
55 | foreach ($values as $name => $config) { |
||
56 | if (class_exists($name)) { |
||
57 | $legacyFormat = true; |
||
58 | @trigger_error('Using enum FQCN as keys at path "elao_enum.doctrine.types" is deprecated. Provide the name as keys and add the "class" option for each entry instead.', E_USER_DEPRECATED); |
||
59 | break; |
||
60 | } |
||
61 | } |
||
62 | $newValues = []; |
||
63 | |||
64 | if ($legacyFormat) { |
||
65 | foreach ($values as $name => $value) { |
||
66 | if (\is_string($value)) { |
||
67 | $newValues[$value] = $name; |
||
68 | } else { |
||
69 | $newValues[$value['name']] = $value + ['class' => $name]; |
||
70 | } |
||
71 | } |
||
72 | } else { |
||
73 | $newValues = $values; |
||
74 | } |
||
75 | |||
76 | return $newValues; |
||
77 | }) |
||
78 | ->end() |
||
79 | ->useAttributeAsKey('name') |
||
80 | ->arrayPrototype() |
||
81 | ->beforeNormalization() |
||
82 | ->ifString()->then(static function (string $v): array { return ['class' => $v]; }) |
||
83 | ->end() |
||
84 | ->children() |
||
85 | ->scalarNode('class') |
||
86 | ->cannotBeEmpty() |
||
87 | ->validate() |
||
88 | ->ifTrue(static function (string $class): bool {return !is_a($class, EnumInterface::class, true); }) |
||
89 | ->thenInvalid(sprintf('Invalid class. Expected instance of "%s"', EnumInterface::class)) |
||
90 | ->end() |
||
91 | ->end() |
||
92 | ->enumNode('type') |
||
93 | ->values(['enum', 'string', 'int', 'collection']) |
||
94 | ->info(<<<TXT |
||
95 | Which column definition to use and the way the enumeration values are stored in the database: |
||
96 | - string: VARCHAR |
||
97 | - enum: ENUM(...values) (Your platform must support it) |
||
98 | - int: INT |
||
99 | - collection: JSON |
||
100 | |||
101 | Default is either "string" or "enum", controlled by the `elao_enum.doctrine.enum_sql_declaration` option. |
||
102 | Default for flagged enums is "int". |
||
103 | TXT |
||
104 | ) |
||
105 | ->cannotBeEmpty() |
||
106 | ->defaultValue(null) |
||
107 | ->end() |
||
108 | ->end() |
||
109 | ->end() |
||
110 | ->end() |
||
111 | ->end(); |
||
112 | } |
||
113 | |||
206 |
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.