Test Setup Failed
Push — master ( ecdc34...0769f8 )
by Gabriel
02:46 queued 11s
created

HasMatcherTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
wmc 2
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A matchRequest() 0 8 2
1
<?php
2
3
namespace Nip\Router\Router\Traits;
4
5
use \Symfony\Component\HttpFoundation\Request;
6
use Nip\Router\Route\Route;
7
use Psr\Http\Message\ServerRequestInterface;
8
9
/**
10
 * Trait HasMatcherTrait
11
 * @package Nip\Router\Router\Traits
12
 */
13
trait HasMatcherTrait
14
{
15
    /**
16
     * @param Request|ServerRequestInterface $request
17
     * @return array
18
     */
19 15
    public function matchRequest(Request $request)
20
    {
21 15
        $return = parent::matchRequest($request);
22 12
        if (isset($return['_route'])) {
23 12
            $this->setCurrent($this->getRoute($return['_route']));
0 ignored issues
show
Bug introduced by
It seems like getRoute() 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...
Bug introduced by
It seems like setCurrent() 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...
24
        }
25 12
        return $return;
26
    }
27
}
28