Selectors   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 4

Importance

Changes 0
Metric Value
wmc 15
lcom 3
cbo 4
dl 0
loc 139
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A factory() 0 8 2
A addSelector() 0 4 1
A addNamespace() 0 4 1
A from() 0 4 1
A __construct() 0 4 1
A __callStatic() 0 4 1
A __call() 0 4 1
A apply() 0 4 1
A select() 0 6 1
A accept() 0 4 1
A selector() 0 4 1
A false() 0 4 1
A true() 0 4 1
A null() 0 4 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 callback(callable $callback)
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::$factory = new SelectorFactory(__NAMESPACE__);
48
        }
49
50
        return self::$factory;
51
    }
52
53
    /**
54
     * @param string $selectorClass
55
     * @param string $selectorName
56
     */
57
    public static function addSelector($selectorClass, $selectorName = null)
58
    {
59
        self::factory()->addSelector($selectorClass, $selectorName);
60
    }
61
62
    /**
63
     * @param string $namespace
64
     */
65
    public static function addNamespace($namespace)
66
    {
67
        self::factory()->addNamespace($namespace);
68
    }
69
70
    /**
71
     * @param callable|mixed $selector
72
     *
73
     * @return \Cubiche\Core\Selector\Selectors
74
     */
75
    public static function from($selector)
76
    {
77
        return new static(Selector::from($selector));
78
    }
79
80
    /**
81
     * @param SelectorInterface $selector
82
     */
83
    protected function __construct(SelectorInterface $selector)
84
    {
85
        $this->selector = $selector;
86
    }
87
88
    /**
89
     * @param string $method
90
     * @param array  $arguments
91
     *
92
     * @return mixed
93
     */
94
    public static function __callStatic($method, $arguments)
95
    {
96
        return new static(self::factory()->create($method, $arguments));
97
    }
98
99
    /**
100
     * @param string $method
101
     * @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...
102
     *
103
     * @return mixed
104
     */
105
    public function __call($method, $arguments)
106
    {
107
        return $this->select(self::factory()->create($method, $arguments));
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function apply($value)
114
    {
115
        return $this->selector()->apply($value);
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function select($selector)
122
    {
123
        $this->selector = $this->selector()->select($selector);
124
125
        return $this;
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131
    public function accept(VisitorInterface $visitor)
132
    {
133
        return $this->delegateAccept($this->selector(), $visitor, \func_get_args());
134
    }
135
136
    /**
137
     * @return \Cubiche\Core\Selector\SelectorInterface
138
     */
139
    public function selector()
140
    {
141
        return $this->selector;
142
    }
143
144
    /**
145
     * @return \Cubiche\Core\Selector\Selectors
146
     */
147
    public static function false()
148
    {
149
        return self::value(false);
150
    }
151
152
    /**
153
     * @return \Cubiche\Core\Selector\Selectors
154
     */
155
    public static function true()
156
    {
157
        return self::value(true);
158
    }
159
160
    /**
161
     * @return \Cubiche\Core\Selector\Selectors
162
     */
163
    public static function null()
164
    {
165
        return self::value(null);
166
    }
167
}
168