Passed
Push — master ( 19098a...8d2d84 )
by Peter
02:39
created

PasswordGeneratorBootstrapper::getSecretLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Bootstrappers\Crypto;
6
7
use AbterPhp\Framework\Constant\Env;
8
use Hackzilla\PasswordGenerator\Generator\ComputerPasswordGenerator;
9
use Opulence\Ioc\Bootstrappers\Bootstrapper;
10
use Opulence\Ioc\Bootstrappers\ILazyBootstrapper;
11
use Opulence\Ioc\IContainer;
12
13
class PasswordGeneratorBootstrapper extends Bootstrapper implements ILazyBootstrapper
14
{
15
    /**
16
     * @return array
17
     */
18
    public function getBindings(): array
19
    {
20
        return [
21
            ComputerPasswordGenerator::class,
22
        ];
23
    }
24
25
    /**
26
     * @param IContainer $container
27
     *
28
     * @throws \Opulence\Ioc\IocException
29
     */
30
    public function registerBindings(IContainer $container)
31
    {
32
        $secretLength = $this->getSecretLength();
33
        $generator    = new ComputerPasswordGenerator();
34
35
        $generator
36
            ->setOptionValue(ComputerPasswordGenerator::OPTION_UPPER_CASE, true)
37
            ->setOptionValue(ComputerPasswordGenerator::OPTION_LOWER_CASE, true)
38
            ->setOptionValue(ComputerPasswordGenerator::OPTION_NUMBERS, true)
39
            ->setOptionValue(ComputerPasswordGenerator::OPTION_SYMBOLS, false)
40
            ->setOptionValue(ComputerPasswordGenerator::OPTION_LENGTH, $secretLength);
41
42
        $container->bindInstance(ComputerPasswordGenerator::class, $generator);
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    private function getSecretLength(): string
49
    {
50
        return getenv(Env::OAUTH2_SECRET_LENGTH);
51
    }
52
}
53