CorsContainerConfigurator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 29
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A configureContainer() 0 17 3
1
<?php declare(strict_types=1);
2
3
namespace Limoncello\Application\Packages\Cors;
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\Application\Packages\Cors\CorsSettings as C;
22
use Limoncello\Contracts\Application\ContainerConfiguratorInterface;
23
use Limoncello\Contracts\Container\ContainerInterface as LimoncelloContainerInterface;
24
use Limoncello\Contracts\Settings\SettingsProviderInterface;
25
use Neomerx\Cors\Analyzer;
26
use Neomerx\Cors\Contracts\AnalyzerInterface;
27
use Neomerx\Cors\Strategies\Settings;
28
use Psr\Container\ContainerInterface as PsrContainerInterface;
29
use Psr\Log\LoggerInterface;
30
31
/**
32
 * @package Limoncello\Application
33
 */
34
class CorsContainerConfigurator implements ContainerConfiguratorInterface
35
{
36
    /** @var callable */
37
    const CONFIGURATOR = [self::class, self::CONTAINER_METHOD_NAME];
38
39
    /**
40
     * @inheritdoc
41
     *
42 1
     * @SuppressWarnings(PHPMD.StaticAccess)
43
     * @SuppressWarnings(PHPMD.UndefinedVariable)
44
     */
45 1
    public static function configureContainer(LimoncelloContainerInterface $container): void
46
    {
47 1
        $container[AnalyzerInterface::class] = function (PsrContainerInterface $container) {
48
            $settingsProvider = $container->get(SettingsProviderInterface::class);
49 1
50
            [$corsSettings, $isLogEnabled] = $settingsProvider->get(C::class);
0 ignored issues
show
Bug introduced by
The variable $corsSettings does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $isLogEnabled does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
51 1
52 1
            $analyzer = Analyzer::instance((new Settings())->setData($corsSettings));
53 1
54
            if ($isLogEnabled === true && $container->has(LoggerInterface::class)) {
55
                $logger = $container->get(LoggerInterface::class);
56 1
                $analyzer->setLogger($logger);
57
            }
58
59
            return $analyzer;
60
        };
61
    }
62
}
63