1 | <?php |
||
22 | class InvariantCheckerAspect extends AbstractContractAspect implements Aspect |
||
23 | { |
||
24 | /** |
||
25 | * @var InvariantFetcher |
||
26 | */ |
||
27 | private $invariantFetcher; |
||
28 | |||
29 | public function __construct(Reader $reader) |
||
34 | |||
35 | /** |
||
36 | * Verifies invariants for contract class |
||
37 | * |
||
38 | * @Around("@within(PhpDeal\Annotation\Invariant) && execution(public **->*(*))") |
||
39 | * @param MethodInvocation $invocation |
||
40 | * |
||
41 | * @throws ContractViolation |
||
42 | * @return mixed |
||
43 | */ |
||
44 | 7 | public function invariantContract(MethodInvocation $invocation) |
|
45 | { |
||
46 | 7 | $object = $invocation->getThis(); |
|
47 | 7 | $args = $this->fetchMethodArguments($invocation); |
|
48 | 7 | $class = $invocation->getMethod()->getDeclaringClass(); |
|
49 | 7 | if ($class->isCloneable()) { |
|
50 | 7 | $args['__old'] = clone $object; |
|
51 | } |
||
52 | |||
53 | 7 | $result = $invocation->proceed(); |
|
54 | 7 | $args['__result'] = $result; |
|
55 | |||
56 | 7 | $allContracts = $this->fetchAllContracts($class); |
|
57 | 7 | $this->ensureContracts($invocation, $allContracts, $object, $class->name, $args); |
|
58 | |||
59 | return $result; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param ReflectionClass $class |
||
64 | * @return array |
||
65 | */ |
||
66 | 7 | private function fetchAllContracts(ReflectionClass $class) |
|
77 | } |
||
78 |