HasherContainerConfigurator::configureContainer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 4
cts 4
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace Limoncello\Crypt\Package;
4
5
/**
6
 * Copyright 2015-2019 [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\Application\ContainerConfiguratorInterface;
22
use Limoncello\Contracts\Container\ContainerInterface as LimoncelloContainerInterface;
23
use Limoncello\Contracts\Settings\SettingsProviderInterface;
24
use Limoncello\Crypt\Contracts\HasherInterface;
25
use Limoncello\Crypt\Hasher;
26
use Psr\Container\ContainerInterface as PsrContainerInterface;
27
use Limoncello\Crypt\Package\HasherSettings as C;
28
29
/**
30
 * @package Limoncello\Crypt
31
 */
32
class HasherContainerConfigurator implements ContainerConfiguratorInterface
33
{
34
    /** @var callable */
35
    const CONFIGURATOR = [self::class, self::CONTAINER_METHOD_NAME];
36
37
    /**
38
     * @inheritdoc
39
     */
40 1
    public static function configureContainer(LimoncelloContainerInterface $container): void
41
    {
42
        $container[HasherInterface::class] = function (PsrContainerInterface $container): HasherInterface {
43 1
            $settings = $container->get(SettingsProviderInterface::class)->get(C::class);
44 1
            $hasher   = new Hasher($settings[C::KEY_ALGORITHM], $settings[C::KEY_COST]);
45
46 1
            return $hasher;
47
        };
48
    }
49
}
50