Conditions | 9 |
Paths | 13 |
Total Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Tests | 26 |
CRAP Score | 9.3399 |
Changes | 0 |
1 | <?php |
||
22 | 5 | public function convert( LogicalFilter $filter ) |
|
23 | { |
||
24 | 5 | $rootOr = $filter->simplify(['force_logical_core' => true])->getRules(); |
|
25 | |||
26 | // TODO remove this once TrueRule implemented https://github.com/jclaveau/php-logical-filter/issues/59 |
||
27 | 5 | if (null === $rootOr) { |
|
28 | 2 | return $this; |
|
29 | } |
||
30 | |||
31 | 3 | if ( ! $rootOr->hasSolution()) { |
|
32 | return $this; |
||
33 | } |
||
34 | |||
35 | 3 | foreach ($rootOr->getOperands() as $andOperand) { |
|
36 | 3 | $this->onOpenOr(); |
|
37 | 3 | $operandsByFields = $andOperand->groupOperandsByFieldAndOperator(); |
|
|
|||
38 | |||
39 | 3 | foreach ($operandsByFields as $field => $operandsByOperator) { |
|
40 | 3 | foreach ($operandsByOperator as $operator => $operandsOfOperator) { |
|
41 | 3 | if (1 != count($operandsOfOperator)) { |
|
42 | throw new \RuntimeException( |
||
43 | "Once a logical filter is simplified, there MUST be " |
||
44 | ."no more than one operand by operator instead of for '$field' / '$operator': " |
||
45 | .var_export($operandsOfOperator, true) |
||
46 | ); |
||
47 | } |
||
48 | |||
49 | 3 | $operandsByFields[ $field ][ $operator ] = $operandsOfOperator[0]; |
|
50 | 3 | } |
|
51 | 3 | } |
|
52 | |||
53 | 3 | foreach ($operandsByFields as $field => $operandsByOperator) { |
|
54 | 3 | foreach ($operandsByOperator as $operator => $operand) { |
|
55 | 3 | $this->onAndPossibility( |
|
56 | 3 | $field, |
|
57 | 3 | $operator, |
|
58 | 3 | $operand, |
|
59 | $operandsByFields |
||
60 | 3 | ); |
|
61 | 3 | } |
|
62 | 3 | } |
|
63 | |||
64 | 3 | $this->onCloseOr(); |
|
65 | 3 | } |
|
66 | 3 | } |
|
67 | |||
70 |
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: