These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the ONGR package. |
||
5 | * |
||
6 | * (c) NFQ Technologies UAB <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace ONGR\ElasticsearchDSL\SearchEndpoint; |
||
13 | |||
14 | use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation; |
||
15 | use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
||
16 | |||
17 | /** |
||
18 | * Search aggregations dsl endpoint. |
||
19 | */ |
||
20 | View Code Duplication | class AggregationsEndpoint extends AbstractSearchEndpoint |
|
21 | { |
||
22 | /** |
||
23 | * Endpoint name |
||
24 | */ |
||
25 | const NAME = 'aggregations'; |
||
26 | |||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) |
||
31 | { |
||
32 | $output = []; |
||
33 | if (count($this->getAll()) > 0) { |
||
34 | /** @var AbstractAggregation $aggregation */ |
||
35 | foreach ($this->getAll() as $aggregation) { |
||
36 | $output[$aggregation->getName()] = $aggregation->toArray(); |
||
0 ignored issues
–
show
|
|||
37 | } |
||
38 | } |
||
39 | |||
40 | return $output; |
||
41 | } |
||
42 | } |
||
43 |
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: