Passed
Pull Request — master (#661)
by Maxim
07:57
created

HttpConfig   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 49
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getBasePath() 0 3 1
A getBaseHeaders() 0 3 1
A getMiddleware() 0 3 1
A getChunkSize() 0 7 3
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Http\Config;
13
14
use Spiral\Core\Container\Autowire;
15
use Spiral\Core\InjectableConfig;
16
17
final class HttpConfig extends InjectableConfig
18
{
19
    public const CONFIG = 'http';
20
21
    /**
22
     * @var array
23
     */
24
    protected $config = [
25
        'basePath'   => '/',
26
        'headers'    => [
27
            'Content-Type' => 'text/html; charset=UTF-8',
28
        ],
29
        'middleware' => [],
30
        'chunkSize' => null,
31
    ];
32
33 9
    public function getBasePath(): string
34
    {
35 9
        return $this->config['basePath'];
36
    }
37
38
    /**
39
     * Initial set of headers.
40
     */
41 154
    public function getBaseHeaders(): array
42
    {
43 154
        return $this->config['headers'];
44
    }
45
46
    /**
47
     * Initial middleware set.
48
     *
49
     * @return array|Autowire[]
50
     */
51 129
    public function getMiddleware(): array
52
    {
53 129
        return $this->config['middleware'] ?? $this->config['middlewares'];
54
    }
55
56
    /**
57
     * If chunkSize isn't provided - using default values
58
     */
59 2
    public function getChunkSize(): ?int
60
    {
61 2
        if (\is_null($this->config['chunkSize']) || (int) $this->config['chunkSize'] < 0) {
62 2
            return null;
63
        }
64
65 1
        return (int) $this->config['chunkSize'];
66
    }
67
}
68