1 | <?php namespace Neomerx\JsonApi\Factories; |
||
74 | class Factory implements FactoryInterface |
||
75 | { |
||
76 | /** |
||
77 | * @var LoggerInterface |
||
78 | */ |
||
79 | protected $logger; |
||
80 | |||
81 | /** |
||
82 | * Constructor. |
||
83 | */ |
||
84 | 193 | public function __construct() |
|
88 | |||
89 | /** |
||
90 | * @inheritdoc |
||
91 | */ |
||
92 | 2 | public function setLogger(LoggerInterface $logger) |
|
96 | |||
97 | /** |
||
98 | * @inheritdoc |
||
99 | */ |
||
100 | 71 | public function createEncoder(ContainerInterface $container, EncoderOptions $encoderOptions = null) |
|
108 | |||
109 | /** |
||
110 | * @inheritdoc |
||
111 | */ |
||
112 | 104 | public function createDocument() |
|
120 | |||
121 | /** |
||
122 | * @inheritdoc |
||
123 | */ |
||
124 | 3 | public function createError( |
|
136 | /** |
||
137 | * @inheritdoc |
||
138 | */ |
||
139 | 62 | public function createReply($replyType, StackReadOnlyInterface $stack) |
|
143 | |||
144 | /** |
||
145 | * @inheritdoc |
||
146 | */ |
||
147 | 24 | public function createEmptyReply( |
|
153 | |||
154 | /** |
||
155 | * @inheritdoc |
||
156 | */ |
||
157 | 68 | public function createParser(ContainerInterface $container, ParserManagerInterface $manager) |
|
165 | |||
166 | /** |
||
167 | * @inheritdoc |
||
168 | */ |
||
169 | 66 | public function createManager(ParametersAnalyzerInterface $parameterAnalyzer) |
|
177 | |||
178 | /** |
||
179 | * @inheritdoc |
||
180 | */ |
||
181 | 71 | public function createFrame(StackFrameReadOnlyInterface $previous = null) |
|
185 | |||
186 | /** |
||
187 | * @inheritdoc |
||
188 | */ |
||
189 | 72 | public function createStack() |
|
193 | |||
194 | /** |
||
195 | * @inheritdoc |
||
196 | */ |
||
197 | 66 | public function createReplyInterpreter(DocumentInterface $document, ParametersAnalyzerInterface $parameterAnalyzer) |
|
205 | |||
206 | /** |
||
207 | * @inheritdoc |
||
208 | */ |
||
209 | 69 | public function createParametersAnalyzer(EncodingParametersInterface $parameters, ContainerInterface $container) |
|
217 | |||
218 | /** |
||
219 | * @inheritdoc |
||
220 | */ |
||
221 | 1 | public function createMediaType($type, $subType, $parameters = null) |
|
225 | |||
226 | /** |
||
227 | * @inheritdoc |
||
228 | */ |
||
229 | 70 | public function createQueryParameters( |
|
246 | |||
247 | /** |
||
248 | * @inheritdoc |
||
249 | */ |
||
250 | 12 | public function createHeaderParameters($method, AcceptHeaderInterface $accept, HeaderInterface $contentType) |
|
254 | |||
255 | /** |
||
256 | * @inheritdoc |
||
257 | */ |
||
258 | 1 | public function createNoContentHeaderParameters($method, AcceptHeaderInterface $accept) |
|
262 | |||
263 | /** |
||
264 | * @inheritdoc |
||
265 | */ |
||
266 | 26 | public function createQueryParametersParser() |
|
274 | |||
275 | /** |
||
276 | * @inheritdoc |
||
277 | */ |
||
278 | 15 | public function createHeaderParametersParser() |
|
286 | |||
287 | /** |
||
288 | * @inheritdoc |
||
289 | */ |
||
290 | 17 | public function createSortParam($sortField, $isAscending) |
|
294 | |||
295 | /** |
||
296 | * @inheritdoc |
||
297 | */ |
||
298 | 1 | public function createSupportedExtensions($extensions = MediaTypeInterface::NO_EXT) |
|
302 | |||
303 | /** |
||
304 | * @inheritdoc |
||
305 | */ |
||
306 | 1 | public function createAcceptMediaType( |
|
316 | |||
317 | /** |
||
318 | * @inheritdoc |
||
319 | */ |
||
320 | 1 | public function createAcceptHeader($unsortedMediaTypes) |
|
324 | |||
325 | /** |
||
326 | * @inheritdoc |
||
327 | */ |
||
328 | 8 | public function createHeadersChecker(CodecMatcherInterface $codecMatcher) |
|
332 | |||
333 | /** |
||
334 | * @inheritdoc |
||
335 | * |
||
336 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||
337 | */ |
||
338 | 14 | public function createQueryChecker( |
|
355 | |||
356 | /** |
||
357 | * @inheritdoc |
||
358 | */ |
||
359 | 83 | public function createContainer(array $providers = []) |
|
367 | |||
368 | /** |
||
369 | * @inheritdoc |
||
370 | */ |
||
371 | 83 | public function createResourceObject( |
|
379 | |||
380 | /** |
||
381 | * @inheritdoc |
||
382 | */ |
||
383 | 83 | public function createRelationshipObject($name, $data, $links, $meta, $isShowData, $isRoot) |
|
387 | |||
388 | /** |
||
389 | * @inheritdoc |
||
390 | * |
||
391 | * @SuppressWarnings(PHPMD.BooleanArgumentFlag) |
||
392 | */ |
||
393 | 58 | public function createLink($subHref, $meta = null, $treatAsHref = false) |
|
397 | |||
398 | /** |
||
399 | * @inheritdoc |
||
400 | */ |
||
401 | 3 | public function createResourceIdentifierSchemaAdapter(SchemaProviderInterface $schema) |
|
405 | |||
406 | /** |
||
407 | * @inheritdoc |
||
408 | */ |
||
409 | 3 | public function createResourceIdentifierContainerAdapter(ContainerInterface $container) |
|
413 | |||
414 | /** |
||
415 | * @inheritdoc |
||
416 | */ |
||
417 | 1 | public function createIdentitySchema(ContainerInterface $container, $classType, Closure $identityClosure) |
|
421 | |||
422 | /** |
||
423 | * @inheritdoc |
||
424 | */ |
||
425 | 20 | public function createCodecMatcher() |
|
429 | } |
||
430 |
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 implementation 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 interface: