Passed
Push — master ( bd3cb9...127ddb )
by Jean-Christophe
17:45
created

CacheFile::setFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
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 1
	public function __construct($type = "", $name = "", $timestamp = 0, $size = 0, $fileKey = "") {
15 1
		$this->type = $type;
16 1
		$this->name = $name;
17 1
		$this->timestamp = $timestamp;
18 1
		$this->size = $size;
19 1
		$this->file = $fileKey;
20
	}
21
22 1
	public static function initFromFiles($folder, $type, $keyFunction = null) {
23 1
		$files = UFileSystem::glob_recursive ( $folder . \DS . '*' );
24 1
		$result = [ ];
25 1
		if (! isset ( $keyFunction )) {
26 1
			$keyFunction = function ($file) {
27 1
				return \basename ( $file );
28
			};
29
		}
30 1
		foreach ( $files as $file ) {
31 1
			if (is_file ( $file )) {
32 1
				$result [] = new CacheFile ( $type, $keyFunction ( $file ), \filectime ( $file ), \filesize ( $file ), $file );
33
			}
34
		}
35 1
		if (\count ( $result ) == 0)
36
			$result [] = new CacheFile ( $type, "", "", "", "" );
37 1
		return $result;
38
	}
39
40 1
	public static function delete($folder) {
41 1
		$files = UFileSystem::glob_recursive ( $folder . \DS . '*' );
42 1
		foreach ( $files as $file ) {
43 1
			if (is_file ( $file )) {
44 1
				\unlink ( $file );
45
			}
46
		}
47
	}
48
49 1
	public function getName() {
50 1
		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 1
	public function getType() {
77 1
		return $this->type;
78
	}
79
80
	public function setType($type) {
81
		$this->type = $type;
82
		return $this;
83
	}
84
85 1
	public function getFile() {
86 1
		return $this->file;
87
	}
88
89
	public function setFile($file) {
90
		$this->file = $file;
91
		return $this;
92
	}
93
}
94