Completed
Push — master ( 0375a2...821836 )
by Ivannis Suárez
02:49
created

SpecificationTrait.php (1 issue)

Upgrade to new PHP Analysis Engine

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
Documentation Bug introduced by
The method acceptSpecificationVisitor does not exist on object<Cubiche\Core\Spec...ion\SpecificationTrait>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and 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 __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
68
        }
69
70
        return parent::accept($visitor);
71
    }
72
}
73