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

FcharsLogicValidator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 4 3
A __construct() 0 3 1
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\Validations\ValidationInterface;
15
16
class FcharsLogicValidator implements ValidationInterface
17
{
18
    private SchemaAttributeInterface $property;
19
20 188
    public function __construct(SchemaAttributeInterface $property)
21
    {
22 188
        $this->property = $property;
23 188
    }
24
25 188
    public function validate(): void
26
    {
27 188
        if ($this->property->fchars() && !$this->property->isFk()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->property->fchars() of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
28 5
            throw new InvalidSchemaAttributeException('Only property with Foreing Key allow fchars option');
29
        }
30 183
    }
31
}
32