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

ControllerTrait::checkControllExist()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
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
}