Dictionary::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 8
ccs 2
cts 2
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
    public function __construct(private Collection $collection, ?Generator $generator = null)
14
    {
15
        if (!$generator instanceof Generator) {
16
            $generator = new Generator();
17
            $generator->addProvider($this);
18 3
        }
19
20 3
        parent::__construct($generator);
21
    }
22 3
23 3
    /**
24 3
     * @return mixed
25
     */
26
    public function dictionary(string $name)
27 3
    {
28 3
        return self::randomElement($this->collection[$name]->getKeys());
29
    }
30
}
31