Passed
Pull Request — master (#5)
by Alex
02:23
created

ArrayAdapterFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Arp\LaminasDoctrine\Factory\Cache\Adapter;
6
7
use Arp\LaminasFactory\AbstractFactory;
8
use Laminas\ServiceManager\Exception\ServiceNotCreatedException;
9
use Laminas\ServiceManager\Exception\ServiceNotFoundException;
10
use Psr\Container\ContainerExceptionInterface;
11
use Psr\Container\ContainerInterface;
12
use Symfony\Component\Cache\Adapter\ArrayAdapter;
13
use Symfony\Component\Cache\Exception\InvalidArgumentException;
14
15
final class ArrayAdapterFactory extends AbstractFactory
16
{
17
    /**
18
     * @param array<string, mixed>|null $options
19
     *
20
     * @throws ServiceNotCreatedException
21
     * @throws ServiceNotFoundException
22
     * @throws ContainerExceptionInterface
23
     */
24
    public function __invoke(ContainerInterface $container, string $requestedName, array $options = null): ArrayAdapter
25
    {
26
        $options = $options ?? $this->getServiceOptions($container, $requestedName, 'cache');
27
28
        try {
29
            return new ArrayAdapter(
30
                $options['default_lifetime'] ?? 0,
31
                $options['store_serialized'] ?? 0,
0 ignored issues
show
Bug introduced by
It seems like $options['store_serialized'] ?? 0 can also be of type integer; however, parameter $storeSerialized of Symfony\Component\Cache\...yAdapter::__construct() does only seem to accept boolean, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
                /** @scrutinizer ignore-type */ $options['store_serialized'] ?? 0,
Loading history...
32
                $options['max_lifetime'] ?? 0,
33
                $options['max_items'] ?? 0,
34
            );
35
        } catch (InvalidArgumentException $e) {
36
            throw new ServiceNotCreatedException(
37
                sprintf('Failed to create cache adapter \'%s\' due to invalid configuration options', $requestedName),
38
                $e->getCode(),
39
                $e,
40
            );
41
        }
42
    }
43
}
44