Passed
Branch tests1.5 (2e49f7)
by Wanderson
01:30
created

DirectoryItem::getLastModifiedDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Win\File;
4
5
use Win\Calendar\DateTime;
6
use const BASE_PATH;
7
8
/**
9
 * Item dentro do Diretório
10
 * São outros diretório, arquivos, etc
11
 */
12
abstract class DirectoryItem implements DirectoryItemInterface {
13
14
	const REGEXP_PATH = '@^(([a-z0-9._\-][\/]?))+$@';
15
	const REGEXP_NAME = '@^(([a-z0-9._\-]?))+$@';
16
17
	/** @var string */
18
	private $path;
19
20
	/** @var Directory */
21
	private $directory;
22
23
	/** @return string */
24
	public function getPath() {
25
		return $this->path;
26
	}
27
28
	/** @return string */
29
	public function getAbsolutePath() {
30
		return BASE_PATH . DIRECTORY_SEPARATOR . $this->path;
31
	}
32
33
	/**
34
	 * Retorna o diretório pai
35
	 * @return Directory
36
	 */
37
	public function getDirectory() {
38
		if (is_null($this->directory)) {
39
			$this->directory = new Directory(pathinfo($this->getPath(), PATHINFO_DIRNAME));
40
		}
41
		return $this->directory;
42
	}
43
44
	/** @return Date */
0 ignored issues
show
Bug introduced by
The type Win\File\Date was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
45
	public function getLastModifiedDate(){
46
		$ts = filemtime($this->getAbsolutePath());
47
		return new \DateTime("@$ts");
0 ignored issues
show
Bug Best Practice introduced by
The expression return new DateTime('@'.$ts) returns the type DateTime which is incompatible with the documented return type Win\File\Date.
Loading history...
48
	}
49
	/** @param string $path */
50
	protected function setPath($path) {
51
		$this->path = $path;
52
	}
53
54
	protected function setDirectory(Directory $directory) {
55
		$this->directory = $directory;
56
		$path = $directory->getPath() . DIRECTORY_SEPARATOR . $this->__toString();
57
		$this->setPath($path);
58
	}
59
60
	/** @param string */
61
	protected function setName($name) {
62
		$path = $this->getDirectory()->getPath() . DIRECTORY_SEPARATOR . $name;
63
		$this->setPath($path);
64
	}
65
66
	/**
67
	 * Renomeia
68
	 * @param string $newName Novo nome
69
	 * @return boolean
70
	 */
71
	public function rename($newName) {
72
		$oldPath = $this->getAbsolutePath();
73
		$this->setName($newName);
74
		return rename($oldPath, $this->getAbsolutePath());
75
	}
76
77
	/**
78
	 * Move para um novo diretório
79
	 * @param Directory $newDirectory
80
	 * @return boolean
81
	 */
82
	public function move(Directory $newDirectory) {
83
		$oldPath = $this->getAbsolutePath();
84
		$this->setDirectory($newDirectory);
85
		if (!$this->getDirectory()->exists()) {
86
			$this->getDirectory()->create();
87
		}
88
		return rename($oldPath, $this->getAbsolutePath());
89
	}
90
91
	/**
92
	 * Define a permissão ao diretório
93
	 * @param int $chmod
94
	 * @return boolean
95
	 */
96
	public function setChmod($chmod = 0755) {
97
		return @chmod($this->getAbsolutePath(), $chmod);
98
	}
99
100
	/** @return string */
101
	public function getChmod() {
102
		clearstatcache();
103
		return substr(decoct(fileperms($this->getAbsolutePath())), 2);
104
	}
105
106
}
107