1 | <?php |
||
24 | class ContractCheckerAspect implements Aspect |
||
25 | { |
||
26 | /** |
||
27 | * Annotation reader |
||
28 | * |
||
29 | * @var Reader|null |
||
30 | */ |
||
31 | private $reader = null; |
||
32 | |||
33 | /** |
||
34 | * Default constructor |
||
35 | * |
||
36 | * @param Reader $reader Annotation reader |
||
37 | */ |
||
38 | public function __construct(Reader $reader) |
||
42 | |||
43 | /** |
||
44 | * Verifies pre-condition contract for the method |
||
45 | * |
||
46 | * @param MethodInvocation $invocation |
||
47 | * @Before("@execution(PhpDeal\Annotation\Verify)") |
||
48 | * |
||
49 | * @throws ContractViolation |
||
50 | */ |
||
51 | 19 | public function preConditionContract(MethodInvocation $invocation) |
|
55 | |||
56 | /** |
||
57 | * Verifies post-condition contract for the method |
||
58 | * |
||
59 | * @Around("@execution(PhpDeal\Annotation\Ensure)") |
||
60 | * @param MethodInvocation $invocation |
||
61 | * |
||
62 | * @throws ContractViolation |
||
63 | * @return mixed |
||
64 | */ |
||
65 | 8 | public function postConditionContract(MethodInvocation $invocation) |
|
69 | |||
70 | /** |
||
71 | * Verifies invariants for contract class |
||
72 | * |
||
73 | * @Around("@within(PhpDeal\Annotation\Invariant) && execution(public **->*(*))") |
||
74 | * @param MethodInvocation $invocation |
||
75 | * |
||
76 | * @throws ContractViolation |
||
77 | * @return mixed |
||
78 | */ |
||
79 | 7 | public function invariantContract(MethodInvocation $invocation) |
|
83 | } |
||
84 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: