Passed
Push — develop ( 5c61b7...a7d981 )
by Freddie
03:02
created

AiLogicValidator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A validate() 0 9 4
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of FlexPHP.
4
 *
5
 * (c) Freddie Gar <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace FlexPHP\Schema\Validators\Logics;
11
12
use FlexPHP\Schema\Exception\InvalidSchemaAttributeException;
13
use FlexPHP\Schema\SchemaAttributeInterface;
14
use FlexPHP\Schema\Traits\AttributeHelperTrait;
15
use FlexPHP\Schema\Validations\ValidationInterface;
16
17
class AiLogicValidator implements ValidationInterface
18
{
19
    use AttributeHelperTrait;
20
21
    private SchemaAttributeInterface $property;
22
23 248
    public function __construct(SchemaAttributeInterface $property)
24
    {
25 248
        $this->property = $property;
26 248
    }
27
28 248
    public function validate(): void
29
    {
30 248
        if ($this->property->isAi()) {
31 19
            if (!$this->property->isPk()) {
32 1
                throw new InvalidSchemaAttributeException('Autoincrement must be Primary Key too.');
33
            }
34
35 18
            if (!$this->isInt($this->property)) {
36 1
                throw new InvalidSchemaAttributeException('Autoincrement must be numeric.');
37
            }
38
        }
39 246
    }
40
}
41