Passed
Push — master ( 9a2405...48cf72 )
by Zaahid
14:14
created

QuotedLiteralPart   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 94.12%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 15
c 1
b 0
f 0
dl 0
loc 29
ccs 16
cts 17
cp 0.9412
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B filterIgnoredSpaces() 0 20 10
1
<?php
2
/**
3
 * This file is part of the ZBateson\MailMimeParser project.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
6
 */
7
8
namespace ZBateson\MailMimeParser\Header\Part;
9
10
/**
11
 * A quoted literal header string part.  The value of the part is stripped of CR
12
 * and LF characters, and whitespace between two adjacent MimeTokens is removed.
13
 *
14
 * @author Zaahid Bateson
15
 */
16
class QuotedLiteralPart extends ContainerPart
17
{
18
    /**
19
     * Strips spaces found between two adjacent MimeToken parts.
20
     * Other whitespace is returned as-is.
21
     *
22
     * @param HeaderPart[] $parts
23
     * @return HeaderPart[]
24
     */
25 102
    protected function filterIgnoredSpaces(array $parts) : array
26
    {
27 102
        $filtered = \array_reduce(
28 102
            \array_keys($parts),
29 102
            function($carry, $key) use ($parts) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
30 102
                $cur = $parts[$key];
31 102
                $last = ($carry !== null) ? \end($carry) : null;
32 102
                $next = (count($parts) > $key + 1) ? $parts[$key + 1] : null;
33 102
                if ($last !== null && $next !== null && $cur->isSpace && (
34 102
                    $last->canIgnoreSpacesAfter
35 102
                    && $next->canIgnoreSpacesBefore
36 102
                    && $last instanceof MimeToken
37 102
                    && $next instanceof MimeToken
38
                )) {
39
                    return $carry;
40
                }
41 102
                return \array_merge($carry ?? [], [$cur]);
42 102
            }
43 102
        );
44 102
        return $filtered;
45
    }
46
}
47