Passed
Branch master (3f372a)
by Henri
02:05 queued 52s
created

ControllerTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

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

3 Methods

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