Passed
Branch master (bf2098)
by Henri
02:32 queued 01:09
created

CheckTrait::check_parameter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 3
rs 10
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_numparams(array $route_loop, array $route_request)
42
    {
43
        return (count($route_loop) !== count($route_request));
44
    }
45
46
    protected function check_parameter(string $route_loop, string $route_request)
47
    {
48
        return !( substr($route_loop,0,1) === '{' ) and $route_loop !== $route_request;
49
    }
50
51
    protected function check_role()
52
    {
53
        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

53
        if(!array_key_exists('role', $this->/** @scrutinizer ignore-call */ getData()['POST'])){
Loading history...
54
            throw new Exception('O servidor não conseguiu identificar a finalidade deste formulário.');
55
        }
56
    }
57
58
    protected function hasProtocol(array $route, string $currentProtocol)
59
    {
60
        $protocols = ( is_array($route['protocol']) ) ? $route['protocol'] : [ $route['protocol'] ];
61
62
        foreach($protocols as $protocol){
63
            if($protocol !== $currentProtocol){
64
                continue;
65
            }
66
        }
67
    }
68
69
}