Test Failed
Push — master ( e59e29...f69517 )
by Jean-Christophe
14:19
created

CacheFile::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Ubiquity\cache;
4
5
use Ubiquity\utils\base\UFileSystem;
6
7
class CacheFile {
8
	private $type;
9
	private $name;
10
	private $timestamp;
11
	private $size;
12
	private $file;
13
14
	public function __construct($type = "", $name = "", $timestamp = 0, $size = 0, $fileKey = "") {
15
		$this->type = $type;
16
		$this->name = $name;
17
		$this->timestamp = $timestamp;
18
		$this->size = $size;
19
		$this->file = $fileKey;
20
	}
21
22
	public static function initFromFiles($folder, $type, $keyFunction = null) {
23
		$files = UFileSystem::glob_recursive ( $folder . \DS . '*' );
24
		$result = [ ];
25
		if (! isset ( $keyFunction )) {
26
			$keyFunction = function ($file) {
27
				return \basename ( $file );
28
			};
29
		}
30
		foreach ( $files as $file ) {
31
			if (is_file ( $file )) {
32
				$result [] = new CacheFile ( $type, $keyFunction ( $file ), \filectime ( $file ), \filesize ( $file ), $file );
33
			}
34
		}
35
		if (\sizeof ( $result ) == 0)
36
			$result [] = new CacheFile ( $type, "", "", "", "" );
37
		return $result;
38
	}
39
40
	public static function delete($folder) {
41
		$files = UFileSystem::glob_recursive ( $folder . \DS . '*' );
42
		foreach ( $files as $file ) {
43
			if (is_file ( $file )) {
44
				\unlink ( $file );
45
			}
46
		}
47
	}
48
49
	public function getName() {
50
		return $this->name;
51
	}
52
53
	public function setName($name) {
54
		$this->name = $name;
55
		return $this;
56
	}
57
58
	public function getTimestamp() {
59
		return $this->timestamp;
60
	}
61
62
	public function setTimestamp($timestamp) {
63
		$this->timestamp = $timestamp;
64
		return $this;
65
	}
66
67
	public function getSize() {
68
		return $this->size;
69
	}
70
71
	public function setSize($size) {
72
		$this->size = $size;
73
		return $this;
74
	}
75
76
	public function getType() {
77
		return $this->type;
78
	}
79
80
	public function setType($type) {
81
		$this->type = $type;
82
		return $this;
83
	}
84
85
	public function getFile() {
86
		return $this->file;
87
	}
88
89
	public function setFile($file) {
90
		$this->file = $file;
91
		return $this;
92
	}
93
}
94