Failed Conditions
Branch feature/refactoring-samurai (8cc7c1)
by Giuliano
03:47
created

SyntaxValidator::theme()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Maestriam\Samurai\Foundation;
4
5
class SyntaxValidator
6
{
7
    /**
8
     * Verifica se o padrão "vendor/theme"
9
     * foi preenchido corretamente
10
     *
11
     * @param  string $sentence
12
     * @return boolean
13
     */
14
    public function vendor(string $sentence) : bool
15
    {
16
        $pattern = "/^[a-z0-9_.-]{0,255}+\/[a-z0-9_.-]{0,255}\w+/"; 
17
18
        return (preg_match($pattern, $sentence)) ? true : false;
19
    }
20
21
    /**
22
     * Verifica se o padrão "Nome do author <email@domain>"
23
     * foi preenchido corretamente
24
     *
25
     * @param  string $sentence
26
     * @return boolean
27
     */
28
    public function author(string $sentence) : bool
29
    {
30
        $pattern = "/^[a-zA-Z0-9\s_.-]+ <[\w.-_]+@+[\w-]+.*(\.[a-z]{2,3})+>$/";
31
32
        return (preg_match($pattern, $sentence)) ? true : false;
33
    }
34
35
    /**
36
     * Verifica se o padrão para o nome do tema está correto.  
37
     * Retorna true se estiver correto.  
38
     *
39
     * @param  string $name
40
     * @return boolean
41
     */
42
    public function theme(string $name) : bool
43
    {
44
        $onlyValidChars = "/^[a-z0-9_.-]+$/";
45
        
46
        return (preg_match($onlyValidChars, $name)) ? true : false;
47
    }
48
    
49
    /**
50
     * Verifica se o padrão para o nome de uma diretiva está correto.  
51
     * Retorna true se estiver correto.  
52
     *
53
     * @param  string $name
54
     * @return boolean
55
     */
56
    public function directive(string $name) : bool
57
    {
58
        $startNumbers   = "/^[\d]/";
59
        $onlyValidChars = "/^[a-zA-Z0-9\/\-]+$/";
60
        
61
        if (preg_match($startNumbers, $name)) {
62
            return false;
63
        }
64
65
        if (! preg_match($onlyValidChars, $name)) {
66
            return false;
67
        }
68
        
69
        return true;
70
    }
71
    
72
    /**
73
     * Verifica se o tipo da diretiva é um tipo aceitável pelo sistema.  
74
     * Retorna true se estiver correto.  
75
     *
76
     * @param  string $type
77
     * @return boolean
78
     */
79
    public function type(string $type = null) : bool
80
    {   
81
        if (! $type) {
82
            return false;
83
        }
84
85
        $types = config('samurai.species');
86
87
        return (in_array($type, $types)) ? true : false;
88
    }
89
}
90