HeaderTrimmer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A trim() 0 10 2
A trimHeaderValues() 0 9 2
A trimHeaderValue() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Furious\Psr7\Header;
6
7
use function trim;
8
9
final class HeaderTrimmer
10
{
11
    public function trim($values): array
12
    {
13
        if (!is_array($values)) {
14
            $stringValues = (string) $values;
15
            $trimmedValues = $this->trimHeaderValue($stringValues);
16
            return [$trimmedValues];
17
        }
18
19
        return $this->trimHeaderValues($values);
20
    }
21
22
    private function trimHeaderValues(array $values): array
23
    {
24
        $trimmedValues = [];
25
        foreach ($values as $value) {
26
            $trimmedValues[] = $this->trimHeaderValue((string) $value);
27
        }
28
29
        return $trimmedValues;
30
    }
31
32
    private function trimHeaderValue(string $value): string
33
    {
34
        return trim($value, " \t");
35
    }
36
}