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

AdaptorCacheFactory::__invoke()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 13
nc 3
nop 1
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 Westin Shafer
$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