Passed
Push — master ( e47fbc...09d435 )
by Hirofumi
152:01 queued 116:37
created

NonRFCMimeGrammer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDefinition() 0 25 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Email\SwiftMailer;
5
6
use Swift_Mime_Grammar;
7
8
/**
9
 * @see https://gist.github.com/basuke/16ad5c07fba3f029e729
10
 */
11
class NonRFCMimeGrammer extends Swift_Mime_Grammar
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16 1
    public function getDefinition($name)
17
    {
18 1
        switch ($name) {
19
            case 'addr-spec':
20
                /** @noinspection PhpUnhandledExceptionInspection */
21 1
                $spec = parent::getDefinition($name);
22
                $fuzzy_domains = array(
23 1
                    'docomo\.ne\.jp',
24
                    'ezweb\.ne\.jp',
25
                );
26 1
                $atext = $this->getDefinition('atext');
27 1
                $CFWS = $this->getDefinition('CFWS');
28 1
                $invalid_dot_atom_text = '(?:\.*'. $atext. '+'. '(\.+'. $atext. '+)*\.*)';
29 1
                $invalid_dot_atom = '(?:'. $CFWS. '?'. $invalid_dot_atom_text. '+'. $CFWS. '?)';
30 1
                $quoted_string = $this->getDefinition('quoted-string');
31 1
                $local_part = '(?:'. $invalid_dot_atom. '|'. $quoted_string. ')';
32 1
                $domain_part = '(?:'. implode('|', $fuzzy_domains). ')';
33 1
                $spec = '(?:'. $spec. '|'. $local_part. '@'. $domain_part. ')';
34
35 1
                return $spec;
36
            default:
37
                /** @noinspection PhpUnhandledExceptionInspection */
38 1
                return parent::getDefinition($name);
39
        }
40
    }
41
}