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

Dictionary::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 10
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