cubiche /
specification
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * This file is part of the Cubiche package. |
||
| 5 | * |
||
| 6 | * Copyright (c) Cubiche |
||
| 7 | * |
||
| 8 | * For the full copyright and license information, please view the LICENSE |
||
| 9 | * file that was distributed with this source code. |
||
| 10 | */ |
||
| 11 | namespace Cubiche\Core\Specification; |
||
| 12 | |||
| 13 | use Cubiche\Core\Visitor\VisitorInterface; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Specification Trait. |
||
| 17 | * |
||
| 18 | * @author Karel Osorio Ramírez <[email protected]> |
||
| 19 | */ |
||
| 20 | trait SpecificationTrait |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @param string $method |
||
| 24 | * @param array $arguments |
||
| 25 | * |
||
| 26 | * @throws \BadMethodCallException |
||
| 27 | */ |
||
| 28 | public function __call($method, array $arguments) |
||
| 29 | { |
||
| 30 | if ($method === 'and' || $method === 'or') { |
||
| 31 | return \call_user_func_array(array($this, $method.'X'), $arguments); |
||
| 32 | } |
||
| 33 | |||
| 34 | throw new \BadMethodCallException(\sprintf('Call to undefined method %s::%s', \get_class($this), $method)); |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc} |
||
| 39 | */ |
||
| 40 | public function andX(SpecificationInterface $specification) |
||
| 41 | { |
||
| 42 | return new AndSpecification($this, $specification); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | public function orX(SpecificationInterface $specification) |
||
| 49 | { |
||
| 50 | return new OrSpecification($this, $specification); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * {@inheritdoc} |
||
| 55 | */ |
||
| 56 | public function not() |
||
| 57 | { |
||
| 58 | return new NotSpecification($this); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * {@inheritdoc} |
||
| 63 | */ |
||
| 64 | public function accept(VisitorInterface $visitor) |
||
| 65 | { |
||
| 66 | if ($visitor instanceof SpecificationVisitorInterface) { |
||
| 67 | return $this->acceptSpecificationVisitor($visitor); |
||
|
0 ignored issues
–
show
|
|||
| 68 | } |
||
| 69 | |||
| 70 | return parent::accept($visitor); |
||
| 71 | } |
||
| 72 | } |
||
| 73 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: