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

NonRFCMimeGrammer::getDefinition()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2.0011

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 25
ccs 14
cts 15
cp 0.9333
crap 2.0011
rs 9.52
c 0
b 0
f 0
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
}