ComplexObjectGeneratorFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
namespace DBFaker\Generators;
3
4
use DBFaker\Helpers\SchemaHelper;
5
use Doctrine\DBAL\Schema\Column;
6
use Doctrine\DBAL\Schema\Table;
7
use Faker\Generator;
8
9
class ComplexObjectGeneratorFactory implements FakeDataGeneratorFactoryInterface
10
{
11
    /**
12
     * @var int|null
13
     */
14
    private $depth;
15
    /**
16
     * @var bool
17
     */
18
    private $toArray;
19
20
    /**
21
     * ComplexObjectGenerator constructor.
22
     * @param int|null $depth
23
     * @param bool $toArray
24
     */
25
    public function __construct(int $depth = null, bool $toArray = true)
26
    {
27
        $this->depth = $depth;
28
        $this->toArray = $toArray;
29
    }
30
31
    /**
32
     * @param Table $table
33
     * @param Column $column
34
     * @param SchemaHelper $schemaHelper
35
     * @return FakeDataGeneratorInterface
36
     */
37
    public function create(Table $table, Column $column, SchemaHelper $schemaHelper): FakeDataGeneratorInterface
38
    {
39
        $unique = $schemaHelper->isColumnPartOfUniqueIndex($table, $column);
40
        return new ComplexObjectGenerator($column, $this->depth, $this->toArray, $unique);
41
    }
42
}
43