CascadeSaveServiceFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 21 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasEntity\Factory\Repository\Persistence;
6
7
use Arp\DoctrineEntityRepository\Constant\ClearMode;
8
use Arp\DoctrineEntityRepository\Constant\EntityEventOption;
9
use Arp\DoctrineEntityRepository\Constant\TransactionMode;
10
use Arp\DoctrineEntityRepository\Persistence\CascadeSaveService;
11
use Arp\LaminasFactory\AbstractFactory;
12
use Interop\Container\ContainerInterface;
13
use Psr\Log\LoggerInterface;
14
use Psr\Log\NullLogger;
15
16
/**
17
 * @author  Alex Patterson <[email protected]>
18
 * @package Arp\LaminasEntity\Factory\Repository\Persistence
19
 */
20
final class CascadeSaveServiceFactory extends AbstractFactory
21
{
22
    /**
23
     * @param ContainerInterface $container
24
     * @param string             $requestedName
25
     * @param array|null         $options
26
     *
27
     * @return CascadeSaveService
28
     */
29
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null): CascadeSaveService
30
    {
31
        $options = $options ?? $this->getServiceOptions($container, $requestedName);
32
33
        /** @var LoggerInterface|string $logger */
34
        $logger = $options['logger'] ?? NullLogger::class;
35
        if (is_string($logger)) {
0 ignored issues
show
introduced by
The condition is_string($logger) is always true.
Loading history...
36
            $logger = $this->getService($container, $logger, $requestedName);
37
        }
38
39
        return new CascadeSaveService(
40
            $logger,
41
            [
42
                EntityEventOption::TRANSACTION_MODE => TransactionMode::DISABLED,
43
                EntityEventOption::FLUSH_MODE => TransactionMode::DISABLED,
44
                EntityEventOption::CLEAR_MODE => ClearMode::DISABLED,
45
            ],
46
            [
47
                EntityEventOption::TRANSACTION_MODE => TransactionMode::DISABLED,
48
                EntityEventOption::FLUSH_MODE => TransactionMode::DISABLED,
49
                EntityEventOption::CLEAR_MODE => ClearMode::DISABLED,
50
            ]
51
        );
52
    }
53
}
54