|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SESP\PropertyAnnotators; |
|
4
|
|
|
|
|
5
|
|
|
use SMW\DIProperty; |
|
6
|
|
|
use SMW\SemanticData; |
|
7
|
|
|
use SMWDataItem as DataItem; |
|
8
|
|
|
use SMWDITime as DITime; |
|
9
|
|
|
use SESP\PropertyAnnotator; |
|
10
|
|
|
use SESP\AppFactory; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @private |
|
14
|
|
|
* @ingroup SESP |
|
15
|
|
|
* |
|
16
|
|
|
* @license GNU GPL v2+ |
|
17
|
|
|
*/ |
|
18
|
|
|
class ApprovedDatePropertyAnnotator implements PropertyAnnotator { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Predefined property ID |
|
22
|
|
|
*/ |
|
23
|
|
|
const PROP_ID = '___APPROVEDDATE'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var AppFactory |
|
27
|
|
|
*/ |
|
28
|
|
|
private $appFactory; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Integer|null |
|
32
|
|
|
*/ |
|
33
|
|
|
private $approvedDate; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param AppFactory $appFactory |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct( AppFactory $appFactory ) { |
|
39
|
|
|
$this->appFactory = $appFactory; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @since 2.0 |
|
44
|
|
|
* |
|
45
|
|
|
* @param Integer $approvedDate |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setApprovedDate( $approvedDate ) { |
|
48
|
|
|
$this->approvedDate = $approvedDate; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritDoc} |
|
53
|
|
|
*/ |
|
54
|
|
|
public function isAnnotatorFor( DIProperty $property ) { |
|
55
|
|
|
return $property->getKey() === self::PROP_ID; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritDoc} |
|
60
|
|
|
*/ |
|
61
|
|
|
public function addAnnotation( |
|
62
|
|
|
DIProperty $property, SemanticData $semanticData |
|
63
|
|
|
) { |
|
64
|
|
|
if ( $this->approvedDate === null && class_exists( 'ApprovedRevs' ) ) { |
|
65
|
|
|
$logReader = new LogReader( |
|
66
|
|
|
$semanticData->getSubject()->getTitle(), 'approval' |
|
67
|
|
|
); |
|
68
|
|
|
$this->approvedDate = $logReader->getDate(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
if ( $this->approvedDate ) { |
|
72
|
|
|
$dataItem = new DITime( |
|
73
|
|
|
DITime::CM_GREGORIAN, |
|
74
|
|
|
$this->approvedDate->format( 'Y' ), |
|
75
|
|
|
$this->approvedDate->format( 'm' ), |
|
76
|
|
|
$this->approvedDate->format( 'd' ), |
|
77
|
|
|
$this->approvedDate->format( 'H' ), |
|
78
|
|
|
$this->approvedDate->format( 'i' ) |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if ( $dataItem instanceof DataItem ) { |
|
83
|
|
|
$semanticData->addPropertyObjectValue( $property, $dataItem ); |
|
|
|
|
|
|
84
|
|
|
} else { |
|
85
|
|
|
$semanticData->removeProperty( $property ); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: