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

Selector::from()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
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\Visitee;
14
15
/**
16
 * Abstract Selector Class.
17
 *
18
 * @author Karel Osorio Ramírez <[email protected]>
19
 */
20
abstract class Selector extends Visitee implements SelectorInterface
21
{
22
    /**
23
     * @param callable $selector
24
     *
25
     * @return \Cubiche\Core\Selector\SelectorInterface
26
     */
27
    public static function from(callable $selector)
28
    {
29
        if ($selector instanceof SelectorInterface) {
30
            return $selector;
31
        }
32
33
        return new Custom($selector);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function __invoke()
40
    {
41
        return \call_user_func_array(array($this, 'apply'), \func_get_args());
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function select(callable $selector)
48
    {
49
        return new Composite($this, self::from($selector));
50
    }
51
}
52