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 | 127 |
Code Lines | 118 |
Lines | 0 |
Ratio | 0 % |
Tests | 116 |
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 |
||
37 | 17 | public function getConfigTreeBuilder() |
|
38 | { |
||
39 | 17 | $treeBuilder = new TreeBuilder(); |
|
40 | 17 | $rootNode = $treeBuilder->root('overblog_graphql'); |
|
41 | |||
42 | $rootNode |
||
43 | 17 | ->children() |
|
44 | 17 | ->arrayNode('definitions') |
|
45 | 17 | ->addDefaultsIfNotSet() |
|
46 | 17 | ->children() |
|
47 | 17 | ->scalarNode('internal_error_message')->defaultNull()->end() |
|
48 | 17 | ->booleanNode('show_debug_info')->defaultValue(false)->end() |
|
49 | 17 | ->booleanNode('config_validation')->defaultValue($this->debug)->end() |
|
50 | 17 | ->arrayNode('schema') |
|
51 | 17 | ->beforeNormalization() |
|
52 | ->ifTrue(function ($v) { |
||
53 | 14 | $needNormalization = isset($v['query']) && is_string($v['query']) || |
|
54 | isset($v['mutation']) && is_string($v['mutation']) || |
||
55 | 14 | isset($v['subscription']) && is_string($v['subscription']); |
|
56 | |||
57 | 14 | return $needNormalization; |
|
58 | 17 | }) |
|
59 | ->then(function ($v) { |
||
60 | 14 | return ['default' => $v]; |
|
61 | 17 | }) |
|
62 | 17 | ->end() |
|
63 | 17 | ->useAttributeAsKey('name') |
|
64 | 17 | ->prototype('array') |
|
65 | 17 | ->addDefaultsIfNotSet() |
|
66 | 17 | ->children() |
|
67 | 17 | ->scalarNode('query')->defaultNull()->end() |
|
68 | 17 | ->scalarNode('mutation')->defaultNull()->end() |
|
69 | 17 | ->scalarNode('subscription')->defaultNull()->end() |
|
70 | 17 | ->end() |
|
71 | 17 | ->end() |
|
72 | 17 | ->end() |
|
73 | 17 | ->arrayNode('mappings') |
|
74 | 17 | ->children() |
|
75 | 17 | ->arrayNode('types') |
|
76 | 17 | ->prototype('array') |
|
77 | 17 | ->addDefaultsIfNotSet() |
|
78 | 17 | ->children() |
|
79 | 17 | ->enumNode('type')->isRequired()->values(['yml', 'xml'])->end() |
|
80 | 17 | ->scalarNode('dir')->defaultNull()->end() |
|
81 | 17 | ->end() |
|
82 | 17 | ->end() |
|
83 | 17 | ->end() |
|
84 | 17 | ->end() |
|
85 | 17 | ->end() |
|
86 | 17 | ->arrayNode('exceptions') |
|
87 | 17 | ->addDefaultsIfNotSet() |
|
88 | 17 | ->children() |
|
89 | 17 | ->arrayNode('warnings') |
|
90 | 17 | ->treatNullLike([]) |
|
91 | 17 | ->prototype('scalar')->end() |
|
92 | 17 | ->end() |
|
93 | 17 | ->arrayNode('errors') |
|
94 | 17 | ->treatNullLike([]) |
|
95 | 17 | ->prototype('scalar')->end() |
|
96 | 17 | ->end() |
|
97 | 17 | ->arrayNode('types') |
|
98 | 17 | ->addDefaultsIfNotSet() |
|
99 | 17 | ->children() |
|
100 | 17 | ->scalarNode('warnings') |
|
101 | 17 | ->defaultValue(ErrorHandler::DEFAULT_USER_WARNING_CLASS) |
|
102 | 17 | ->end() |
|
103 | 17 | ->scalarNode('errors') |
|
104 | 17 | ->defaultValue(ErrorHandler::DEFAULT_USER_ERROR_CLASS) |
|
105 | 17 | ->end() |
|
106 | 17 | ->end() |
|
107 | 17 | ->end() |
|
108 | 17 | ->end() |
|
109 | 17 | ->end() |
|
110 | |||
111 | 17 | ->arrayNode('builders') |
|
112 | 17 | ->children() |
|
113 | 17 | ->append($this->addBuilderSection('field')) |
|
114 | 17 | ->append($this->addBuilderSection('args')) |
|
115 | 17 | ->end() |
|
116 | 17 | ->end() |
|
117 | |||
118 | 17 | ->end() |
|
119 | 17 | ->end() |
|
120 | 17 | ->arrayNode('templates') |
|
121 | 17 | ->addDefaultsIfNotSet() |
|
122 | 17 | ->children() |
|
123 | 17 | ->scalarNode('graphiql') |
|
124 | 17 | ->defaultValue('OverblogGraphQLBundle:GraphiQL:index.html.twig') |
|
125 | 17 | ->end() |
|
126 | 17 | ->end() |
|
127 | 17 | ->end() |
|
128 | 17 | ->arrayNode('services') |
|
129 | 17 | ->addDefaultsIfNotSet() |
|
130 | 17 | ->children() |
|
131 | 17 | ->scalarNode('executor') |
|
132 | 17 | ->defaultValue('overblog_graphql.executor.default') |
|
133 | 17 | ->end() |
|
134 | 17 | ->scalarNode('promise_adapter') |
|
135 | 17 | ->defaultValue('overblog_graphql.promise_adapter.default') |
|
136 | 17 | ->end() |
|
137 | 17 | ->scalarNode('expression_language') |
|
138 | 17 | ->defaultValue('overblog_graphql.expression_language.default') |
|
139 | 17 | ->end() |
|
140 | 17 | ->scalarNode('cache_expression_language_parser') |
|
141 | 17 | ->defaultValue('overblog_graphql.cache_expression_language_parser.default') |
|
142 | 17 | ->end() |
|
143 | 17 | ->end() |
|
144 | 17 | ->end() |
|
145 | 17 | ->arrayNode('security') |
|
146 | 17 | ->addDefaultsIfNotSet() |
|
147 | 17 | ->children() |
|
148 | 17 | ->append($this->addSecurityQuerySection('query_max_depth', QueryDepth::DISABLED)) |
|
149 | 17 | ->append($this->addSecurityQuerySection('query_max_complexity', QueryComplexity::DISABLED)) |
|
150 | 17 | ->end() |
|
151 | 17 | ->end() |
|
152 | 17 | ->arrayNode('versions') |
|
153 | 17 | ->addDefaultsIfNotSet() |
|
154 | 17 | ->children() |
|
155 | 17 | ->scalarNode('graphiql')->defaultValue('0.9')->end() |
|
156 | 17 | ->scalarNode('react')->defaultValue('15.4')->end() |
|
157 | 17 | ->scalarNode('fetch')->defaultValue('2.0')->end() |
|
158 | 17 | ->end() |
|
159 | 17 | ->end() |
|
160 | 17 | ->end(); |
|
161 | |||
162 | 17 | return $treeBuilder; |
|
163 | } |
||
164 | |||
233 |
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: