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

LocalAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 8
c 0
b 0
f 0
dl 0
loc 21
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A publicUrl() 0 13 3
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