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