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

IdnDependencyTrait::initIdnFunctionExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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