1 | <?php |
||
23 | class CompositeAggregation extends AbstractAggregation |
||
24 | { |
||
25 | use BucketingTrait; |
||
26 | |||
27 | /** |
||
28 | * @var BuilderInterface[] |
||
29 | */ |
||
30 | private $sources = []; |
||
31 | |||
32 | /** |
||
33 | * @var int |
||
34 | */ |
||
35 | private $size; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | private $after; |
||
41 | |||
42 | /** |
||
43 | * Inner aggregations container init. |
||
44 | * |
||
45 | * @param string $name |
||
46 | * @param BuilderInterface[] $sources |
||
47 | */ |
||
48 | public function __construct($name, $sources = []) |
||
56 | |||
57 | /** |
||
58 | * @param BuilderInterface $agg |
||
59 | * |
||
60 | * @throws \LogicException |
||
61 | * |
||
62 | * @return self |
||
63 | */ |
||
64 | public function addSource(BuilderInterface $agg) |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function getArray() |
||
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | public function getType() |
||
100 | |||
101 | /** |
||
102 | * Sets size |
||
103 | * |
||
104 | * @param int $size Size |
||
105 | * |
||
106 | * @return void |
||
107 | */ |
||
108 | public function setSize($size) |
||
112 | |||
113 | /** |
||
114 | * Returns size |
||
115 | * |
||
116 | * @return int |
||
117 | */ |
||
118 | public function getSize() |
||
122 | |||
123 | /** |
||
124 | * Sets after |
||
125 | * |
||
126 | * @param array $after After |
||
127 | * |
||
128 | * @return void |
||
129 | */ |
||
130 | public function setAfter(array $after) |
||
134 | |||
135 | /** |
||
136 | * Returns after |
||
137 | * |
||
138 | * @return array |
||
139 | */ |
||
140 | public function getAfter() |
||
144 | } |
||
145 |
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: