samwilson /
simple-wikidata
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Samwilson\SimpleWikidata\Items; |
||||||
| 4 | |||||||
| 5 | use Psr\Cache\CacheItemPoolInterface; |
||||||
| 6 | use Samwilson\SimpleWikidata\Item; |
||||||
| 7 | use Samwilson\SimpleWikidata\Query; |
||||||
| 8 | |||||||
| 9 | /** |
||||||
| 10 | * @link |
||||||
| 11 | */ |
||||||
| 12 | class Work extends Item { |
||||||
| 13 | |||||||
| 14 | const ITEM_WORK = 'Q386724'; |
||||||
| 15 | const PROP_SUBTITLE = 'P1680'; |
||||||
| 16 | const PROP_GENRE = 'P136'; |
||||||
| 17 | const PROP_SUBJECT = 'P921'; |
||||||
| 18 | |||||||
| 19 | /** |
||||||
| 20 | * @param string $lang ISO639 language code. |
||||||
| 21 | * @param CacheItemPoolInterface $cache The cache. |
||||||
| 22 | * @return array|Item[] |
||||||
| 23 | */ |
||||||
| 24 | public static function getBookTypes( $lang = 'en', $cache ) { |
||||||
| 25 | $sparql = "SELECT ?item WHERE { |
||||||
| 26 | ?item wdt:P279 wd:Q571 . |
||||||
| 27 | ?item rdfs:label ?label . |
||||||
| 28 | FILTER(LANG(?label) = '$lang') . |
||||||
| 29 | } ORDER BY ?label "; |
||||||
| 30 | $query = new Query( $sparql, $lang ); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 31 | $query->setCache( $cache ); |
||||||
|
0 ignored issues
–
show
The method
setCache() does not exist on Samwilson\SimpleWikidata\Query.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 32 | $bookType = Item::factory( self::ITEM_WORK, $lang, $cache ); |
||||||
| 33 | return [ $bookType ] + $query->getItems(); |
||||||
| 34 | } |
||||||
| 35 | |||||||
| 36 | /** |
||||||
| 37 | * @return bool|string |
||||||
| 38 | */ |
||||||
| 39 | public function getSubtitle() { |
||||||
| 40 | return $this->getPropertyOfTypeText( self::PROP_SUBTITLE ); |
||||||
| 41 | } |
||||||
| 42 | |||||||
| 43 | /** |
||||||
| 44 | * @param string $subtitle The new subtitle. |
||||||
| 45 | */ |
||||||
| 46 | public function setSubtitle( $subtitle ) { |
||||||
| 47 | $this->setPropertyOfTypeText( self::PROP_SUBTITLE, $subtitle ); |
||||||
| 48 | } |
||||||
| 49 | |||||||
| 50 | /** |
||||||
| 51 | * @param string $property A property identifier. |
||||||
| 52 | * @return array |
||||||
| 53 | */ |
||||||
| 54 | public function getPropertyOfTypeItems( $property ) { |
||||||
| 55 | $entity = $this->getEntity( $this->id ); |
||||||
| 56 | if ( !isset( $entity['claims'][ $property ] ) ) { |
||||||
| 57 | return []; |
||||||
| 58 | } |
||||||
| 59 | $items = []; |
||||||
| 60 | foreach ( $entity['claims'][ $property ] as $authorClaim ) { |
||||||
| 61 | $item_id = $authorClaim['mainsnak']['datavalue']['value']['id']; |
||||||
| 62 | $items[] = Item::factory( $item_id, $this->lang, $this->cache ); |
||||||
| 63 | } |
||||||
| 64 | |||||||
| 65 | return $items; |
||||||
| 66 | } |
||||||
| 67 | |||||||
| 68 | /** |
||||||
| 69 | * @return array |
||||||
| 70 | */ |
||||||
| 71 | public function getAuthors() { |
||||||
| 72 | return $this->getPropertyOfTypeItems( self::PROP_AUTHOR ); |
||||||
| 73 | } |
||||||
| 74 | |||||||
| 75 | /** |
||||||
| 76 | * @return Item[] |
||||||
| 77 | */ |
||||||
| 78 | public function getSubjects() { |
||||||
| 79 | return $this->getPropertyOfTypeItems( self::PROP_SUBJECT ); |
||||||
| 80 | } |
||||||
| 81 | |||||||
| 82 | /** |
||||||
| 83 | * @return Item[] |
||||||
| 84 | */ |
||||||
| 85 | public function getEditions() { |
||||||
| 86 | $sparql = "SELECT ?item WHERE {" |
||||||
| 87 | . " ?item wdt:" . Edition::PROP_EDITION_OR_TRANSLATION_OF . " wd:" . $this->getId() |
||||||
| 88 | . "}"; |
||||||
| 89 | $query = new Query( $sparql, $this->lang, $this->cache ); |
||||||
| 90 | $editions = $query->getItems(); |
||||||
| 91 | usort( $editions, function ( Item $a, Item $b ) { |
||||||
| 92 | if ( $a instanceof Edition && $b instanceof Edition ) { |
||||||
| 93 | return $a->getPublicationYear() - $b->getPublicationYear(); |
||||||
| 94 | } |
||||||
| 95 | return 0; |
||||||
| 96 | } ); |
||||||
| 97 | |||||||
| 98 | return $editions; |
||||||
| 99 | } |
||||||
| 100 | |||||||
| 101 | public function newEdition() { |
||||||
| 102 | } |
||||||
| 103 | |||||||
| 104 | } |
||||||
| 105 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.