Completed
Push — master ( 0bfb02...89f47c )
by Robin
02:44
created

NativeFileInfo   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 0
loc 133
ccs 42
cts 42
cp 1
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getPath() 0 3 1
A getName() 0 3 1
A stat() 0 6 2
A getSize() 0 4 1
A getMTime() 0 4 1
A isDirectory() 0 4 1
A getMode() 0 8 2
A isReadOnly() 0 4 1
A isHidden() 0 4 1
A isSystem() 0 4 1
A isArchived() 0 4 1
1
<?php
2
/**
3
 * Copyright (c) 2014 Robin Appelman <[email protected]>
4
 * This file is licensed under the Licensed under the MIT license:
5
 * http://opensource.org/licenses/MIT
6
 */
7
8
namespace Icewind\SMB\Native;
9
10
use Icewind\SMB\IFileInfo;
11
12
class NativeFileInfo implements IFileInfo {
13
	const MODE_FILE = 0100000;
14
15
	/**
16
	 * @var string
17
	 */
18
	protected $path;
19
20
	/**
21
	 * @var string
22
	 */
23
	protected $name;
24
25
	/**
26
	 * @var NativeShare
27
	 */
28
	protected $share;
29
30
	/**
31
	 * @var array|null
32
	 */
33
	protected $statCache;
34
35
	/**
36
	 * @var int
37
	 */
38
	protected $modeCache;
39
40
	/**
41
	 * @param NativeShare $share
42
	 * @param string $path
43
	 * @param string $name
44
	 * @param array $stat
45
	 */
46 208
	public function __construct($share, $path, $name, $stat = null) {
47 208
		$this->share = $share;
48 208
		$this->path = $path;
49 208
		$this->name = $name;
50 208
		$this->statCache = $stat;
51 208
	}
52
53
	/**
54
	 * @return string
55
	 */
56 204
	public function getPath() {
57 204
		return $this->path;
58
	}
59
60
	/**
61
	 * @return string
62
	 */
63 98
	public function getName() {
64 98
		return $this->name;
65
	}
66
67
	/**
68
	 * @return array
69
	 */
70 204
	protected function stat() {
71 204
		if (is_null($this->statCache)) {
72 204
			$this->statCache = $this->share->getStat($this->getPath());
73 102
		}
74 204
		return $this->statCache;
75
	}
76
77
	/**
78
	 * @return int
79
	 */
80 58
	public function getSize() {
81 58
		$stat = $this->stat();
82 58
		return $stat['size'];
83
	}
84
85
	/**
86
	 * @return int
87
	 */
88 2
	public function getMTime() {
89 2
		$stat = $this->stat();
90 2
		return $stat['mtime'];
91
	}
92
93
	/**
94
	 * @return bool
95
	 */
96 202
	public function isDirectory() {
97 202
		$stat = $this->stat();
98 202
		return !($stat['mode'] & self::MODE_FILE);
99
	}
100
101
	/**
102
	 * @return int
103
	 */
104 28
	protected function getMode() {
105 28
		if (!$this->modeCache) {
106 28
			$attribute = $this->share->getAttribute($this->path, 'system.dos_attr.mode');
107
			// parse hex string
108 28
			$this->modeCache = (int)hexdec(substr($attribute, 2));
109 14
		}
110 28
		return $this->modeCache;
111
	}
112
113
	/**
114
	 * @return bool
115
	 */
116 18
	public function isReadOnly() {
117 18
		$mode = $this->getMode();
118 18
		return (bool)($mode & IFileInfo::MODE_READONLY);
119
	}
120
121
	/**
122
	 * @return bool
123
	 */
124 26
	public function isHidden() {
125 26
		$mode = $this->getMode();
126 26
		return (bool)($mode & IFileInfo::MODE_HIDDEN);
127
	}
128
129
	/**
130
	 * @return bool
131
	 */
132 16
	public function isSystem() {
133 16
		$mode = $this->getMode();
134 16
		return (bool)($mode & IFileInfo::MODE_SYSTEM);
135
	}
136
137
	/**
138
	 * @return bool
139
	 */
140 16
	public function isArchived() {
141 16
		$mode = $this->getMode();
142 16
		return (bool)($mode & IFileInfo::MODE_ARCHIVE);
143
	}
144
}
145