Passed
Push — master ( 52d18d...80d494 )
by Patrick
10:33
created

PatternString::matches()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 2
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 5
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Architecture\Analyzer;
5
6
use Arkitect\Analyzer\PatternString as ArkitectPatternString;
7
8
class PatternString extends ArkitectPatternString
9
{
10
    private string $value;
11
12
    public function __construct(string $value)
13
    {
14
        parent::__construct($value);
15
        $this->value = $value;
16
    }
17
18
    public function matches(string $pattern): bool
19
    {
20
        if (!parent::matches($pattern))
21
        {
22
            return preg_match($pattern, $this->value) === 1;
23
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 20 is false. This is incompatible with the type-hinted return boolean. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
24
    }
25
}
26