FilePath::parse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 13
rs 10
c 0
b 0
f 0
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