Completed
Push — master ( a04aa9...a7d02a )
by Ivannis Suárez
02:48
created

Selectors::accept()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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\Selector;
12
13
use Cubiche\Core\Visitor\VisitorInterface;
14
15
/**
16
 * Selector Builder Class.
17
 *
18
 * @method static Selectors key(string $name)
19
 * @method static Selectors property(string $name)
20
 * @method static Selectors method(string $name)
21
 * @method static Selectors custom(callable $callable)
22
 * @method static Selectors value($value)
23
 * @method static Selectors count()
24
 * @method static Selectors composite(SelectorInterface $x, SelectorInterface $y)
25
 * @method static Selectors this()
26
 *
27
 * @author Karel Osorio Ramírez <[email protected]>
28
 */
29
class Selectors extends Selector
30
{
31
    /**
32
     * @var SelectorFactoryInterface
33
     */
34
    protected static $factory;
35
36
    /**
37
     * @var SelectorInterface
38
     */
39
    private $selector;
40
41
    /**
42
     * @return \Cubiche\Core\Selector\SelectorFactoryInterface
43
     */
44
    protected static function factory()
45
    {
46
        if (self::$factory === null) {
47
            self::setFactory(new SelectorFactory(__NAMESPACE__));
48
        }
49
50
        return self::$factory;
51
    }
52
53
    /**
54
     * @param SelectorFactoryInterface $factory
55
     */
56
    public static function setFactory(SelectorFactoryInterface $factory)
57
    {
58
        self::$factory = $factory;
59
    }
60
61
    /**
62
     * @param string $selectorClass
63
     * @param string $selectorName
64
     */
65
    public static function addSelector($selectorClass, $selectorName = null)
66
    {
67
        self::factory()->addSelector($selectorClass, $selectorName);
68
    }
69
70
    /**
71
     * @param string $namespace
72
     */
73
    public static function addNamespace($namespace)
74
    {
75
        self::factory()->addNamespace($namespace);
76
    }
77
78
    /**
79
     * @param SelectorInterface $selector
80
     */
81
    protected function __construct(SelectorInterface $selector)
82
    {
83
        $this->selector = $selector;
84
    }
85
86
    /**
87
     * @param string $method
88
     * @param array  $arguments
89
     *
90
     * @return mixed
91
     */
92
    public static function __callStatic($method, $arguments)
93
    {
94
        return new static(self::factory()->create($method, $arguments));
95
    }
96
97
    /**
98
     * @param string $method
99
     * @param array  $args
0 ignored issues
show
Bug introduced by
There is no parameter named $args. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
100
     *
101
     * @return mixed
102
     */
103
    public function __call($method, $arguments)
104
    {
105
        return $this->select(self::factory()->create($method, $arguments));
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111
    public function apply($value)
112
    {
113
        return $this->selector()->apply($value);
114
    }
115
116
    /**
117
     * {@inheritdoc}
118
     */
119
    public function select(callable $selector)
120
    {
121
        $this->selector = $this->selector()->select($selector);
122
123
        return $this;
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129
    public function accept(VisitorInterface $visitor)
130
    {
131
        return $this->delegateAccept($this->selector(), $visitor, \func_get_args());
132
    }
133
134
    /**
135
     * @return \Cubiche\Core\Selector\SelectorInterface
136
     */
137
    public function selector()
138
    {
139
        return $this->selector;
140
    }
141
}
142