Completed
Pull Request — master (#18)
by Frederik
01:37
created

CanonicalizeHeaderRelaxed   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 22
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canonicalize() 0 7 1
A name() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Genkgo\Mail\Dkim;
5
6
use Genkgo\Mail\HeaderInterface;
7
8
final class CanonicalizeHeaderRelaxed implements CanonicalizeHeaderInterface
9
{
10
    /**
11
     * @param HeaderInterface $header
12
     * @return string
13
     */
14 2
    public function canonicalize(HeaderInterface $header): string
15
    {
16 2
        $name = strtolower(trim((string)$header->getName()));
17 2
        $value = str_replace("\r\n", '', (string)$header->getValue());
18 2
        $value = preg_replace("/[ \t][ \t]+/", ' ', $value);
19 2
        return $name . ':' . trim($value);
20
    }
21
22
    /**
23
     * @return string
24
     */
25 1
    public function name(): string
26
    {
27 1
        return 'relaxed';
28
    }
29
}