Constant::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace WebnetFr\DatabaseAnonymizer\Generator;
4
5
use WebnetFr\DatabaseAnonymizer\Exception\InvalidConstantException;
6
7
/**
8
 * Generator that always return constant.
9
 *
10
 * @author Vlad Riabchenko <[email protected]>
11
 */
12
class Constant implements GeneratorInterface
13
{
14
    /**
15
     * Arbitrary constant value.
16
     *
17
     * @var mixed
18
     */
19
    private $constant;
20
21
    /**
22
     * @param $constant
23
     */
24
    public function __construct($constant)
25
    {
26
        if (null !== $constant && !\is_string($constant)) {
27
            throw new InvalidConstantException('Constant value must be null or string');
28
        }
29
30
        $this->constant = $constant;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function generate()
37
    {
38
        return $this->constant;
39
    }
40
}
41