HeaderTrimmer::trim()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 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
}