Passed
Pull Request — main (#161)
by Daniel
05:38 queued 01:35
created

TemporaryUrlGenerator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 2
ccs 0
cts 1
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentsBundle\Factory\Uploadable;
15
16
use League\Flysystem\Config;
17
use League\Flysystem\Filesystem;
18
use League\Flysystem\UrlGeneration\TemporaryUrlGenerator as FlysystemTemporaryUrlGenerator;
19
use Silverback\ApiComponentsBundle\Exception\InvalidArgumentException;
20
21
class TemporaryUrlGenerator implements UploadableUrlGeneratorInterface
22
{
23
    public function __construct(private readonly array $config = [], private readonly string $expires = '+3 days')
24
    {
25
    }
26
27
    public function generateUrl(object $object, string $fileProperty, Filesystem $filesystem, string $path): string
28
    {
29
        if (!$filesystem instanceof FlysystemTemporaryUrlGenerator) {
30
            throw new InvalidArgumentException(sprintf('The public URL generator requires a filesystem implementing %s', FlysystemTemporaryUrlGenerator::class));
31
        }
32
33
        return $filesystem->temporaryUrl($path, new \DateTime($this->expires), new Config($this->config));
0 ignored issues
show
Bug introduced by
new League\Flysystem\Config($this->config) of type League\Flysystem\Config is incompatible with the type array expected by parameter $config of League\Flysystem\Filesystem::temporaryUrl(). ( Ignorable by Annotation )

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

33
        return $filesystem->temporaryUrl($path, new \DateTime($this->expires), /** @scrutinizer ignore-type */ new Config($this->config));
Loading history...
34
    }
35
}
36