SWLPropertyChange   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 2
dl 0
loc 96
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A newFromSerialization() 0 8 3
A __construct() 0 4 1
A getOldValue() 0 3 1
A getNewValue() 0 3 1
A getType() 0 11 3
A getSerialization() 0 4 3
1
<?php
2
3
/**
4
 * Represents a change to a semantic property.
5
 *
6
 * @since 0.1
7
 *
8
 * @file SWL_PropertyChange.php
9
 * @ingroup SemanticWatchlist
10
 *
11
 * @licence GNU GPL v3 or later
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
class SWLPropertyChange {
15
16
	const TYPE_INSERT = 0;
17
	const TYPE_UPDATE = 1;
18
	const TYPE_DELETE = 2;
19
20
	/**
21
	 * The old value.
22
	 *
23
	 * @var SMWDataItem or null
24
	 */
25
	private $oldValue;
26
27
	/**
28
	 * The new value.
29
	 *
30
	 * @var SMWDataItem or null
31
	 */
32
	private $newValue;
33
34
	/**
35
	 * Creates and returns a new SWLPropertyChange instance from a serialization.
36
	 *
37
	 * @param string|null $oldValue
38
	 * @param string|null $newValue
39
	 *
40
	 * @return SWLPropertyChange
41
	 */
42
	public static function newFromSerialization( SMWDIProperty $property, $oldValue, $newValue ) {
43
		$diType = SMWDataValueFactory::getDataItemId( $property->findPropertyTypeID() );
0 ignored issues
show
Deprecated Code introduced by
The method SMW\DIProperty::findPropertyTypeId() has been deprecated with message: since 3.0, use DIProperty::findPropertyValueType

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
44
45
		return new self(
46
			is_null( $oldValue ) ? null : SMWDataItem::newFromSerialization( $diType, $oldValue ),
47
			is_null( $newValue ) ? null : SMWDataItem::newFromSerialization( $diType, $newValue )
48
		);
49
	}
50
51
	/**
52
	 * Create a new SWLPropertyChange.
53
	 *
54
	 * @param SMWDataItem $oldValue
55
	 * @param SMWDataItem $newValue
56
	 */
57
	public function __construct( /* SMWDataItem */ $oldValue, /* SMWDataItem */ $newValue ) {
58
		$this->oldValue = $oldValue;
59
		$this->newValue = $newValue;
60
	}
61
62
	/**
63
	 * Returns the old value, or null if there is none.
64
	 *
65
	 * @return SMWDataItem or null
66
	 */
67
	public function getOldValue() {
68
		return $this->oldValue;
69
	}
70
71
72
	/**
73
	 * returns the new value, or null if there is none.
74
	 *
75
	 * @return SMWDataItem or null
76
	 */
77
	public function getNewValue() {
78
		return $this->newValue;
79
	}
80
81
	/**
82
	 * Returns the type of the change.
83
	 *
84
	 * @return element of the SWLPropertyChange::TYPE_ enum
85
	 */
86
	public function getType() {
87
		if ( is_null( $this->oldValue ) ) {
88
			return self::TYPE_INSERT;
89
		}
90
		elseif ( is_null( $this->newValue ) ) {
91
			return self::TYPE_DELETE;
92
		}
93
		else {
94
			return self::TYPE_UPDATE;
95
		}
96
	}
97
98
	/**
99
	 * Returns a serialized version of the change, suitable to
100
	 * do equal comparisions but not to unserialize.
101
	 *
102
	 * @return string
103
	 */
104
	public function getSerialization() {
105
		return is_null( $this->oldValue ) ? '' : $this->oldValue->getSerialization() . '|' .
106
			is_null( $this->newValue ) ? '' : $this->newValue->getSerialization();
107
	}
108
109
}
110