Completed
Push — master ( d2d28e...1c2760 )
by mw
35:37
created

includes/dataitems/SMW_DI_Error.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @ingroup SMWDataItems
4
 */
5
6
/**
7
 * This class implements error list data items. These data items are used to
8
 * pass around lists of error messages within the application. They are not
9
 * meant to be stored or exported, but they can be useful to a user.
10
 *
11
 * @since 1.6
12
 *
13
 * @author Markus Krötzsch
14
 * @ingroup SMWDataItems
15
 */
16
class SMWDIError extends SMWDataItem {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
18
	/**
19
	 * List of error messages. Should always be safe for HTML.
20
	 * @var array of strings
21
	 */
22
	protected $m_errors;
23
24 1
	public function __construct( $errors ) {
25 1
		$this->m_errors = $errors;
26 1
	}
27
28
	public function getDIType() {
29
		return SMWDataItem::TYPE_ERROR;
30
	}
31
32
	public function getErrors() {
33
		return $this->m_errors;
34
	}
35
36
	public function getSortKey() {
37
		return 'error';
38
	}
39
40
	public function getString() {
41
		return $this->getSerialization();
42
	}
43
44
	public function getSerialization() {
45
		return serialize( $this->m_errors );
46
	}
47
48
	/**
49
	 * Create a data item from the provided serialization string and type
50
	 * ID.
51
	 * @todo Be more careful with unserialization. It can create E_NOTICEs.
52
	 * @return SMWDIError
53
	 */
54
	public static function doUnserialize( $serialization ) {
55
		return new SMWDIError( unserialize( $serialization ) );
56
	}
57
58
	public function equals( SMWDataItem $di ) {
59
		if ( $di->getDIType() !== SMWDataItem::TYPE_ERROR ) {
60
			return false;
61
		}
62
63
		return $di->getSerialization() === $this->getSerialization();
64
	}
65
}
66