@@ -13,31 +13,31 @@ discard block |
||
| 13 | 13 | * @link https://www.wikidata.org/wiki/Wikidata:WikiProject_Railways |
| 14 | 14 | */ |
| 15 | 15 | class RailwayStation extends \Samwilson\SimpleWikidata\Item { |
| 16 | - // @codingStandardsIgnoreEnd |
|
| 17 | - /** |
|
| 18 | - * Every subclass of Item should define its 'instance of' ID. |
|
| 19 | - */ |
|
| 20 | - const INSTANCE_OF = 'Q55488'; |
|
| 16 | + // @codingStandardsIgnoreEnd |
|
| 17 | + /** |
|
| 18 | + * Every subclass of Item should define its 'instance of' ID. |
|
| 19 | + */ |
|
| 20 | + const INSTANCE_OF = 'Q55488'; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * It can then contain any type-specific methods that are required. |
|
| 24 | - * @return RailwayStation[] |
|
| 25 | - */ |
|
| 26 | - public function hasAdjacentStations() { |
|
| 27 | - return $this->getPropertyOfTypeItem( 'P197' ); |
|
| 28 | - } |
|
| 22 | + /** |
|
| 23 | + * It can then contain any type-specific methods that are required. |
|
| 24 | + * @return RailwayStation[] |
|
| 25 | + */ |
|
| 26 | + public function hasAdjacentStations() { |
|
| 27 | + return $this->getPropertyOfTypeItem( 'P197' ); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Including queries. |
|
| 32 | - * @return RailwayStation[] |
|
| 33 | - */ |
|
| 34 | - public function isAdjacentTo() { |
|
| 35 | - $sparql = "SELECT ?item WHERE { ?item wdt:P197 wd:" . $this->getId() . " }"; |
|
| 36 | - $query = new \Samwilson\SimpleWikidata\Query( $sparql, $this->lang, $this->cache ); |
|
| 37 | - // Each query result will also be a RailwayStation |
|
| 38 | - // (if they're correctly recorded as such on Wikidata). |
|
| 39 | - return $query->getItems(); |
|
| 40 | - } |
|
| 30 | + /** |
|
| 31 | + * Including queries. |
|
| 32 | + * @return RailwayStation[] |
|
| 33 | + */ |
|
| 34 | + public function isAdjacentTo() { |
|
| 35 | + $sparql = "SELECT ?item WHERE { ?item wdt:P197 wd:" . $this->getId() . " }"; |
|
| 36 | + $query = new \Samwilson\SimpleWikidata\Query( $sparql, $this->lang, $this->cache ); |
|
| 37 | + // Each query result will also be a RailwayStation |
|
| 38 | + // (if they're correctly recorded as such on Wikidata). |
|
| 39 | + return $query->getItems(); |
|
| 40 | + } |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // Then the class must register itself. |
@@ -47,5 +47,5 @@ discard block |
||
| 47 | 47 | /** @var RailwayStation $eustonStation */ |
| 48 | 48 | $eustonStation = \Samwilson\SimpleWikidata\Item::factory( 'Q800751', 'en', $cache ); |
| 49 | 49 | echo $eustonStation->getLabel() |
| 50 | - . " has " . count( $eustonStation->hasAdjacentStations() ) . " adjacent stations" |
|
| 51 | - . " and is adjacent to " . count( $eustonStation->isAdjacentTo() ) . " stations.\n"; |
|
| 50 | + . " has " . count( $eustonStation->hasAdjacentStations() ) . " adjacent stations" |
|
| 51 | + . " and is adjacent to " . count( $eustonStation->isAdjacentTo() ) . " stations.\n"; |
|
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | require_once __DIR__ . '/../vendor/autoload.php'; |
| 4 | 4 | |
| 5 | 5 | // Any PSR6 cache can be used. |
| 6 | -$cache = new Stash\Pool( new \Stash\Driver\FileSystem() ); |
|
| 6 | +$cache = new Stash\Pool(new \Stash\Driver\FileSystem()); |
|
| 7 | 7 | |
| 8 | 8 | // @codingStandardsIgnoreStart |
| 9 | 9 | /** |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * @return RailwayStation[] |
| 25 | 25 | */ |
| 26 | 26 | public function hasAdjacentStations() { |
| 27 | - return $this->getPropertyOfTypeItem( 'P197' ); |
|
| 27 | + return $this->getPropertyOfTypeItem('P197'); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public function isAdjacentTo() { |
| 35 | 35 | $sparql = "SELECT ?item WHERE { ?item wdt:P197 wd:" . $this->getId() . " }"; |
| 36 | - $query = new \Samwilson\SimpleWikidata\Query( $sparql, $this->lang, $this->cache ); |
|
| 36 | + $query = new \Samwilson\SimpleWikidata\Query($sparql, $this->lang, $this->cache); |
|
| 37 | 37 | // Each query result will also be a RailwayStation |
| 38 | 38 | // (if they're correctly recorded as such on Wikidata). |
| 39 | 39 | return $query->getItems(); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | // Then we can create items with the factory and use them. |
| 47 | 47 | /** @var RailwayStation $eustonStation */ |
| 48 | -$eustonStation = \Samwilson\SimpleWikidata\Item::factory( 'Q800751', 'en', $cache ); |
|
| 48 | +$eustonStation = \Samwilson\SimpleWikidata\Item::factory('Q800751', 'en', $cache); |
|
| 49 | 49 | echo $eustonStation->getLabel() |
| 50 | - . " has " . count( $eustonStation->hasAdjacentStations() ) . " adjacent stations" |
|
| 51 | - . " and is adjacent to " . count( $eustonStation->isAdjacentTo() ) . " stations.\n"; |
|
| 50 | + . " has " . count($eustonStation->hasAdjacentStations()) . " adjacent stations" |
|
| 51 | + . " and is adjacent to " . count($eustonStation->isAdjacentTo()) . " stations.\n"; |
|
@@ -11,12 +11,12 @@ |
||
| 11 | 11 | $query = new \Samwilson\SimpleWikidata\Query( $sparql, 'en', $cache ); |
| 12 | 12 | $hills = $query->getItems(); |
| 13 | 13 | foreach ( $hills as $hill ) { |
| 14 | - $heights = $hill->getPropertyOfTypeQuantity( 'P2044' ); |
|
| 15 | - if ( !$heights ) { |
|
| 16 | - echo "No heights found for " . $hill->getLabel() . "\n"; |
|
| 17 | - continue; |
|
| 18 | - } |
|
| 19 | - $height = array_shift( $heights ); |
|
| 20 | - echo $hill->getLabel() . " is " |
|
| 21 | - . $height['amount'] . " " . $height['unit']->getLabel() . " high.\n"; |
|
| 14 | + $heights = $hill->getPropertyOfTypeQuantity( 'P2044' ); |
|
| 15 | + if ( !$heights ) { |
|
| 16 | + echo "No heights found for " . $hill->getLabel() . "\n"; |
|
| 17 | + continue; |
|
| 18 | + } |
|
| 19 | + $height = array_shift( $heights ); |
|
| 20 | + echo $hill->getLabel() . " is " |
|
| 21 | + . $height['amount'] . " " . $height['unit']->getLabel() . " high.\n"; |
|
| 22 | 22 | } |
@@ -3,20 +3,20 @@ |
||
| 3 | 3 | require_once __DIR__ . '/../vendor/autoload.php'; |
| 4 | 4 | |
| 5 | 5 | // Any PSR6 cache can be used. |
| 6 | -$cache = new Stash\Pool( new \Stash\Driver\FileSystem() ); |
|
| 6 | +$cache = new Stash\Pool(new \Stash\Driver\FileSystem()); |
|
| 7 | 7 | |
| 8 | 8 | $sparql = 'SELECT ?item WHERE { |
| 9 | 9 | ?item wdt:P31 wd:Q54050 |
| 10 | 10 | } LIMIT 5'; |
| 11 | -$query = new \Samwilson\SimpleWikidata\Query( $sparql, 'en', $cache ); |
|
| 11 | +$query = new \Samwilson\SimpleWikidata\Query($sparql, 'en', $cache); |
|
| 12 | 12 | $hills = $query->getItems(); |
| 13 | -foreach ( $hills as $hill ) { |
|
| 14 | - $heights = $hill->getPropertyOfTypeQuantity( 'P2044' ); |
|
| 15 | - if ( !$heights ) { |
|
| 13 | +foreach ($hills as $hill) { |
|
| 14 | + $heights = $hill->getPropertyOfTypeQuantity('P2044'); |
|
| 15 | + if (!$heights) { |
|
| 16 | 16 | echo "No heights found for " . $hill->getLabel() . "\n"; |
| 17 | 17 | continue; |
| 18 | 18 | } |
| 19 | - $height = array_shift( $heights ); |
|
| 19 | + $height = array_shift($heights); |
|
| 20 | 20 | echo $hill->getLabel() . " is " |
| 21 | 21 | . $height['amount'] . " " . $height['unit']->getLabel() . " high.\n"; |
| 22 | 22 | } |
@@ -9,9 +9,9 @@ |
||
| 9 | 9 | $search = new \Samwilson\SimpleWikidata\Search( 'pride and prejudice', 'en', $cache ); |
| 10 | 10 | $items = $search->getItems( 3 ); |
| 11 | 11 | foreach ( $items as $item ) { |
| 12 | - $instanceOf = $item->getPropertyOfTypeItem( |
|
| 13 | - \Samwilson\SimpleWikidata\Item::PROP_INSTANCE_OF |
|
| 14 | - ); |
|
| 15 | - $instanceOfLabel = isset( $instanceOf[0] ) ? $instanceOf[0]->getItem()->getLabel() : 'UNKNOWN'; |
|
| 16 | - echo $item->getLabel() . ' (' . $instanceOfLabel . ')' . "\n"; |
|
| 12 | + $instanceOf = $item->getPropertyOfTypeItem( |
|
| 13 | + \Samwilson\SimpleWikidata\Item::PROP_INSTANCE_OF |
|
| 14 | + ); |
|
| 15 | + $instanceOfLabel = isset( $instanceOf[0] ) ? $instanceOf[0]->getItem()->getLabel() : 'UNKNOWN'; |
|
| 16 | + echo $item->getLabel() . ' (' . $instanceOfLabel . ')' . "\n"; |
|
| 17 | 17 | } |
@@ -3,15 +3,15 @@ |
||
| 3 | 3 | require_once __DIR__ . '/../vendor/autoload.php'; |
| 4 | 4 | |
| 5 | 5 | // Any PSR6 cache can be used. |
| 6 | -$cache = new Stash\Pool( new \Stash\Driver\FileSystem() ); |
|
| 6 | +$cache = new Stash\Pool(new \Stash\Driver\FileSystem()); |
|
| 7 | 7 | |
| 8 | 8 | // Search for anything. |
| 9 | -$search = new \Samwilson\SimpleWikidata\Search( 'pride and prejudice', 'en', $cache ); |
|
| 10 | -$items = $search->getItems( 3 ); |
|
| 11 | -foreach ( $items as $item ) { |
|
| 9 | +$search = new \Samwilson\SimpleWikidata\Search('pride and prejudice', 'en', $cache); |
|
| 10 | +$items = $search->getItems(3); |
|
| 11 | +foreach ($items as $item) { |
|
| 12 | 12 | $instanceOf = $item->getPropertyOfTypeItem( |
| 13 | 13 | \Samwilson\SimpleWikidata\Item::PROP_INSTANCE_OF |
| 14 | 14 | ); |
| 15 | - $instanceOfLabel = isset( $instanceOf[0] ) ? $instanceOf[0]->getItem()->getLabel() : 'UNKNOWN'; |
|
| 15 | + $instanceOfLabel = isset($instanceOf[0]) ? $instanceOf[0]->getItem()->getLabel() : 'UNKNOWN'; |
|
| 16 | 16 | echo $item->getLabel() . ' (' . $instanceOfLabel . ')' . "\n"; |
| 17 | 17 | } |
@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | $datesOfBirth = $princeCharles->getDatesOfBirth(); |
| 18 | 18 | echo " Date of birth: " . $datesOfBirth[0]->getDateTime()->format( 'j F, Y' ) . " "; |
| 19 | 19 | foreach ( $datesOfBirth[0]->getReferences() as $ref ) { |
| 20 | - if ( $ref->statedIn() ) { |
|
| 21 | - echo "[$refNum]"; |
|
| 22 | - $references[$refNum] = $ref; |
|
| 23 | - } |
|
| 20 | + if ( $ref->statedIn() ) { |
|
| 21 | + echo "[$refNum]"; |
|
| 22 | + $references[$refNum] = $ref; |
|
| 23 | + } |
|
| 24 | 24 | } |
| 25 | 25 | echo "\n"; |
| 26 | 26 | |
@@ -28,13 +28,13 @@ discard block |
||
| 28 | 28 | $fathers = $princeCharles->fathers(); |
| 29 | 29 | echo " Father: " . $fathers[0]->getItem()->getLabel() . " "; |
| 30 | 30 | foreach ( $fathers[0]->getReferences() as $ref ) { |
| 31 | - if ( $ref->statedIn() ) { |
|
| 32 | - echo "[$refNum]"; |
|
| 33 | - $references[$refNum] = $ref; |
|
| 34 | - } |
|
| 31 | + if ( $ref->statedIn() ) { |
|
| 32 | + echo "[$refNum]"; |
|
| 33 | + $references[$refNum] = $ref; |
|
| 34 | + } |
|
| 35 | 35 | } |
| 36 | 36 | echo "\n"; |
| 37 | 37 | |
| 38 | 38 | foreach ( $references as $refNum => $ref ) { |
| 39 | - echo " [$refNum] - " . $ref->statedIn()->getLabel() . "\n"; |
|
| 39 | + echo " [$refNum] - " . $ref->statedIn()->getLabel() . "\n"; |
|
| 40 | 40 | } |
@@ -3,10 +3,10 @@ discard block |
||
| 3 | 3 | require_once __DIR__ . '/../vendor/autoload.php'; |
| 4 | 4 | |
| 5 | 5 | // Any PSR6 cache can be used. |
| 6 | -$cache = new Stash\Pool( new \Stash\Driver\FileSystem() ); |
|
| 6 | +$cache = new Stash\Pool(new \Stash\Driver\FileSystem()); |
|
| 7 | 7 | |
| 8 | 8 | /** @var \Samwilson\SimpleWikidata\Items\Human $princeCharles */ |
| 9 | -$princeCharles = Samwilson\SimpleWikidata\Item::factory( 'Q43274', 'en', $cache ); |
|
| 9 | +$princeCharles = Samwilson\SimpleWikidata\Item::factory('Q43274', 'en', $cache); |
|
| 10 | 10 | |
| 11 | 11 | echo $princeCharles->getLabel() . ":\n"; |
| 12 | 12 | |
@@ -15,9 +15,9 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | /** @var \Samwilson\SimpleWikidata\Properties\Time[] $datesOfBirth */ |
| 17 | 17 | $datesOfBirth = $princeCharles->getDatesOfBirth(); |
| 18 | -echo " Date of birth: " . $datesOfBirth[0]->getDateTime()->format( 'j F, Y' ) . " "; |
|
| 19 | -foreach ( $datesOfBirth[0]->getReferences() as $ref ) { |
|
| 20 | - if ( $ref->statedIn() ) { |
|
| 18 | +echo " Date of birth: " . $datesOfBirth[0]->getDateTime()->format('j F, Y') . " "; |
|
| 19 | +foreach ($datesOfBirth[0]->getReferences() as $ref) { |
|
| 20 | + if ($ref->statedIn()) { |
|
| 21 | 21 | echo "[$refNum]"; |
| 22 | 22 | $references[$refNum] = $ref; |
| 23 | 23 | } |
@@ -27,14 +27,14 @@ discard block |
||
| 27 | 27 | /** @var \Samwilson\SimpleWikidata\Properties\Item[] $fathers */ |
| 28 | 28 | $fathers = $princeCharles->fathers(); |
| 29 | 29 | echo " Father: " . $fathers[0]->getItem()->getLabel() . " "; |
| 30 | -foreach ( $fathers[0]->getReferences() as $ref ) { |
|
| 31 | - if ( $ref->statedIn() ) { |
|
| 30 | +foreach ($fathers[0]->getReferences() as $ref) { |
|
| 31 | + if ($ref->statedIn()) { |
|
| 32 | 32 | echo "[$refNum]"; |
| 33 | 33 | $references[$refNum] = $ref; |
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | echo "\n"; |
| 37 | 37 | |
| 38 | -foreach ( $references as $refNum => $ref ) { |
|
| 38 | +foreach ($references as $refNum => $ref) { |
|
| 39 | 39 | echo " [$refNum] - " . $ref->statedIn()->getLabel() . "\n"; |
| 40 | 40 | } |