CommandSettings   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 33
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 16 4
A getSettings() 0 7 1
1
<?php declare(strict_types=1);
2
3
namespace Limoncello\Application\Packages\Commands;
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\CommandSettingsInterface;
22
use Limoncello\Contracts\Settings\SettingsInterface;
23
use function assert;
24
use function is_array;
25
use function is_int;
26
use function is_string;
27
28
/**
29
 * @package Limoncello\Application
30 1
 */
31
class CommandSettings implements SettingsInterface, CommandSettingsInterface
32 1
{
33
    /**
34 1
     * @inheritdoc
35 1
     */
36
    final public function get(array $appConfig): array
37 1
    {
38 1
        $defaults = $this->getSettings();
39 1
40 1
        $userIdentity   = $defaults[static::KEY_IMPERSONATE_AS_USER_IDENTITY] ?? null;
41
        $userProperties = $defaults[static::KEY_IMPERSONATE_WITH_USER_PROPERTIES] ?? null;
42 1
43
        assert(
44 1
            $userIdentity === null || (is_string($userIdentity) === true && empty($userIdentity) === false) ||
45
            is_int($userIdentity) === true,
46
            'Invalid Impersonation User Identity.'
47
        );
48
        assert(is_array($userProperties) === true, 'Invalid Impersonation User Properties.');
49
50 1
        return $defaults;
51
    }
52
53 1
    /**
54 1
     * @return array
55
     */
56
    protected function getSettings(): array
57
    {
58
        return [
59
            static::KEY_IMPERSONATE_AS_USER_IDENTITY     => null,
60
            static::KEY_IMPERSONATE_WITH_USER_PROPERTIES => [],
61
        ];
62
    }
63
}
64