Conditions | 7 |
Paths | 8 |
Total Lines | 25 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 7.1429 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | 398 | public function __construct( |
|
22 | string $name, |
||
23 | DataFields $fields, |
||
24 | array $primaryKey = [], |
||
25 | bool $withoutPrimaryKey = false |
||
26 | ) { |
||
27 | 398 | if ('' === $name) { |
|
28 | throw new LogicException('The table name must not be empty'); |
||
29 | } |
||
30 | 398 | if (0 === count($fields)) { |
|
31 | 1 | throw new LogicException('The data fields map must not be empty'); |
|
32 | } |
||
33 | 397 | $primaryKey = array_unique(array_filter(array_map('trim', $primaryKey))); |
|
34 | 397 | if (0 === count($primaryKey) && ! $withoutPrimaryKey) { |
|
35 | 321 | $primaryKey = [$fields->getByPosition(0)->name()]; |
|
36 | } |
||
37 | 397 | foreach ($primaryKey as $primaryKeyName) { |
|
38 | 340 | if (! $fields->exists($primaryKeyName)) { |
|
39 | throw new LogicException('The primary key is not found in the data fields map'); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | 397 | $this->name = $name; |
|
|
|||
44 | 397 | $this->fields = $fields; |
|
45 | 397 | $this->primaryKey = $primaryKey; |
|
46 | } |
||
64 |