Completed
Push — master ( 178a08...5c0b6f )
by Oleg
05:22
created

PasswordHydratorFactory::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlowServer\Authentication\Factory;
5
6
use Interop\Container\ContainerInterface;
7
use SlayerBirden\DataFlowServer\Authentication\Hydrator\Strategy\HashStrategy;
8
use SlayerBirden\DataFlowServer\Doctrine\Hydrator\Strategy\NestedEntityStrategy;
9
use Zend\Hydrator\ClassMethods;
10
use Zend\Hydrator\NamingStrategy\MapNamingStrategy;
11
use Zend\Hydrator\Strategy\BooleanStrategy;
12
use Zend\Hydrator\Strategy\DateTimeFormatterStrategy;
13
use Zend\ServiceManager\Factory\FactoryInterface;
14
15
class PasswordHydratorFactory implements FactoryInterface
16
{
17
    /**
18
     * @inheritdoc
19
     */
20 6
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
21
    {
22 6
        $extraction = new ClassMethods();
23 6
        $extraction->addStrategy('created_at', new DateTimeFormatterStrategy());
24 6
        $extraction->addStrategy('due', new DateTimeFormatterStrategy());
25 6
        $extraction->addStrategy('active', new BooleanStrategy(1, 0));
26 6
        $extraction->addStrategy('owner', new NestedEntityStrategy(new ClassMethods()));
27 6
        $extraction->addStrategy('hash', $container->get(HashStrategy::class));
28
29 6
        $extraction->setNamingStrategy(new MapNamingStrategy([
30 6
            'created_at' => 'createdAt',
31
            'password' => 'hash',
32
        ], [
33 6
            'isActive' => 'active',
34
            'createdAt' => 'created_at',
35
        ]));
36
37 6
        return $extraction;
38
    }
39
}
40