Passed
Push — main ( 501f40...d2df27 )
by Pranjal
13:08 queued 13s
created

LocalAdapter::publicUrl()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 13
rs 10
cc 3
nc 3
nop 2
1
<?php
2
/*
3
 * This file is part of the Scrawler package.
4
 *
5
 * (c) Pranjal Pandey <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Scrawler\Adapters\Storage;
12
13
use League\Flysystem\Local\LocalFilesystemAdapter;
14
use League\Flysystem\UnableToGeneratePublicUrl;
15
use League\Flysystem\UrlGeneration\PublicUrlGenerator;
16
17
class LocalAdapter extends LocalFilesystemAdapter implements PublicUrlGenerator
18
{
19
    public function __construct(
20
        private readonly string $storagePath,
21
    ) {
22
        parent::__construct($storagePath);
23
    }
24
25
    #[\Override]
26
    public function publicUrl(string $path, \League\Flysystem\Config $config): string
27
    {
28
        if ($this->fileExists('public/'.$path)) {
29
            if (function_exists('url')) {
30
                // @codeCoverageIgnoreStart
31
                return url($this->storagePath.'//public//'.$path);
32
                // @codeCoverageIgnoreEnd
33
            }
34
35
            return $this->storagePath.'//public//'.$path;
36
        }
37
        throw new UnableToGeneratePublicUrl('File is not public', $path);
38
    }
39
}
40