Completed
Push — master ( 534878...ea6b08 )
by Tom
02:29
created

Rule   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 43
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A __get() 0 3 1
A __set() 0 3 1
A touch() 0 3 1
A shouldRun() 0 8 4
1
<?php
2
namespace Transphporm;
3
class Rule {
4
	private $query;
5
	private $pseudo;
6
	private $depth;
7
	private $index;
8
	private $properties = [];
9
	private $lastRun = 0;
10
11
	const S = 1;
12
	const M = 60;
13
	const H = self::M*60;
14
	const D = self::H*24;
15
16
17
	public function __construct($query, $pseudo, $depth, $index, array $properties = []) {
18
		$this->query = $query;
19
		$this->pseudo = $pseudo;
20
		$this->depth = $depth;
21
		$this->index = $index;
22
		$this->properties = $properties;
23
	}
24
25
	public function __get($name) {
26
		return $this->$name;
27
	}
28
29
	public function __set($name, $value) {
30
		$this->$name = $value;
31
	}
32
33
	public function touch() {
34
		$this->lastRun = time();
35
	}
36
37
	public function shouldRun($time) {
0 ignored issues
show
Unused Code introduced by
The parameter $time is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
		if (isset($this->properties['update-frequency']) && $this->lastRun !== 0) {
39
			$frequency = $this->properties['update-frequency'];
40
			$static = ['always' => true, 'never' => false];
41
			if (isset($static[$frequency])) return $static[$frequency];
42
		}
43
		else return true;
44
	}
45
}