1 | <?php |
||
24 | class ContractCheckerAspect implements Aspect |
||
25 | { |
||
26 | |||
27 | /** |
||
28 | * Annotation reader |
||
29 | * |
||
30 | * @var Reader|null |
||
31 | */ |
||
32 | private $reader = null; |
||
33 | |||
34 | /** |
||
35 | * @var MethodInvocation |
||
36 | */ |
||
37 | private $invocation; |
||
38 | |||
39 | /** |
||
40 | * Default constructor |
||
41 | * |
||
42 | * @param Reader $reader Annotation reader |
||
43 | */ |
||
44 | public function __construct(Reader $reader) |
||
48 | |||
49 | /** |
||
50 | * Verifies pre-condition contract for the method |
||
51 | * |
||
52 | * @param MethodInvocation $invocation |
||
53 | * @Before("@execution(PhpDeal\Annotation\Verify)") |
||
54 | * |
||
55 | * @throws ContractViolation |
||
56 | */ |
||
57 | 8 | public function preConditionContract(MethodInvocation $invocation) |
|
74 | |||
75 | /** |
||
76 | * Verifies post-condition contract for the method |
||
77 | * |
||
78 | * @Around("@execution(PhpDeal\Annotation\Ensure)") |
||
79 | * @param MethodInvocation $invocation |
||
80 | * |
||
81 | * @throws ContractViolation |
||
82 | * @return mixed |
||
83 | */ |
||
84 | 3 | public function postConditionContract(MethodInvocation $invocation) |
|
109 | |||
110 | /** |
||
111 | * Verifies invariants for contract class |
||
112 | * |
||
113 | * @Around("@within(PhpDeal\Annotation\Invariant) && execution(public **->*(*))") |
||
114 | * @param MethodInvocation $invocation |
||
115 | * |
||
116 | * @throws ContractViolation |
||
117 | * @return mixed |
||
118 | */ |
||
119 | 3 | public function invariantContract(MethodInvocation $invocation) |
|
144 | |||
145 | /** |
||
146 | * Returns a result of contract verification |
||
147 | * |
||
148 | * @param object|string $instance Invocation instance or string for static class |
||
149 | * @param string $scope Scope of method |
||
150 | * @param array $args List of arguments for the method |
||
151 | * @param Annotation $annotation Contract annotation |
||
152 | * |
||
153 | * @return mixed |
||
154 | */ |
||
155 | 14 | private function isContractSatisfied($instance, $scope, array $args, $annotation) |
|
177 | |||
178 | /** |
||
179 | * Returns an associative list of arguments for the method invocation |
||
180 | * |
||
181 | * @param MethodInvocation $invocation |
||
182 | * |
||
183 | * @return array |
||
184 | */ |
||
185 | 14 | private function getMethodArguments(MethodInvocation $invocation) |
|
195 | } |
||
196 |