PatternString::matches()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
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 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of forecast.it.fill project.
7
 * (c) Patrick Jaja <[email protected]>
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Architecture\Analyzer;
13
14
use Arkitect\Analyzer\PatternString as ArkitectPatternString;
15
16
class PatternString extends ArkitectPatternString
17
{
18
    private string $value;
19
20
    public function __construct(string $value)
21
    {
22
        parent::__construct($value);
23
        $this->value = $value;
24
    }
25
26
    public function matches(string $pattern): bool
27
    {
28
        if (! parent::matches($pattern)) {
29
            return 1 === preg_match($pattern, $this->value);
30
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 28 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...
31
    }
32
}
33