Test Setup Failed
Push — master ( 1d7e99...ecdc34 )
by Gabriel
05:18 queued 10s
created

RouterTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerRouter() 0 12 1
A newRouter() 0 10 2
1
<?php
2
3
namespace Nip\Router\ServiceProvider\Traits;
4
5
use Nip\Request;
6
use Nip\Router\RequestContext;
7
use Nip\Router\Router;
8
use Symfony\Component\Routing\RouterInterface;
9
10
/**
11
 * Trait RouterTrait
12
 * @package Nip\Router\ServiceProvider\Traits
13
 */
14
trait RouterTrait
15
{
16 2
    public function registerRouter()
17
    {
18
        $this->getContainer()->share('router', function () {
0 ignored issues
show
Bug introduced by
It seems like getContainer() 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...
19 2
            return $this->newRouter();
20 2
        });
21
22 2
        $this->getContainer()->add(RouterInterface::class, Router::class);
0 ignored issues
show
Bug introduced by
It seems like getContainer() 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...
23
24
        $this->getContainer()->share(Router::class, function () {
0 ignored issues
show
Bug introduced by
It seems like getContainer() 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...
25
            return $this->getContainer()->get('router');
0 ignored issues
show
Bug introduced by
It seems like getContainer() 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...
26 2
        });
27 2
    }
28
29
    /**
30
     * @return Router
31
     */
32 2
    public function newRouter()
33
    {
34
        /** @var Router $router */
35 2
        $router = $this->getContainer()->get(RouterInterface::class);
0 ignored issues
show
Bug introduced by
It seems like getContainer() 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...
36 2
        $request = Request::instance();
37 2
        if ($request instanceof Request) {
38 2
            $router->setContext((new RequestContext())->fromRequest($request));
39
        }
40 2
        return $router;
41
    }
42
}
43