Passed
Pull Request — master (#661)
by Maxim
08:20
created

HttpConfig::getChunkSize()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 3
rs 10
c 0
b 0
f 0
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
     * @psalm-return positive-int
60
     */
61 2
    public function getChunkSize(): ?int
62
    {
63 2
        if (\is_null($this->config['chunkSize']) || (int) $this->config['chunkSize'] <= 0) {
64 2
            return null;
65
        }
66
67 1
        return (int) $this->config['chunkSize'];
68
    }
69
}
70