Passed
Branch v2-dev (0ddf7c)
by Henri
10:02
created

OwnerTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 12
c 1
b 0
f 1
dl 0
loc 32
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A unsetRoute() 0 4 1
A loadIn() 0 5 1
A runIn() 0 9 2
A hasCurrentRoute() 0 4 2
1
<?php
2
3
namespace HnrAzevedo\Router;
4
5
trait OwnerTrait
6
{
7
8
    public function loadIn(string $name): RouterInterface
9
    {
10
        $this->hasRouteName($name);
0 ignored issues
show
Bug introduced by
It seems like hasRouteName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

10
        $this->/** @scrutinizer ignore-call */ 
11
               hasRouteName($name);
Loading history...
11
        $this->loaded = true;
0 ignored issues
show
Bug Best Practice introduced by
The property loaded does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
12
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type HnrAzevedo\Router\OwnerTrait which is incompatible with the type-hinted return HnrAzevedo\Router\RouterInterface.
Loading history...
13
    }
14
15
    public function runIn(string $name): RouterInterface
16
    {
17
        $this->hasRouteName($name);
18
19
        if(!$this->loaded){
20
            $this->loadIn($name);
21
        }
22
        
23
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type HnrAzevedo\Router\OwnerTrait which is incompatible with the type-hinted return HnrAzevedo\Router\RouterInterface.
Loading history...
24
    }
25
26
    public function hasCurrentRoute(): void
27
    {
28
        if(!isset($this->currentRoute)){
29
            throw new \RuntimeException('Route not yet loaded');
30
        }
31
    }
32
33
    public function unsetRoute($key): RouterInterface
34
    {
35
        unset($this->routes[$key]);
36
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type HnrAzevedo\Router\OwnerTrait which is incompatible with the type-hinted return HnrAzevedo\Router\RouterInterface.
Loading history...
37
    }
38
39
}