Conditions | 19 |
Paths | 96 |
Total Lines | 76 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | 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 |
||
130 | public function resolveReference($referencePath) |
||
131 | { |
||
132 | if ($this->resolutionScope) { |
||
133 | $referencePath = Helper::resolveURI($this->resolutionScope, $referencePath); |
||
134 | } |
||
135 | |||
136 | $refParts = explode('#', $referencePath, 2); |
||
137 | $url = rtrim($refParts[0], '#'); |
||
138 | $refLocalPath = isset($refParts[1]) ? '#' . $refParts[1] : '#'; |
||
139 | |||
140 | if ($url === $this->url) { |
||
141 | $referencePath = $refLocalPath; |
||
142 | } |
||
143 | |||
144 | /** @var null|Ref $ref */ |
||
145 | $ref = &$this->refs[$referencePath]; |
||
146 | |||
147 | $refResolver = $this; |
||
148 | |||
149 | if (null === $ref) { |
||
150 | if ($referencePath[0] === '#') { |
||
151 | if ($referencePath === '#') { |
||
152 | $ref = new Ref($referencePath, $refResolver->rootData); |
||
153 | } else { |
||
154 | $ref = new Ref($referencePath); |
||
155 | $path = explode('/', trim($referencePath, '#/')); |
||
156 | |||
157 | /** @var JsonSchema $branch */ |
||
158 | $branch = &$refResolver->rootData; |
||
159 | while (!empty($path)) { |
||
160 | if (isset($branch->{Schema::ID_D4}) && is_string($branch->{Schema::ID_D4})) { |
||
161 | $refResolver->updateResolutionScope($branch->{Schema::ID_D4}); |
||
162 | } |
||
163 | if (isset($branch->{Schema::ID}) && is_string($branch->{Schema::ID})) { |
||
164 | $refResolver->updateResolutionScope($branch->{Schema::ID}); |
||
165 | } |
||
166 | |||
167 | $folder = array_shift($path); |
||
168 | |||
169 | // unescaping special characters |
||
170 | // https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07#section-4 |
||
171 | // https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/130 |
||
172 | $folder = str_replace(array('~0', '~1', '%25'), array('~', '/', '%'), $folder); |
||
173 | |||
174 | if ($branch instanceof \stdClass && isset($branch->$folder)) { |
||
175 | $branch = &$branch->$folder; |
||
176 | } elseif (is_array($branch) && isset($branch[$folder])) { |
||
177 | $branch = &$branch[$folder]; |
||
178 | } else { |
||
179 | throw new InvalidValue('Could not resolve ' . $referencePath . '@' . $this->getResolutionScope() . ': ' . $folder); |
||
180 | } |
||
181 | } |
||
182 | $ref->setData($branch); |
||
183 | } |
||
184 | } else { |
||
185 | if ($url !== $this->url) { |
||
186 | $rootResolver = $this->rootResolver ? $this->rootResolver : $this; |
||
187 | /** @var null|RefResolver $refResolver */ |
||
188 | $refResolver = &$rootResolver->remoteRefResolvers[$url]; |
||
189 | $this->setResolutionScope($url); |
||
190 | if (null === $refResolver) { |
||
191 | $rootData = $rootResolver->getRefProvider()->getSchemaData($url); |
||
192 | $refResolver = new RefResolver($rootData); |
||
|
|||
193 | $refResolver->rootResolver = $rootResolver; |
||
194 | $refResolver->refProvider = $this->refProvider; |
||
195 | $refResolver->url = $url; |
||
196 | $rootResolver->setResolutionScope($url); |
||
197 | } |
||
198 | } |
||
199 | |||
200 | $ref = $refResolver->resolveReference($refLocalPath); |
||
201 | } |
||
202 | } |
||
203 | |||
204 | return $ref; |
||
205 | } |
||
206 | |||
256 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: