RegexFacade::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Gobie\Regex\Wrappers;
4
5
/**
6
 * Facade over static Wrappers to use them in object method calls and DI.
7
 *
8
 * @method bool match($pattern, $subject)
9
 * @method string get($pattern, $subject)
10
 * @method string[][] getAll($pattern, $subject)
11
 * @method string|string[] replace($pattern, $replacement, $subject)
12
 * @method string[] split($pattern, $subject)
13
 * @method string[] grep($pattern, $subject)
14
 * @method string[] filter($pattern, $replacement, $subject)
15
 */
16
class RegexFacade
17
{
18
19
    const PCRE = '\Gobie\Regex\Wrappers\Pcre\PcreRegex';
20
21
    const MB = '\Gobie\Regex\Wrappers\Mb\MbRegex';
22
23
    /**
24
     * Class name of regex driver.
25
     *
26
     * @var string
27
     */
28
    private $driverClass;
29
30
    /**
31
     * @param string $driverClass Fully qualified class
32
     */
33 6
    public function __construct($driverClass)
34
    {
35 6
        $this->driverClass = $driverClass;
36 6
    }
37
38
    /**
39
     * Redirects object calls to static methods of the driver.
40
     *
41
     * @param string $name      Method
42
     * @param array  $arguments Arguments
43
     * @return mixed Whatever is returned from drivers
44
     * @throws \BadMethodCallException When driver doesn't implement requested functionality
45
     */
46 4
    public function __call($name, $arguments)
47
    {
48 4
        if (!\method_exists($this->driverClass, $name)) {
49 2
            throw new \BadMethodCallException('Method ' . $this->driverClass . '::' . $name . ' not implemented');
50
        }
51
52 2
        return \call_user_func_array(array($this->driverClass, $name), $arguments);
53
    }
54
55
    /**
56
     * Getter for driver class name.
57
     *
58
     * @return string
59
     */
60 2
    public function getDriverClass()
61
    {
62 2
        return $this->driverClass;
63
    }
64
}
65