RegExFakerClass   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 42
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B process() 0 24 6
1
<?php
2
/**
3
 * This file is part of the Fakerino package.
4
 *
5
 * (c) Nicola Pietroluongo <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fakerino\Core\FakeHandler;
12
13
use Fakerino\Core\RegEx\RegExGeneratorInterface;
14
15
/**
16
 * Class RegExFakerClass,
17
 * processes the request of a regular expression.
18
 *
19
 * @author Nicola Pietroluongo <[email protected]>
20
 */
21
final class RegExFakerClass extends Handler
22
{
23
    private $regexGenerator;
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param RegExGeneratorInterface $regexGenerator
29
     */
30 27
    public function __construct(RegExGeneratorInterface $regexGenerator)
31
    {
32 27
        $this->regexGenerator = $regexGenerator;
33 27
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    protected function process($data)
39
    {
40 3
        $elementName = $data->getName();
41 3
        $options = $data->getOptions();
42 3
        $expr = null;
43 3
        if ($elementName[0] == '/') {
44 1
            $expr = $elementName;
45 1
        }
46 3
        if ($options !== null && is_string($options)) {
47 1
            if ($options[0] == '/') {
48 1
                $expr = $options;
49 1
            }
50 1
        }
51 3
        if ($expr !== null) {
52
            $options = array(
53 2
                'regexgenerator' => $this->regexGenerator,
54 2
                'expression' => $expr,
55 2
            );
56
57 2
            return $this->getOutput('Fakerino\\FakeData\\Core\\RegExFake', $options);
58
        }
59
60 1
        return;
61
    }
62
}