Completed
Pull Request — master (#18)
by Frederik
03:05
created

CanonicalizeHeaderRelaxed   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

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
    public function canonicalize(HeaderInterface $header): string
15
    {
16
        $name = strtolower(trim((string)$header->getName()));
17
        $value = str_replace("\r\n", '', (string)$header->getValue());
18
        $value = preg_replace("/[ \t][ \t]+/", ' ', $value);
19
        return $name . ':' . trim($value);
20
    }
21
22
    /**
23
     * @return string
24
     */
25
    public static function name(): string
26
    {
27
        return 'relaxed';
28
    }
29
}