BaseCoreData::getGlobalConfiguratorsFromData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
crap 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace Limoncello\Core\Application;
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 FastRoute\DataGenerator;
22
use FastRoute\Dispatcher;
23
use Limoncello\Common\Reflection\ClassIsTrait;
24
use Limoncello\Core\Contracts\CoreDataInterface;
25
use function assert;
26
use function array_key_exists;
27
28
/**
29
 * @package Limoncello\Core
30
 */
31
abstract class BaseCoreData implements CoreDataInterface
32
{
33
    use ClassIsTrait;
34
35
    /**
36
     * @param array $data
37
     *
38
     * @return array
39
     */
40 8
    public static function getRouterParametersFromData(array $data): array
41
    {
42 8
        assert(array_key_exists(self::KEY_ROUTER_PARAMS, $data));
43 8
        $result = $data[self::KEY_ROUTER_PARAMS];
44 8
        assert(empty($result) === false);
45
46 8
        return $result;
47
    }
48
49
    /**
50
     * @param array $data
51
     *
52
     * @return string
53
     */
54 8 View Code Duplication
    public static function getGeneratorFromParametersData(array $data): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56 8
        assert(array_key_exists(self::KEY_ROUTER_PARAMS__GENERATOR, $data));
57 8
        $result = $data[self::KEY_ROUTER_PARAMS__GENERATOR];
58 8
        assert(empty($result) === false);
59 8
        assert(static::classImplements($result, DataGenerator::class));
60
61 8
        return $result;
62
    }
63
64
    /**
65
     * @param array $data
66
     *
67
     * @return string
68
     */
69 8 View Code Duplication
    public static function getDispatcherFromParametersData(array $data): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71 8
        assert(array_key_exists(self::KEY_ROUTER_PARAMS__DISPATCHER, $data));
72 8
        $result = $data[self::KEY_ROUTER_PARAMS__DISPATCHER];
73 8
        assert(empty($result) === false);
74 8
        assert(static::classImplements($result, Dispatcher::class));
75
76 8
        return $result;
77
    }
78
79
    /**
80
     * @param array $data
81
     *
82
     * @return array
83
     */
84 8
    public static function getRoutesDataFromData(array $data): array
85
    {
86 8
        assert(array_key_exists(self::KEY_ROUTES_DATA, $data));
87 8
        $result = $data[self::KEY_ROUTES_DATA];
88
89 8
        return $result;
90
    }
91
92
    /**
93
     * @param array $data
94
     *
95
     * @return callable[]
96
     */
97 8
    public static function getGlobalConfiguratorsFromData(array $data): array
98
    {
99 8
        assert(array_key_exists(self::KEY_GLOBAL_CONTAINER_CONFIGURATORS, $data));
100 8
        $result = $data[self::KEY_GLOBAL_CONTAINER_CONFIGURATORS];
101
102 8
        return $result;
103
    }
104
105
    /**
106
     * @param array $data
107
     *
108
     * @return array
109
     */
110 8
    public static function getGlobalMiddlewareFromData(array $data): array
111
    {
112 8
        assert(array_key_exists(self::KEY_GLOBAL_MIDDLEWARE, $data));
113 8
        $result = $data[self::KEY_GLOBAL_MIDDLEWARE];
114
115 8
        return $result;
116
    }
117
}
118