We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 7 |
Paths | 1 |
Total Lines | 160 |
Code Lines | 148 |
Lines | 0 |
Ratio | 0 % |
Tests | 150 |
CRAP Score | 7 |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
32 | 24 | public function getConfigTreeBuilder() |
|
33 | { |
||
34 | 24 | $treeBuilder = new TreeBuilder(); |
|
35 | 24 | $rootNode = $treeBuilder->root('overblog_graphql'); |
|
36 | |||
37 | $rootNode |
||
38 | 24 | ->children() |
|
39 | 24 | ->enumNode('batching_method') |
|
40 | 24 | ->values(['relay', 'apollo']) |
|
41 | 24 | ->defaultValue('relay') |
|
42 | 24 | ->end() |
|
43 | 24 | ->arrayNode('definitions') |
|
44 | 24 | ->addDefaultsIfNotSet() |
|
45 | 24 | ->children() |
|
46 | 24 | ->scalarNode('internal_error_message')->defaultNull()->end() |
|
47 | 24 | ->variableNode('default_resolver')->defaultValue([Resolver::class, 'defaultResolveFn'])->end() |
|
48 | 24 | ->scalarNode('class_namespace')->defaultValue('Overblog\\GraphQLBundle\\__DEFINITIONS__')->end() |
|
49 | 24 | ->scalarNode('cache_dir')->defaultValue($this->cacheDir.'/overblog/graphql-bundle/__definitions__')->end() |
|
50 | 24 | ->booleanNode('use_classloader_listener')->defaultTrue()->end() |
|
51 | 24 | ->booleanNode('show_debug_info')->defaultFalse()->end() |
|
52 | 24 | ->booleanNode('config_validation')->defaultValue($this->debug)->end() |
|
53 | 24 | ->arrayNode('schema') |
|
54 | 24 | ->beforeNormalization() |
|
55 | 24 | ->ifTrue(function ($v) { |
|
56 | 20 | $needNormalization = isset($v['query']) && is_string($v['query']) || |
|
57 | isset($v['mutation']) && is_string($v['mutation']) || |
||
58 | 20 | isset($v['subscription']) && is_string($v['subscription']); |
|
59 | |||
60 | 20 | return $needNormalization; |
|
61 | 24 | }) |
|
62 | 24 | ->then(function ($v) { |
|
63 | 20 | return ['default' => $v]; |
|
64 | 24 | }) |
|
65 | 24 | ->end() |
|
66 | 24 | ->useAttributeAsKey('name') |
|
67 | 24 | ->prototype('array') |
|
68 | 24 | ->addDefaultsIfNotSet() |
|
69 | 24 | ->children() |
|
70 | 24 | ->scalarNode('query')->defaultNull()->end() |
|
71 | 24 | ->scalarNode('mutation')->defaultNull()->end() |
|
72 | 24 | ->scalarNode('subscription')->defaultNull()->end() |
|
73 | 24 | ->end() |
|
74 | 24 | ->end() |
|
75 | 24 | ->end() |
|
76 | 24 | ->arrayNode('auto_mapping') |
|
77 | 24 | ->treatFalseLike(['enabled' => false]) |
|
78 | 24 | ->treatTrueLike(['enabled' => true]) |
|
79 | 24 | ->treatNullLike(['enabled' => true]) |
|
80 | 24 | ->addDefaultsIfNotSet() |
|
81 | 24 | ->children() |
|
82 | 24 | ->booleanNode('enabled')->defaultTrue()->end() |
|
83 | 24 | ->arrayNode('directories') |
|
84 | 24 | ->info('List of directories containing GraphQL classes.') |
|
85 | 24 | ->prototype('scalar')->end() |
|
86 | 24 | ->end() |
|
87 | 24 | ->end() |
|
88 | 24 | ->end() |
|
89 | 24 | ->arrayNode('mappings') |
|
90 | 24 | ->children() |
|
91 | 24 | ->arrayNode('auto_discover') |
|
92 | 24 | ->treatFalseLike(['bundles' => false, 'root_dir' => false]) |
|
93 | 24 | ->treatTrueLike(['bundles' => true, 'root_dir' => true]) |
|
94 | 24 | ->treatNullLike(['bundles' => true, 'root_dir' => true]) |
|
95 | 24 | ->addDefaultsIfNotSet() |
|
96 | 24 | ->children() |
|
97 | 24 | ->booleanNode('bundles')->defaultTrue()->end() |
|
98 | 24 | ->booleanNode('root_dir')->defaultTrue()->end() |
|
99 | 24 | ->end() |
|
100 | 24 | ->end() |
|
101 | 24 | ->arrayNode('types') |
|
102 | 24 | ->prototype('array') |
|
103 | 24 | ->addDefaultsIfNotSet() |
|
104 | 24 | ->beforeNormalization() |
|
105 | 24 | ->ifTrue(function ($v) { |
|
106 | 19 | return isset($v['type']) && 'yml' === $v['type']; |
|
107 | 24 | }) |
|
108 | 24 | ->then(function ($v) { |
|
109 | 4 | $v['type'] = 'yaml'; |
|
110 | |||
111 | 4 | return $v; |
|
112 | 24 | }) |
|
113 | 24 | ->end() |
|
114 | 24 | ->children() |
|
115 | 24 | ->enumNode('type')->values(['yaml', 'xml'])->defaultNull()->end() |
|
116 | 24 | ->scalarNode('dir')->defaultNull()->end() |
|
117 | 24 | ->scalarNode('suffix')->defaultValue(OverblogGraphQLTypesExtension::DEFAULT_TYPES_SUFFIX)->end() |
|
118 | 24 | ->end() |
|
119 | 24 | ->end() |
|
120 | 24 | ->end() |
|
121 | 24 | ->end() |
|
122 | 24 | ->end() |
|
123 | 24 | ->arrayNode('exceptions') |
|
124 | 24 | ->addDefaultsIfNotSet() |
|
125 | 24 | ->children() |
|
126 | 24 | ->arrayNode('warnings') |
|
127 | 24 | ->treatNullLike([]) |
|
128 | 24 | ->prototype('scalar')->end() |
|
129 | 24 | ->end() |
|
130 | 24 | ->arrayNode('errors') |
|
131 | 24 | ->treatNullLike([]) |
|
132 | 24 | ->prototype('scalar')->end() |
|
133 | 24 | ->end() |
|
134 | 24 | ->arrayNode('types') |
|
135 | 24 | ->addDefaultsIfNotSet() |
|
136 | 24 | ->children() |
|
137 | 24 | ->scalarNode('warnings') |
|
138 | 24 | ->defaultValue(ErrorHandler::DEFAULT_USER_WARNING_CLASS) |
|
139 | 24 | ->end() |
|
140 | 24 | ->scalarNode('errors') |
|
141 | 24 | ->defaultValue(ErrorHandler::DEFAULT_USER_ERROR_CLASS) |
|
142 | 24 | ->end() |
|
143 | 24 | ->end() |
|
144 | 24 | ->end() |
|
145 | 24 | ->end() |
|
146 | 24 | ->end() |
|
147 | |||
148 | 24 | ->arrayNode('builders') |
|
149 | 24 | ->children() |
|
150 | 24 | ->append($this->addBuilderSection('field')) |
|
151 | 24 | ->append($this->addBuilderSection('args')) |
|
152 | 24 | ->end() |
|
153 | 24 | ->end() |
|
154 | |||
155 | 24 | ->end() |
|
156 | 24 | ->end() |
|
157 | 24 | ->arrayNode('services') |
|
158 | 24 | ->addDefaultsIfNotSet() |
|
159 | 24 | ->children() |
|
160 | 24 | ->scalarNode('executor') |
|
161 | 24 | ->defaultValue('overblog_graphql.executor.default') |
|
162 | 24 | ->end() |
|
163 | 24 | ->scalarNode('promise_adapter') |
|
164 | 24 | ->defaultValue('overblog_graphql.promise_adapter.default') |
|
165 | 24 | ->end() |
|
166 | 24 | ->scalarNode('expression_language') |
|
167 | 24 | ->defaultValue('overblog_graphql.expression_language.default') |
|
168 | 24 | ->end() |
|
169 | 24 | ->scalarNode('cache_expression_language_parser') |
|
170 | 24 | ->defaultValue('overblog_graphql.cache_expression_language_parser.default') |
|
171 | 24 | ->end() |
|
172 | 24 | ->end() |
|
173 | 24 | ->end() |
|
174 | 24 | ->arrayNode('security') |
|
175 | 24 | ->addDefaultsIfNotSet() |
|
176 | 24 | ->children() |
|
177 | 24 | ->append($this->addSecurityQuerySection('query_max_depth', QueryDepth::DISABLED)) |
|
178 | 24 | ->append($this->addSecurityQuerySection('query_max_complexity', QueryComplexity::DISABLED)) |
|
179 | 24 | ->booleanNode('handle_cors')->defaultFalse()->end() |
|
180 | 24 | ->end() |
|
181 | 24 | ->end() |
|
182 | 24 | ->arrayNode('versions') |
|
183 | 24 | ->addDefaultsIfNotSet() |
|
184 | 24 | ->children() |
|
185 | 24 | ->enumNode('relay')->values(['modern', 'classic'])->defaultValue('classic')->end() |
|
186 | 24 | ->end() |
|
187 | 24 | ->end() |
|
188 | 24 | ->end(); |
|
189 | |||
190 | 24 | return $treeBuilder; |
|
191 | } |
||
192 | |||
261 |
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: