1 | <?php |
||
25 | class ContractCheckerAspect implements Aspect |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * Annotation reader |
||
30 | * |
||
31 | * @var Reader|null |
||
32 | */ |
||
33 | private $reader = null; |
||
34 | |||
35 | /** |
||
36 | * Default constructor |
||
37 | * |
||
38 | * @param Reader $reader Annotation reader |
||
39 | */ |
||
40 | public function __construct(Reader $reader) |
||
44 | |||
45 | /** |
||
46 | * Verifies pre-condition contract for the method |
||
47 | * |
||
48 | * @param MethodInvocation $invocation |
||
49 | * @Before("@execution(PhpDeal\Annotation\Verify)") |
||
50 | * |
||
51 | * @throws ContractViolation |
||
52 | */ |
||
53 | 8 | public function preConditionContract(MethodInvocation $invocation) |
|
71 | |||
72 | /** |
||
73 | * Verifies post-condition contract for the method |
||
74 | * |
||
75 | * @Around("@execution(PhpDeal\Annotation\Ensure)") |
||
76 | * @param MethodInvocation $invocation |
||
77 | * |
||
78 | * @throws ContractViolation |
||
79 | * @return mixed |
||
80 | */ |
||
81 | 3 | public function postConditionContract(MethodInvocation $invocation) |
|
107 | |||
108 | /** |
||
109 | * Verifies invariants for contract class |
||
110 | * |
||
111 | * @Around("@within(PhpDeal\Annotation\Invariant) && execution(public **->*(*))") |
||
112 | * @param MethodInvocation $invocation |
||
113 | * |
||
114 | * @throws ContractViolation |
||
115 | * @return mixed |
||
116 | */ |
||
117 | 3 | public function invariantContract(MethodInvocation $invocation) |
|
143 | |||
144 | /** |
||
145 | * Returns a result of contract verification |
||
146 | * |
||
147 | * @param object|string $instance Invocation instance or string for static class |
||
148 | * @param string $scope Scope of method |
||
149 | * @param array $args List of arguments for the method |
||
150 | * @param Annotation $annotation Contract annotation |
||
151 | * @throws DomainException |
||
152 | */ |
||
153 | 14 | private function ensureContractSatisfied($instance, $scope, array $args, $annotation) |
|
174 | |||
175 | /** |
||
176 | * Returns an associative list of arguments for the method invocation |
||
177 | * |
||
178 | * @param MethodInvocation $invocation |
||
179 | * |
||
180 | * @return array |
||
181 | */ |
||
182 | 14 | private function getMethodArguments(MethodInvocation $invocation) |
|
192 | } |
||
193 |