Completed
Push — stable2 ( 10fadc...4d0e89 )
by Robin
07:41
created

NativeFileInfo   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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