Completed
Push — master ( 829a6e...eda3d5 )
by Westin
06:45
created

AdaptorCacheFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 28
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 25 3
1
<?php
2
declare(strict_types=1);
3
4
namespace WShafer\PSR11FlySystem\Cache;
5
6
use League\Flysystem\Cached\Storage\Adapter;
7
use WShafer\PSR11FlySystem\Exception\MissingConfigException;
8
use WShafer\PSR11FlySystem\Exception\MissingServiceException;
9
use WShafer\PSR11FlySystem\FlySystemManager;
10
11
class AdaptorCacheFactory extends ContainerAwareCacheAbstract
12
{
13
    public function __invoke(array $options)
14
    {
15
        $flyManagerServiceName = $options['flyManagerServiceName'] ?? FlySystemManager::class;
16
17
        if (empty($options['fileSystem'])) {
18
            throw new MissingConfigException(
19
                'Unable to locate cache file adaptor in config'
20
            );
21
        }
22
23
        $fileSystem = $options['fileSystem'];
24
        $fileName = $options['fileName'] ?? 'file_cache';
25
        $ttl = $options['ttl'] ?? null;
26
27
        /** @var FlySystemManager $manager */
28
        $manager = $this->getService($flyManagerServiceName);
29
30
        if (!$manager->has($fileSystem)) {
31
            throw new MissingServiceException(
32
                'Unable to locate file system: '.$fileSystem
33
            );
34
        }
35
36
        return new Adapter($manager->get($fileSystem), $fileName, $ttl);
0 ignored issues
show
Documentation introduced by
$manager->get($fileSystem) is of type object<League\Flysystem\...Flysystem\MountManager>, but the function expects a object<League\Flysystem\AdapterInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
37
    }
38
}
39