Passed
Pull Request — master (#149)
by Pierre
03:06
created

Dictionary   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 25
ccs 9
cts 9
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A dictionary() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Knp\DictionaryBundle\Faker\Provider;
6
7
use Faker\Generator;
8
use Faker\Provider\Base;
9
use Knp\DictionaryBundle\Dictionary\Collection;
10
11
final class Dictionary extends Base
12
{
13
    /**
14
     * @var Collection
15
     */
16
    private $dictionaries;
17
18 3
    public function __construct(Collection $dictionaries, Generator $generator = null)
19
    {
20 3
        $this->dictionaries = $dictionaries;
21
22 3
        if (null === $generator) {
23 3
            $generator = new Generator();
24 3
            $generator->addProvider($this);
25
        }
26
27 3
        parent::__construct($generator);
28 3
    }
29
30
    /**
31
     * @return mixed
32
     */
33 2
    public function dictionary(string $name)
34
    {
35 2
        return self::randomElement($this->dictionaries[$name]->getKeys());
36
    }
37
}
38