CookieSettings::getSettings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 3
cts 3
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace Limoncello\Application\Packages\Cookies;
4
5
/**
6
 * Copyright 2015-2020 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Limoncello\Contracts\Settings\Packages\CookieSettingsInterface;
22
use function assert;
23
use function is_bool;
24
use function is_string;
25
26
/**
27
 * @package Limoncello\Application
28
 */
29 1
class CookieSettings implements CookieSettingsInterface
30
{
31 1
    /**
32
     * @inheritdoc
33 1
     */
34 1
    final public function get(array $appConfig): array
35
    {
36 1
        $defaults = $this->getSettings();
37 1
38
        $path = $defaults[static::KEY_DEFAULT_PATH] ?? null;
39 1
        assert(is_string($path), 'Invalid default path.');
40 1
41
        $domain = $defaults[static::KEY_DEFAULT_DOMAIN] ?? null;
42 1
        assert(is_string($domain), 'Invalid default domain.');
43 1
44
        $isSecure = $defaults[static::KEY_DEFAULT_IS_SEND_ONLY_OVER_SECURE_CONNECTION] ?? null;
45 1
        assert(is_bool($isSecure), 'Invalid `secure` value.');
46 1
47
        $isHttpOnly = $defaults[static::KEY_DEFAULT_IS_ACCESSIBLE_ONLY_THROUGH_HTTP] ?? null;
48 1
        assert(is_bool($isHttpOnly), 'Invalid `httpOnly` value.');
49
50
        $isRaw = $defaults[static::KEY_DEFAULT_IS_RAW] ?? null;
51
        assert(is_bool($isRaw), 'Invalid Send Raw Cookies value.');
52
53
        return $defaults;
54 1
    }
55
56
    /**
57 1
     * @return array
58 1
     */
59 1
    protected function getSettings(): array
60 1
    {
61 1
        return [
62
            static::KEY_DEFAULT_PATH                                => '',
63
            static::KEY_DEFAULT_DOMAIN                              => '',
64
            static::KEY_DEFAULT_IS_SEND_ONLY_OVER_SECURE_CONNECTION => false,
65
            static::KEY_DEFAULT_IS_ACCESSIBLE_ONLY_THROUGH_HTTP     => true,
66
            static::KEY_DEFAULT_IS_RAW                              => false,
67
        ];
68
    }
69
}
70