PathInfo   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 73
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A dirname() 0 3 1
A extension() 0 3 1
A hasExtension() 0 3 1
A for() 0 3 1
A filename() 0 3 1
A __construct() 0 8 2
A basename() 0 3 1
1
<?php
2
3
/**
4
 * Copyright (c) Florian Krämer (https://florian-kraemer.net)
5
 * Licensed under The MIT License
6
 * For full copyright and license information, please see the LICENSE.txt
7
 * Redistributions of files must retain the above copyright notice.
8
 *
9
 * @copyright Copyright (c) Florian Krämer (https://florian-kraemer.net)
10
 * @author    Florian Krämer
11
 * @link      https://github.com/Phauthentic
12
 * @license   https://opensource.org/licenses/MIT MIT License
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phauthentic\Infrastructure\Storage\Utility;
18
19
/**
20
 * OO version of pathinfo()
21
 */
22
class PathInfo
23
{
24
    /** @var string */
25
    protected string $dirname;
26
27
    /** @var string */
28
    protected string $basename;
29
30
    /** @var string|null */
31
    protected ?string $extension;
32
33
    /** @var string */
34
    protected string $filename;
35
36
    /**
37
     * @param string $path Path
38
     */
39
    private function __construct(string $path)
40
    {
41
        $info = pathinfo($path);
42
43
        $this->dirname = $info['dirname'] ?? '';
44
        $this->basename = $info['basename'];
45
        $this->extension = empty($info['extension'] ?? null) ? null : $info['extension'];
46
        $this->filename = $info['filename'];
47
    }
48
49
    /**
50
     * @return self
51
     */
52
    public static function for(string $path): self
53
    {
54
        return new self($path);
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    public function dirname(): ?string
61
    {
62
        return $this->dirname;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function basename(): string
69
    {
70
        return $this->basename;
71
    }
72
73
    /**
74
     * @return string|null
75
     */
76
    public function extension(): ?string
77
    {
78
        return $this->extension;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function filename(): string
85
    {
86
        return $this->filename;
87
    }
88
89
    /**
90
     * @return bool
91
     */
92
    public function hasExtension(): bool
93
    {
94
        return $this->extension !== null;
95
    }
96
}
97