PathInfo   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 73
ccs 19
cts 19
cp 1
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 $dirname;
26
27
    /** @var string */
28
    protected $basename;
29
30
    /** @var string|null */
31
    protected $extension;
32
33
    /** @var string */
34
    protected $filename;
35
36
    /**
37
     * @param string $path Path
38
     */
39 12
    private function __construct(string $path)
40
    {
41 12
        $info = pathinfo($path);
42
43 12
        $this->dirname = $info['dirname'];
44 12
        $this->basename = $info['basename'];
45 12
        $this->extension = empty($info['extension']) ? null : $info['extension'];
46 12
        $this->filename = $info['filename'];
47 12
    }
48
49
    /**
50
     * @return self
51
     */
52 12
    public static function for(string $path): self
53
    {
54 12
        return new self($path);
55
    }
56
57
    /**
58
     * @return string
59
     */
60 1
    public function dirname(): ?string
61
    {
62 1
        return $this->dirname;
63
    }
64
65
    /**
66
     * @return string
67
     */
68 11
    public function basename(): string
69
    {
70 11
        return $this->basename;
71
    }
72
73
    /**
74
     * @return string|null
75
     */
76 12
    public function extension(): ?string
77
    {
78 12
        return $this->extension;
79
    }
80
81
    /**
82
     * @return string
83
     */
84 9
    public function filename(): string
85
    {
86 9
        return $this->filename;
87
    }
88
89
    /**
90
     * @return bool
91
     */
92 9
    public function hasExtension(): bool
93
    {
94 9
        return $this->extension !== null;
95
    }
96
}
97