Completed
Push — master ( 7a83e2...2cf7e5 )
by Shcherbak
02:26
created

FileInfo::getPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
  namespace Funivan\Cs\FileFinder;
4
5
  /**
6
   
7
   * @author Ivan Shcherbak <[email protected]> 2016
8
   */
9
  class FileInfo {
10
11
    const STATUS_UNKNOWN = 0;
12
13
    const STATUS_ADDED = 1;
14
15
    const STATUS_COPIED = 2;
16
17
    const STATUS_MODIFIED = 3;
18
19
    const STATUS_RENAMED = 4;
20
21
    const STATUS_DELETED = 5;
22
23
24
    /**
25
     * @var array
26
     */
27
    private static $statusMap = [
28
      self::STATUS_UNKNOWN => 'unknown',
29
      self::STATUS_ADDED => 'added',
30
      self::STATUS_COPIED => 'copied',
31
      self::STATUS_MODIFIED => 'modified',
32
      self::STATUS_RENAMED => 'renamed',
33
      self::STATUS_DELETED => 'deleted',
34
    ];
35
36
    /**
37
     * The full path to the file
38
     *
39
     * @var string
40
     */
41
    private $path;
42
43
    /**
44
     * The files status
45
     *
46
     * @var int
47
     */
48
    private $status;
49
50
    /**
51
     * @var \Funivan\PhpTokenizer\File
52
     */
53
    private $tokenizer;
54
55
56
    /**
57
     * Initializes a new instance of the File class.
58
     *
59
     * @param string $status
60
     * @param string $filePath
61
     */
62 3
    public function __construct($filePath, $status) {
63 3
      if (!isset(self::$statusMap[$status])) {
64
        throw new \InvalidArgumentException('Invalid status');
65
      }
66
67 3
      $this->status = (int) $status;
68 3
      $this->path = $filePath;
69 3
    }
70
71
72
    /**
73
     * @return string
74
     */
75
    public function getName() {
76
      return basename($this->path);
77
    }
78
79
80
    /**
81
     * @return string
82
     */
83
    public function getExtension() {
84
      return pathinfo($this->path, PATHINFO_EXTENSION);
85
    }
86
87
88
    /**
89
     * @return string
90
     */
91
    public function getStatus() {
92
      return $this->status;
93
    }
94
95
96
    /**
97
     * @return string
98
     */
99
    public function getStatusName() {
100
      return self::$statusMap[$this->status];
101
    }
102
103
104
    /**
105
     * @return string
106
     */
107
    public function getMimeType() {
108
      if ($this->status === self::STATUS_DELETED) {
109
        return '';
110
      }
111
      return finfo_file(finfo_open(FILEINFO_MIME), $this->path);
112
    }
113
114
115
    /**
116
     * @return string
117
     */
118 3
    public function getPath() {
119 3
      return $this->path;
120
    }
121
122
123
    /**
124
     * @return \Funivan\PhpTokenizer\File
125
     */
126 3
    public function getTokenizer() {
127 3
      if (empty($this->tokenizer)) {
128 3
        $this->tokenizer = new \Funivan\PhpTokenizer\File($this->getPath());
129 3
      }
130
131 3
      return $this->tokenizer;
132
    }
133
134
  }
135