Passed
Branch master (eeb79a)
by Henri
02:29 queued 01:14
created

CheckTrait   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 16

6 Methods

Rating   Name   Duplication   Size   Complexity  
A check_name() 0 3 2
A check_protocol() 0 4 2
A check_role() 0 4 2
A check_filtering() 0 9 4
A check_config() 0 4 2
A hasProtocol() 0 7 4
1
<?php
2
3
namespace HnrAzevedo\Router;
4
5
use Exception;
6
7
trait CheckTrait{
8
9
    protected function check_protocol(string $expected, string $current)
10
    {
11
        if($expected !== $current){
12
            throw new Exception('Page not found.',404);
13
        }
14
    }
15
16
    protected function check_name(string $route_name){
17
        if(!array_key_exists($route_name,$this->routers)){
18
            throw new Exception('Page not found.',404);
19
        }
20
    }
21
22
    protected function check_filtering(array $route)
23
    {
24
        $filters = (is_array($route['filters'])) ? $route['filters'] : [ $route['filters'] ];
25
26
        foreach($filters as $filter){
27
            if(is_null($filter)){
28
                continue;
29
            }
30
            $this->filter->filtering($filter);
31
        }
32
    }
33
34
    protected function check_config()
35
    {
36
        if(!defined('ROUTER_CONFIG')){
37
            throw new Exception("Information for loading routes has not been defined.");
38
        }
39
    }
40
41
    protected function check_role()
42
    {
43
        if(!array_key_exists('role', $this->getData()['POST'])){
0 ignored issues
show
Bug introduced by
It seems like getData() 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

43
        if(!array_key_exists('role', $this->/** @scrutinizer ignore-call */ getData()['POST'])){
Loading history...
44
            throw new Exception('O servidor não conseguiu identificar a finalidade deste formulário.');
45
        }
46
    }
47
48
    protected function hasProtocol(array $route, string $currentProtocol)
49
    {
50
        $protocols = ( is_array($route['protocol']) ) ? $route['protocol'] : [ $route['protocol'] ];
51
52
        foreach($protocols as $protocol){
53
            if($protocol !== $currentProtocol){
54
                parent::continue;
0 ignored issues
show
Bug introduced by
The constant HnrAzevedo\Router\CheckTrait::continue was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
55
            }
56
        }
57
    }
58
59
}