1 | <?php |
||
32 | class BucketOutput extends AbstractOutput |
||
33 | { |
||
34 | /** |
||
35 | * @param Builder $builder |
||
36 | * @param Stage\Bucket $bucket |
||
37 | */ |
||
38 | 3 | public function __construct(Builder $builder, Stage\Bucket $bucket) |
|
42 | |||
43 | /** |
||
44 | * An expression to group documents by. To specify a field path, prefix the |
||
45 | * field name with a dollar sign $ and enclose it in quotes. |
||
46 | * |
||
47 | * @param mixed|Expr $expression |
||
48 | * @return Stage\Bucket |
||
49 | */ |
||
50 | public function groupBy($expression) |
||
54 | |||
55 | /** |
||
56 | * An array of values based on the groupBy expression that specify the |
||
57 | * boundaries for each bucket. |
||
58 | * |
||
59 | * Each adjacent pair of values acts as the inclusive lower boundary and the |
||
60 | * exclusive upper boundary for the bucket. You must specify at least two |
||
61 | * boundaries. The specified values must be in ascending order and all of |
||
62 | * the same type. The exception is if the values are of mixed numeric types. |
||
63 | * |
||
64 | * @param array ...$boundaries |
||
65 | * |
||
66 | * @return Stage\Bucket |
||
67 | */ |
||
68 | public function boundaries(...$boundaries) |
||
72 | |||
73 | /** |
||
74 | * A literal that specifies the _id of an additional bucket that contains |
||
75 | * all documents whose groupBy expression result does not fall into a bucket |
||
76 | * specified by boundaries. |
||
77 | * |
||
78 | * @param mixed $default |
||
79 | * |
||
80 | * @return Stage\Bucket |
||
81 | */ |
||
82 | public function defaultBucket($default) |
||
86 | } |
||
87 |
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 sub-classes 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 parent class: