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 | * @var AppFactory |
||
| 26 | */ |
||
| 27 | private $appFactory; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @since 2.0 |
||
| 31 | * |
||
| 32 | * @param AppFactory $appFactory |
||
| 33 | */ |
||
| 34 | public function __construct( AppFactory $appFactory ) { |
||
| 35 | $this->appFactory = $appFactory; |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @since 2.0 |
||
| 40 | * |
||
| 41 | * {@inheritDoc} |
||
| 42 | */ |
||
| 43 | public function isAnnotatorFor( DIProperty $property ) { |
||
| 44 | return $property->getKey() === '___EUSER' ; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @since 2.0 |
||
| 49 | * |
||
| 50 | * {@inheritDoc} |
||
| 51 | */ |
||
| 52 | public function addAnnotation( DIProperty $property, SemanticData $semanticData ) { |
||
| 53 | |||
| 54 | $title = $semanticData->getSubject()->getTitle(); |
||
| 55 | $page = $this->appFactory->newWikiPage( $title ); |
||
|
0 ignored issues
–
show
|
|||
| 56 | |||
| 57 | $user = $this->appFactory->newUserFromID( $page->getUser() ); |
||
| 58 | $authors = $page->getContributors(); |
||
| 59 | |||
| 60 | $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...
|
|||
| 61 | |||
| 62 | while ( $user ) { |
||
| 63 | //no anonymous users (hidden users are not returned) |
||
| 64 | if ( $this->isNotAnonymous( $user ) ) { |
||
| 65 | $semanticData->addPropertyObjectValue( |
||
| 66 | $property, |
||
| 67 | DIWikiPage::newFromTitle( $user->getUserPage() ) |
||
| 68 | ); |
||
| 69 | } |
||
| 70 | |||
| 71 | $user = $authors->current(); |
||
| 72 | $authors->next(); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | private function isNotAnonymous( $user ) { |
||
| 77 | return !( in_array( 'bot', $user->getRights() ) && $this->appFactory->getOption( 'wgSESPExcludeBots' ) ) && !$user->isAnon(); |
||
| 78 | } |
||
| 79 | |||
| 80 | } |
||
| 81 |
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: