Conditions | 17 |
Paths | 80 |
Total Lines | 70 |
Code Lines | 43 |
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 |
||
114 | public function resolveReference($referencePath) |
||
115 | { |
||
116 | if ($this->resolutionScope) { |
||
117 | $referencePath = Helper::resolveURI($this->resolutionScope, $referencePath); |
||
118 | } |
||
119 | |||
120 | $refParts = explode('#', $referencePath, 2); |
||
121 | $url = rtrim($refParts[0], '#'); |
||
122 | $refLocalPath = isset($refParts[1]) ? '#' . $refParts[1] : '#'; |
||
123 | |||
124 | if ($url === $this->url) { |
||
125 | $referencePath = $refLocalPath; |
||
126 | } |
||
127 | |||
128 | $ref = &$this->refs[$referencePath]; |
||
129 | |||
130 | $refResolver = $this; |
||
131 | |||
132 | if (null === $ref) { |
||
133 | if ($referencePath[0] === '#') { |
||
134 | if ($referencePath === '#') { |
||
135 | $ref = new Ref($referencePath, $refResolver->rootData); |
||
136 | } else { |
||
137 | $ref = new Ref($referencePath); |
||
138 | $path = explode('/', trim($referencePath, '#/')); |
||
139 | |||
140 | /** @var JsonSchema $branch */ |
||
141 | $branch = &$refResolver->rootData; |
||
142 | while (!empty($path)) { |
||
143 | if (isset($branch->id) && is_string($branch->id)) { |
||
144 | $refResolver->updateResolutionScope($branch->id); |
||
145 | } |
||
146 | |||
147 | $folder = array_shift($path); |
||
148 | |||
149 | // unescaping special characters |
||
150 | // https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-07#section-4 |
||
151 | // https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/130 |
||
152 | $folder = str_replace(array('~0', '~1', '%25'), array('~', '/', '%'), $folder); |
||
153 | |||
154 | if ($branch instanceof \stdClass && isset($branch->$folder)) { |
||
155 | $branch = &$branch->$folder; |
||
156 | } elseif (is_array($branch) && isset($branch[$folder])) { |
||
157 | $branch = &$branch[$folder]; |
||
158 | } else { |
||
159 | throw new InvalidValue('Could not resolve ' . $referencePath . '@' . $this->getResolutionScope() . ': ' . $folder); |
||
160 | } |
||
161 | } |
||
162 | $ref->setData($branch); |
||
163 | } |
||
164 | } else { |
||
165 | if ($url !== $this->url) { |
||
166 | $rootResolver = $this->rootResolver ? $this->rootResolver : $this; |
||
167 | $refResolver = &$rootResolver->remoteRefResolvers[$url]; |
||
168 | if (null === $refResolver) { |
||
169 | $rootData = $rootResolver->getRefProvider()->getSchemaData($url); |
||
170 | $refResolver = new RefResolver($rootData); |
||
171 | $refResolver->rootResolver = $rootResolver; |
||
172 | $refResolver->refProvider = $this->refProvider; |
||
173 | $refResolver->url = $url; |
||
174 | $rootResolver->setResolutionScope($url); |
||
175 | } |
||
176 | } |
||
177 | |||
178 | $ref = $refResolver->resolveReference($refLocalPath); |
||
179 | } |
||
180 | } |
||
181 | |||
182 | return $ref; |
||
183 | } |
||
184 | |||
186 | } |