Completed
Push — develop ( 027f5e...8e896a )
by Neomerx
02:11
created

CommandSettings   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 33
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 namespace Limoncello\Application\Packages\Commands;
2
3
/**
4
 * Copyright 2015-2018 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Limoncello\Contracts\Settings\Packages\CommandSettingsInterface;
20
use Limoncello\Contracts\Settings\SettingsInterface;
21
22
/**
23
 * @package Limoncello\Application
24
 */
25
class CommandSettings implements SettingsInterface, CommandSettingsInterface
26
{
27
    /**
28
     * @inheritdoc
29
     */
30
    final public function get(array $appConfig): array
31
    {
32
        $defaults = $this->getSettings();
33
34
        $userIdentity   = $defaults[static::KEY_IMPERSONATE_AS_USER_IDENTITY] ?? null;
35
        $userProperties = $defaults[static::KEY_IMPERSONATE_WITH_USER_PROPERTIES] ?? null;
36
37
        assert(
38
            $userIdentity === null || (is_string($userIdentity) === true && empty($userIdentity) === false) ||
39
            is_int($userIdentity) === true,
40
            'Invalid Impersonation User Identity.'
41
        );
42
        assert(is_array($userProperties) === true, 'Invalid Impersonation User Properties.');
43
44
        return $defaults;
45
    }
46
47
    /**
48
     * @return array
49
     */
50
    protected function getSettings(): array
51
    {
52
        return [
53
            static::KEY_IMPERSONATE_AS_USER_IDENTITY     => null,
54
            static::KEY_IMPERSONATE_WITH_USER_PROPERTIES => [],
55
        ];
56
    }
57
}
58