Test Failed
Push — master ( 2ab532...05cdde )
by Jean-Christophe
06:27
created

LogMessage   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 21
eloc 34
dl 0
loc 124
c 0
b 0
f 0
rs 10

17 Methods

Rating   Name   Duplication   Size   Complexity  
A getPart() 0 2 1
A __construct() 0 7 1
A getDatetime() 0 2 1
A setContext() 0 2 1
A equals() 0 2 3
A incCount() 0 2 1
A setExtra() 0 2 1
A getCount() 0 2 1
A getLevel() 0 2 1
A getMessage() 0 2 1
A setDatetime() 0 2 1
A setPart() 0 2 1
A setMessage() 0 2 1
A addMessage() 0 8 3
A getContext() 0 2 1
A getExtra() 0 2 1
A setLevel() 0 2 1
1
<?php
2
3
namespace Ubiquity\log;
4
5
class LogMessage {
6
	
7
	private $message;
8
	private $context;
9
	private $part;
10
	private $level;
11
	private $extra;
12
	private $datetime;
13
	private $count=1;
14
	
15
	public function __construct($message="",$context="",$part="",$level=0,$datetime=null,$extra=null){
16
		$this->message=$message;
17
		$this->context=$context;
18
		$this->part=$part;
19
		$this->level=$level;
20
		$this->datetime=$datetime;
21
		$this->extra=$extra;
22
	}
23
	/**
24
	 * @return mixed
25
	 */
26
	public function getMessage() {
27
		return $this->message;
28
	}
29
30
	/**
31
	 * @return mixed
32
	 */
33
	public function getContext() {
34
		return $this->context;
35
	}
36
37
	/**
38
	 * @return mixed
39
	 */
40
	public function getPart() {
41
		return $this->part;
42
	}
43
44
	/**
45
	 * @return mixed
46
	 */
47
	public function getLevel() {
48
		return $this->level;
49
	}
50
51
	/**
52
	 * @return mixed
53
	 */
54
	public function getExtra() {
55
		return $this->extra;
56
	}
57
58
	/**
59
	 * @return mixed
60
	 */
61
	public function getDatetime() {
62
		return $this->datetime;
63
	}
64
65
	/**
66
	 * @param mixed $message
67
	 */
68
	public function setMessage($message) {
69
		$this->message = $message;
70
	}
71
72
	/**
73
	 * @param mixed $context
74
	 */
75
	public function setContext($context) {
76
		$this->context = $context;
77
	}
78
79
	/**
80
	 * @param mixed $part
81
	 */
82
	public function setPart($part) {
83
		$this->part = $part;
84
	}
85
86
	/**
87
	 * @param mixed $level
88
	 */
89
	public function setLevel($level) {
90
		$this->level = $level;
91
	}
92
93
	/**
94
	 * @param mixed $extra
95
	 */
96
	public function setExtra($extra) {
97
		$this->extra = $extra;
98
	}
99
100
	/**
101
	 * @param mixed $datetime
102
	 */
103
	public function setDatetime($datetime) {
104
		$this->datetime = $datetime;
105
	}
106
	
107
	public function incCount(){
108
		$this->count++;
109
	}
110
	/**
111
	 * @return mixed
112
	 */
113
	public function getCount() {
114
		return $this->count;
115
	}
116
	
117
	public function equals(LogMessage $message){
118
		return $this->message===$message->getMessage() && $this->context===$message->getContext() && $this->part===$message->getPart();
119
	}
120
121
	public static function addMessage(&$messages,LogMessage $newMessage){
122
		if(sizeof($messages)>0){
123
			$lastM=end($messages);
124
			if($newMessage->equals($lastM)){
125
				return $lastM->incCount();
126
			}
127
		}
128
		$messages[]=$newMessage;
129
	}
130
	
131
}
132
133