1 | <?php |
||
4 | abstract class AbstractRule implements \JsonSerializable |
||
5 | { |
||
6 | use Trait_RuleWithOptions; |
||
7 | use Trait_RuleWithCache; |
||
8 | use Trait_ExportableRule; |
||
9 | use Trait_RuleFactory; |
||
10 | |||
11 | /** |
||
12 | * Clones the rule with a chained syntax. |
||
13 | * |
||
14 | * @return AbstractRule A copy of the current instance. |
||
15 | */ |
||
16 | 135 | public function copy() |
|
20 | |||
21 | /** |
||
22 | * @deprecated addMinimalCase |
||
23 | */ |
||
24 | 4 | protected function forceLogicalCore() |
|
28 | |||
29 | /** |
||
30 | * Forces the two firsts levels of the tree to be an OrRule having |
||
31 | * only AndRules as operands: |
||
32 | * ['field', '=', '1'] <=> ['or', ['and', ['field', '=', '1']]] |
||
33 | * As a simplified ruleTree will alwways be reduced to this structure |
||
34 | * with no suboperands others than atomic ones or a simpler one like: |
||
35 | * ['or', ['field', '=', '1'], ['field2', '>', '3']] |
||
36 | * |
||
37 | * This helpes to ease the result of simplify() |
||
38 | * |
||
39 | * @return OrRule |
||
40 | */ |
||
41 | 48 | public function addMinimalCase() |
|
106 | |||
107 | /**/ |
||
108 | } |
||
109 |
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: