CascadeSaveServiceFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 21
rs 9.8666
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