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

PublicUrlGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 13
ccs 0
cts 6
cp 0
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A generateUrl() 0 7 2
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\PublicUrlGenerator as FlysystemPublicUrlGenerator;
19
use Silverback\ApiComponentsBundle\Exception\InvalidArgumentException;
20
21
class PublicUrlGenerator implements UploadableUrlGeneratorInterface
22
{
23
    public function __construct(private readonly array $config = [])
24
    {
25
    }
26
27
    public function generateUrl(object $object, string $fileProperty, Filesystem $filesystem, string $path): string
28
    {
29
        if (!$filesystem instanceof FlysystemPublicUrlGenerator) {
30
            throw new InvalidArgumentException(sprintf('The public URL generator requires a filesystem implementing %s', FlysystemPublicUrlGenerator::class));
31
        }
32
33
        return $filesystem->publicUrl($path, 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::publicUrl(). ( 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->publicUrl($path, /** @scrutinizer ignore-type */ new Config($this->config));
Loading history...
34
    }
35
}
36