Passed
Branch master (23c1c2)
by Wanderson
03:02
created

Storable::getLastModifiedDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Win\Models\Filesystem;
4
5
use Win\Models\DateTime;
6
7
/**
8
 * Item dentro do Diretório
9
 * Podendo ser outro diretório, arquivos, etc
10
 */
11
abstract class Storable
12
{
13
	const REGEXP_PATH = '@^(([a-zA-Z0-9._\-][\/]?))+$@';
14
	const REGEXP_NAME = '@^(([a-zA-Z0-9._\-]?))+$@';
15
	const DS = DIRECTORY_SEPARATOR;
16
17
	/** @var string */
18
	private $path;
19
20
	/** @var Directory */
21
	private $directory;
22
23
	/** @return string */
24
	public function __toString()
25
	{
26
		return $this->getPath();
27
	}
28
29
	/** @return string */
30
	public function getPath()
31
	{
32
		return $this->path;
33
	}
34
35
	/** @return string */
36
	public function getAbsolutePath()
37
	{
38
		return BASE_PATH . static::DS . $this->path;
39
	}
40
41
	/**
42
	 * Retorna o diretório pai
43
	 * @return Directory
44
	 */
45
	public function getDirectory()
46
	{
47
		if (is_null($this->directory)) {
48
			$path = pathinfo($this->getPath(), PATHINFO_DIRNAME);
49
			$this->directory = new Directory($path);
50
		}
51
52
		return $this->directory;
53
	}
54
55
	/** @return string */
56
	public function getName()
57
	{
58
		return pathinfo($this->getAbsolutePath(), PATHINFO_FILENAME);
59
	}
60
61
	/** @return string */
62
	public function getBaseName()
63
	{
64
		return pathinfo($this->getAbsolutePath(), PATHINFO_BASENAME);
65
	}
66
67
	/** @return DateTime */
68
	public function getLastModifiedDate()
69
	{
70
		$ts = filemtime($this->getAbsolutePath());
71
72
		return new DateTime("@$ts");
73
	}
74
75
	/** @param string $path */
76
	protected function setPath($path)
77
	{
78
		$this->path = $path;
79
	}
80
}
81