FilePath   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 13 2
A file() 0 4 1
A __construct() 0 3 1
A dir() 0 4 1
A ext() 0 4 1
A __toString() 0 3 1
1
<?php
2
3
namespace HexMakina\LocalFS;
4
5
class FilePath
6
{
7
    private $filepath = null;
8
9
    private $directories = null;
10
    private $file = null;
11
    private $file_extension = null;
12
13
    private $already_parsed = false;
14
15
    public function __construct($filepath)
16
    {
17
        $this->filepath = $filepath;
18
    }
19
20
    public function __toString()
21
    {
22
        return '' . $this->filepath;
23
    }
24
25
    public function dir(): string
26
    {
27
        $this->parse();
28
        return $this->directories;
29
    }
30
31
    public function file(): string
32
    {
33
        $this->parse();
34
        return $this->file;
35
    }
36
37
    public function ext(): string
38
    {
39
        $this->parse();
40
        return $this->file_extension;
41
    }
42
43
    private function parse(): FilePath
44
    {
45
        if ($this->already_parsed === false) {
46
            $res = pathinfo($this->filepath);
47
48
            $this->directories = $res['dirname'];
49
            $this->file = $res['basename'];
50
            $this->file_extension = $res['extension'];
51
52
            $this->already_parsed = true;
53
        }
54
55
        return $this;
56
    }
57
}
58
59
// mime_content_type() - Detect MIME Content-type for a file
60
// stat()
61