Completed
Push — master ( c80620...0cd8d9 )
by Martijn
03:25
created

Rfc4408   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 89
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 85 1
1
<?php /** @noinspection PhpUndefinedFieldInspection */
2
3
/**
4
 * RFC 4408 - Sender Policy Framework (SPF) for Authorizing Use of Domains in E-Mail, Version 1
5
 *
6
 * Updated by RFC 6652
7
 * Obsoleted by RFC 7208
8
 *
9
 * @see https://tools.ietf.org/html/rfc4408
10
 * @package Vanderlee\Comprehend\Library
11
 */
12
13
namespace Vanderlee\Comprehend\Library;
14
15
use Vanderlee\Comprehend\builder\AbstractRuleset;
16
use Vanderlee\Comprehend\Parser\Parser;
17
use Vanderlee\Comprehend\Parser\Terminal\Integer;
18
19
require_once 'functions.php';
20
21
/**
22
 * Class Rfc4408
23
 *
24
 * ABNF in official RFC specs does not take into account left hand recursion issues.
25
 * Instances are fixed manually where appropriate.
26
 *
27
 * @property-read Parser record Complete SPF record
28
 * @property-read Parser version SPF version tag
29
 *
30
 * @package Vanderlee\Comprehend\Library
31
 */
32
class Rfc4408 extends AbstractRuleset
33
{
34
    protected static $name = 'Rfc4408';
35
36
    public function __construct($overwrites = [])
37
    {
38
        $abnf = new Rfc4234;
0 ignored issues
show
Bug introduced by
The type Vanderlee\Comprehend\Library\Rfc4234 was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
40
        $ipv6 = new Rfc3513;
41
42
        /*
43
         * Normal rules
44
         */
45
        $rules = [
46
            // 4.5. Selecting Records
47
            'record'           => [$this->version, $this->terms, $this->SP],
0 ignored issues
show
Bug Best Practice introduced by
The property SP does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property terms does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
48
            'version'          => 'v=spf1',
49
50
            // 4.6.1. Term Evaluation
51
            'terms'            => star([plus($abnf->SP), c($this->directive, $this->modifier)]),
0 ignored issues
show
Bug Best Practice introduced by
The property directive does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property modifier does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
52
            'directive'        => [opt($this->qualifier), $this->mechanism],
0 ignored issues
show
Bug Best Practice introduced by
The property mechanism does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property qualifier does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
53
            'qualifier'        => set('+-?~'),
54
            'mechanism'        => c($this->all, $this->include, $this->A, $this->MX, $this->PTR, $this->IP4, $this->IP6,
0 ignored issues
show
Bug Best Practice introduced by
The property MX does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property IP4 does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property A does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property all does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property IP6 does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property PTR does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property include does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
55
                $this->exists), // @todo order?
0 ignored issues
show
Bug Best Practice introduced by
The property exists does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
56
            'modifier'         => c($this->redirect, $this->explanation, $this->unknown_modifier),
0 ignored issues
show
Bug Best Practice introduced by
The property explanation does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property unknown_modifier does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property redirect does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
57
            'unknown_modifier' => [$this->name, '=', $this->macro_string],
0 ignored issues
show
Bug Best Practice introduced by
The property macro_string does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
58
            'name'             => [$abnf->ALPHA, star(c($abnf->ALPHA, $abnf->DIGIT, '-', '_', '.'))],
59
60
            // 5.1. "all"
61
            'all'              => 'all',
62
63
            // 5.2. "include"
64
            'include'          => ['include', ':', $this->domain_spec],
0 ignored issues
show
Bug Best Practice introduced by
The property domain_spec does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
65
66
            // 5.3. "a"
67
            'A'                => ['a', opt(s(':', $this->domain_spec)), opt($this->dual_cidr_length)],
0 ignored issues
show
Bug Best Practice introduced by
The property dual_cidr_length does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
68
69
            // 5.4. "mx"
70
            'MX'               => ['mx', opt(s(':', $this->domain_spec)), opt($this->dual_cidr_length)],
71
72
            // 5.5. "ptr"
73
            'PTR'              => ['ptr', ':', $this->domain_spec],
74
75
            // 5.6. "ip4" and "ip6"
76
            'IP4'              => ['ip4', ':', $this->ip4_network, opt($this->ip4_cidr_length)],
0 ignored issues
show
Bug Best Practice introduced by
The property ip4_network does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property ip4_cidr_length does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
77
            'IP6'              => ['ip6', ':', ":", $this->ip6_network, opt($this->ip6_cidr_length)],
0 ignored issues
show
Bug Best Practice introduced by
The property ip6_cidr_length does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property ip6_network does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
78
            'ip4_cidr_length'  => ['/', plus($abnf->DIGIT)],
79
            'ip6_cidr_length'  => ['/', plus($abnf->DIGIT)],
80
            'dual_cidr_length' => [opt($this->ip4_cidr_length), opt(['/', $this->ip6_cidr_length])],
81
            'ip4_network'      => [$this->qnum, '.', $this->qnum, '.', $this->qnum, '.', $this->qnum],
0 ignored issues
show
Bug Best Practice introduced by
The property qnum does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
82
            'qnum'             => new Integer(0, 255),
83
            'ip6_network'      => $ipv6->ipv6_address,
84
85
            // 5.7. "exists"
86
            'exists'           => ['exists', ':', $this->domain_spec],
87
88
            // 6.1. redirect: Redirected Query
89
            'redirect'         => ['redirect', '=', $this->domain_spec],
90
91
            // 6.2. exp: Explanation
92
            'explanation'      => ['exp', '=', $this->domain_spec],
93
94
            // 8. Macros
95
            'domain_spec'      => [$this->macro_string, $this->domain_end],
0 ignored issues
show
Bug Best Practice introduced by
The property domain_end does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
96
            'domain_end'       => c(['.', $this->toplabel, opt('.')], $this->macro_expand),
0 ignored issues
show
Bug Best Practice introduced by
The property toplabel does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property macro_expand does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
97
            'toplabel'         => c(
98
                [star($this->alphanum), $abnf->ALPHA, star($this->alphanum)],
0 ignored issues
show
Bug Best Practice introduced by
The property alphanum does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
99
                [plus($this->alphanum), '=', star(c($this->alphanum, '-')), $this->alphanum]
100
            ), // LDH rule plus additional TLD restrictions (see [RFC3696], Section 2) @todo Read & implement
101
            'alphanum'         => c($abnf->ALPHA, $abnf->DIGIT),
102
            'explain_string'   => star(c($this->macro_string, $abnf->SP)),
103
            'macro_string'     => star(c($this->macro_expand, $this->macro_literal)),
0 ignored issues
show
Bug Best Practice introduced by
The property macro_literal does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
104
            'macro_expand'     => c(
105
                ['%{', $this->macro_letter, $this->transformers, star($this->delimiter), '}'],
0 ignored issues
show
Bug Best Practice introduced by
The property transformers does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property macro_letter does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property delimiter does not exist on Vanderlee\Comprehend\Library\Rfc4408. Since you implemented __get, consider adding a @property annotation.
Loading history...
106
                '%%', '%_', '%-'
107
            ),
108
            'macro_literal'    => c(range(0x21, 0x24), range(0x26, 0x7E)),
109
            'macro_letter'     => set('slodiphcrt'),
110
            'transformers'     => [star($abnf->DIGIT), opt('r')],
111
            'delimiter'        => set('.-+,/_='),
112
113
            // 7. The Received-SPF Header Field
114
            // Implement as separate ruleset?
115
            // Does it conflict with the record definition?
116
117
            self::DEFAULT => $this->record,
118
        ];
119
120
        parent::__construct(array_merge($rules, $overwrites));
121
    }
122
}