Passed
Pull Request — master (#209)
by
unknown
02:29
created

IdnDependencyTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A idnFunctionRequired() 0 4 3
A initIdnFunctionExists() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Rule;
6
7
use RuntimeException;
8
9
trait IdnDependencyTrait
10
{
11
    /**
12
     * @var bool|null A separate property is used for easier testing.
13
     */
14
    private ?bool $idnFunctionExists = null;
15
16 123
    private function initIdnFunctionExists(): void
17
    {
18 123
        $this->idnFunctionExists = function_exists('idn_to_ascii');
19
    }
20
21
    /**
22
     * @throws RuntimeException
23
     */
24 126
    private function idnFunctionRequired(): void
25
    {
26 126
        if ($this->enableIDN && !$this->idnFunctionExists) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->idnFunctionExists of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
27 2
            throw new RuntimeException('In order to use IDN validation intl extension must be installed and enabled.');
28
        }
29
    }
30
}
31