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

FcharsLogicValidator::validate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 3
rs 10
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