LocalAdapterFactory::doCreateService()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 0
cp 0
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
/**
4
 * BsbFlystem
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @see       https://bushbaby.nl/
10
 *
11
 * @copyright Copyright (c) 2014-2021 bushbaby multimedia. (https://bushbaby.nl)
12
 * @author    Bas Kamer <[email protected]>
13
 * @license   MIT
14 3
 *
15
 * @package   bushbaby/flysystem
16 3
 */
17
18 3
declare(strict_types=1);
19
20
namespace BsbFlysystem\Adapter\Factory;
21 5
22
use BsbFlysystem\Exception\UnexpectedValueException;
23 5
use League\Flysystem\Adapter\Local as Adapter;
24 1
use League\Flysystem\AdapterInterface;
25
use Psr\Container\ContainerInterface;
26 4
27
class LocalAdapterFactory extends AbstractAdapterFactory
28
{
29
    public function doCreateService(ContainerInterface $container): AdapterInterface
30
    {
31
        $options = [];
32
        $options[] = $this->options['root'];
33
        $options[] = $this->options['writeFlags'] ?? null;
34
35
        if (isset($this->options['linkHandling'])) { // since 1.0.8
36
            $options[] = $this->options['linkHandling'];
37
38
            if (isset($this->options['permissions'])) { // since 1.0.14
39
                $options[] = $this->options['permissions'];
40
            }
41
        }
42
43
        return new Adapter(...$options);
0 ignored issues
show
Documentation introduced by
$options is of type array<integer,?>, but the function expects a string.

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...
44
    }
45
46
    protected function validateConfig(): void
47
    {
48
        if (! isset($this->options['root'])) {
49
            throw new UnexpectedValueException("Missing 'root' as option");
50
        }
51
    }
52
}
53