SemanticMediaWiki /
SemanticExtraSpecialProperties
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 SESP\PropertyAnnotators; |
||
| 4 | |||
| 5 | use SMW\DIProperty; |
||
| 6 | use SMW\DIWikiPage; |
||
| 7 | use SMW\SemanticData; |
||
| 8 | use SMWDataItem as DataItem; |
||
| 9 | use SMWDINumber as DINumber; |
||
| 10 | use SESP\PropertyAnnotator; |
||
| 11 | use SESP\AppFactory; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @private |
||
| 15 | * @ingroup SESP |
||
| 16 | * |
||
| 17 | * @license GNU GPL v2+ |
||
| 18 | * @since 2.0 |
||
| 19 | * |
||
| 20 | * @author mwjames |
||
| 21 | */ |
||
| 22 | class PageContributorsPropertyAnnotator implements PropertyAnnotator { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Predefined property ID |
||
| 26 | */ |
||
| 27 | const PROP_ID = '___EUSER'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var AppFactory |
||
| 31 | */ |
||
| 32 | private $appFactory; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @since 2.0 |
||
| 36 | * |
||
| 37 | * @param AppFactory $appFactory |
||
| 38 | */ |
||
| 39 | 3 | public function __construct( AppFactory $appFactory ) { |
|
| 40 | 3 | $this->appFactory = $appFactory; |
|
| 41 | 3 | } |
|
| 42 | |||
| 43 | /** |
||
| 44 | * @since 2.0 |
||
| 45 | * |
||
| 46 | * {@inheritDoc} |
||
| 47 | */ |
||
| 48 | 1 | public function isAnnotatorFor( DIProperty $property ) { |
|
| 49 | 1 | return $property->getKey() === self::PROP_ID; |
|
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @since 2.0 |
||
| 54 | * |
||
| 55 | * {@inheritDoc} |
||
| 56 | */ |
||
| 57 | 1 | public function addAnnotation( DIProperty $property, SemanticData $semanticData ) { |
|
| 58 | |||
| 59 | 1 | $title = $semanticData->getSubject()->getTitle(); |
|
| 60 | 1 | $page = $this->appFactory->newWikiPage( $title ); |
|
|
0 ignored issues
–
show
|
|||
| 61 | |||
| 62 | 1 | $user = $this->appFactory->newUserFromID( $page->getUser() ); |
|
| 63 | 1 | $authors = $page->getContributors(); |
|
| 64 | |||
| 65 | 1 | $dataItem = null; |
|
|
0 ignored issues
–
show
$dataItem is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the Loading history...
|
|||
| 66 | |||
| 67 | 1 | while ( $user ) { |
|
| 68 | //no anonymous users (hidden users are not returned) |
||
| 69 | 1 | if ( $this->isNotAnonymous( $user ) ) { |
|
| 70 | 1 | $semanticData->addPropertyObjectValue( |
|
| 71 | 1 | $property, |
|
| 72 | 1 | DIWikiPage::newFromTitle( $user->getUserPage() ) |
|
| 73 | 1 | ); |
|
| 74 | 1 | } |
|
| 75 | |||
| 76 | 1 | $user = $authors->current(); |
|
| 77 | 1 | $authors->next(); |
|
| 78 | 1 | } |
|
| 79 | 1 | } |
|
| 80 | |||
| 81 | 1 | private function isNotAnonymous( $user ) { |
|
| 82 | 1 | return !( in_array( 'bot', $user->getRights() ) && $this->appFactory->getOption( 'wgSESPExcludeBots' ) ) && !$user->isAnon(); |
|
| 83 | } |
||
| 84 | |||
| 85 | } |
||
| 86 |
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: