These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace SMW\PropertyAnnotator; |
||
4 | |||
5 | use SMW\DIProperty; |
||
6 | use SMW\DIWikiPage; |
||
7 | use SMW\MediaWiki\RedirectTargetFinder; |
||
8 | use SMW\PropertyAnnotator; |
||
9 | |||
10 | /** |
||
11 | * Handling redirect annotation |
||
12 | * |
||
13 | * @license GNU GPL v2+ |
||
14 | * @since 1.9 |
||
15 | * |
||
16 | * @author mwjames |
||
17 | */ |
||
18 | class RedirectPropertyAnnotator extends PropertyAnnotatorDecorator { |
||
19 | |||
20 | /** |
||
21 | * @var RedirectTargetFinder |
||
22 | */ |
||
23 | private $redirectTargetFinder; |
||
24 | |||
25 | /** |
||
26 | * @since 1.9 |
||
27 | * |
||
28 | * @param PropertyAnnotator $propertyAnnotator |
||
29 | * @param RedirectTargetFinder $redirectTargetFinder |
||
30 | */ |
||
31 | 193 | public function __construct( PropertyAnnotator $propertyAnnotator, RedirectTargetFinder $redirectTargetFinder ) { |
|
32 | 193 | parent::__construct( $propertyAnnotator ); |
|
33 | 193 | $this->redirectTargetFinder = $redirectTargetFinder; |
|
34 | 193 | } |
|
35 | |||
36 | /** |
||
37 | * @see PropertyAnnotatorDecorator::addPropertyValues |
||
38 | */ |
||
39 | 192 | protected function addPropertyValues() { |
|
40 | |||
41 | 192 | if ( !$this->redirectTargetFinder->hasRedirectTarget() ) { |
|
42 | 190 | return; |
|
43 | } |
||
44 | |||
45 | 26 | $this->getSemanticData()->addPropertyObjectValue( |
|
46 | 26 | new DIProperty( '_REDI' ), |
|
47 | 26 | DIWikiPage::newFromTitle( $this->redirectTargetFinder->getRedirectTarget() ) |
|
0 ignored issues
–
show
|
|||
48 | ); |
||
49 | 26 | } |
|
50 | |||
51 | } |
||
52 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: