Passed
Branch master (c64b1d)
by Henri
01:38
created

ControllerTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkControllExist() 0 7 2
A checkControllMethod() 0 8 2
A checkControllSettable() 0 6 2
1
<?php
2
3
namespace HnrAzevedo\Router;
4
5
use Exception;
6
7
trait ControllerTrait{
8
9
    protected function checkControllSettable(string $controll)
10
    {
11
        if(count(explode(':',$controll)) != 2){
12
            throw new Exception("Controller {$controll} badly set.");
13
        }
14
        return $this;
15
    }
16
17
    protected function checkControllExist(string $controll)
18
    {
19
        $controllname = ucfirst(explode(':',$controll)[0]);
20
        if(!class_exists($controllname)){
21
            throw new Exception("No controller {$controllname} found.");
22
        }
23
        return $this;
24
    }
25
26
    protected function checkControllMethod(string $controll)
27
    {
28
        $controllname = ucfirst(explode(':',$controll)[0]);
29
        $method = explode(':',$controll)[1];
30
        if(!method_exists($controllname, $method)){
31
            throw new Exception("No method {$method} found for {$controllname}.");
32
        }
33
        return $this;
34
    }
35
36
}