Passed
Push — 10.x ( 52de98...21fac1 )
by Andrey
14:55
created

Paths::basename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the "andrey-helldar/laravel-lang-publisher" project.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @author Andrey Helldar <[email protected]>
10
 *
11
 * @copyright 2021 Andrey Helldar
12
 *
13
 * @license MIT
14
 *
15
 * @see https://github.com/andrey-helldar/laravel-lang-publisher
16
 */
17
18
declare(strict_types=1);
19
20
namespace Helldar\LaravelLangPublisher\Concerns;
21
22
use Helldar\LaravelLangPublisher\Facades\Helpers\Config;
23
use Illuminate\Support\Collection;
24
use Illuminate\Support\Str;
25
26
trait Paths
27
{
28
    protected $trim_chars = '/\\';
29
30
    protected $directory_separator = DIRECTORY_SEPARATOR;
31
32
    protected function extension(string $filename): string
33
    {
34
        return pathinfo($filename, PATHINFO_EXTENSION);
0 ignored issues
show
Bug Best Practice introduced by
The expression return pathinfo($filenam...rns\PATHINFO_EXTENSION) could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
35
    }
36
37
    protected function filename(string $filename): string
38
    {
39
        return pathinfo($filename, PATHINFO_FILENAME);
0 ignored issues
show
Bug Best Practice introduced by
The expression return pathinfo($filenam...erns\PATHINFO_FILENAME) could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
40
    }
41
42
    protected function basename(string $filename): string
43
    {
44
        return pathinfo($filename, PATHINFO_BASENAME);
0 ignored issues
show
Bug Best Practice introduced by
The expression return pathinfo($filenam...erns\PATHINFO_BASENAME) could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
45
    }
46
47
    protected function path(string $base_path, ...$parameters): string
48
    {
49
        $base_path = rtrim($base_path, $this->trim_chars);
50
51
        $parameters = Collection::make($parameters)
52
            ->map(function (string $parameter) {
53
                return trim($parameter, $this->trim_chars);
54
            })->implode($this->directory_separator);
55
56
        return $base_path . $this->directory_separator . $parameters;
57
    }
58
59
    protected function vendorPath(string ...$parameters): string
60
    {
61
        return $this->path(Config::vendor(), ...$parameters);
62
    }
63
64
    protected function resourcesPath(string ...$parameters): string
65
    {
66
        return $this->path(Config::resources(), ...$parameters);
67
    }
68
69
    protected function resolvePath(string $path, string $locale): string
70
    {
71
        return Str::replace('{locale}', $locale, $path);
72
    }
73
}
74