Test Setup Failed
Push — master ( 7450ca...e4bb3e )
by Gabriel
05:50 queued 15s
created

HasMatchTrait::match()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
ccs 0
cts 8
cp 0
crap 12
1
<?php
2
3
namespace Nip\Router\Route\Traits;
4
5
/**
6
 * Trait HasMatchTrait
7
 * @package Nip\Router\Route\Traits
8
 */
9
trait HasMatchTrait
10
{
11
12
    /**
13
     * @param $uri
14
     * @return bool
15
     */
16
    public function match($uri)
17
    {
18
        $this->uri = $uri;
0 ignored issues
show
Bug introduced by
The property uri does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
        if ($this->domainCheck()) {
20
            $return = $this->getParser()->match($uri);
0 ignored issues
show
Bug introduced by
It seems like getParser() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
21
            if ($return === true) {
22
                $this->postMatch();
23
            }
24
25
            return $return;
26
        }
27
28
        return false;
29
    }
30
31
    /**
32
     * @return bool
33
     */
34
    public function domainCheck()
35
    {
36
        return true;
37
    }
38
39
    public function postMatch()
40
    {
41
    }
42
}
43