Completed
Pull Request — master (#37)
by Alberto
02:21
created

AbstractStub   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A getName() 0 4 1
A getValue() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Moka\Stub;
5
6
use Moka\Exception\InvalidArgumentException;
7
8
/**
9
 * Class AbstractStub
10
 * @package Moka\Stub
11
 */
12
abstract class AbstractStub implements StubInterface
13
{
14
    const REGEX_NAME = '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/';
15
16
    /**
17
     * @var string
18
     */
19
    protected $name;
20
21
    /**
22
     * @var mixed
23
     */
24
    protected $value;
25
26
    /**
27
     * AbstractStub constructor.
28
     * @param string $name
29
     * @param mixed $value
30
     *
31
     * @throws InvalidArgumentException
32
     */
33 103
    public function __construct(string $name, $value)
34
    {
35 103
        if (!preg_match(self::REGEX_NAME, $name)) {
36 2
            throw new InvalidArgumentException(
37 2
                sprintf(
38 2
                    'Name must be a valid variable or method name, "%s" given',
39 2
                    $name
40
                )
41
            );
42
        }
43
44 101
        $this->name = $name;
45 101
        $this->value = $value;
46
    }
47
48
    /**
49
     * @return string
50
     */
51 96
    public function getName(): string
52
    {
53 96
        return $this->name;
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59 96
    public function getValue()
60
    {
61 96
        return $this->value;
62
    }
63
}
64