| 1 | <?php |
||
| 23 | class CompositeAggregation extends AbstractAggregation |
||
| 24 | { |
||
| 25 | use BucketingTrait; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var BuilderInterface[] |
||
| 29 | */ |
||
| 30 | private $sources = []; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Inner aggregations container init. |
||
| 34 | * |
||
| 35 | * @param string $name |
||
| 36 | * @param BuilderInterface[] $sources |
||
| 37 | */ |
||
| 38 | public function __construct($name, $sources = []) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param BuilderInterface $agg |
||
| 49 | * |
||
| 50 | * @throws \LogicException |
||
| 51 | * |
||
| 52 | * @return self |
||
| 53 | */ |
||
| 54 | public function addSource(BuilderInterface $agg) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * {@inheritdoc} |
||
| 65 | */ |
||
| 66 | public function getArray() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * {@inheritdoc} |
||
| 75 | */ |
||
| 76 | public function getType() |
||
| 80 | } |
||
| 81 |
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: