Passed
Push — master ( 3a7c7a...fe0bb9 )
by Sam
03:04
created

Edition::getWikisourceIndexPages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Samwilson\SimpleWikidata\Items;
4
5
use Samwilson\SimpleWikidata\Item;
6
7
class Edition extends Item {
8
9
	const PROP_WIKISOURCE_INDEX_PAGE = 'P1957';
10
	const PROP_SCANNED_FILE_ON_COMMONS = 'P996';
11
	const PROP_INTERNET_ARCHIVE_ID = 'P724';
12
	const PROP_PUBLICATION_DATE = '';
13
	const PROP_PUBLISHER = '';
14
15
	/**
16
	 * @return string
17
	 */
18
	public function getPublicationYear() {
19
		$publicationYears = $this->getPropertyOfTypeTime( static::PROP_PUBLICATION_DATE );
20
		return $publicationYears[0]->getDateTime()->format( 'Y' );
21
	}
22
23
	/**
24
	 * @return \Samwilson\SimpleWikidata\Properties\Item[]
25
	 */
26
	public function getPublishers() {
27
		return $this->getPropertyOfTypeItem( static::PROP_PUBLISHER );
28
	}
29
30
	/**
31
	 * @return array|bool
32
	 */
33
	public function getWikisourceIndexPages() {
34
		return $this->getPropertyOfTypeUrl( $this->getId(), static::PROP_WIKISOURCE_INDEX_PAGE );
35
	}
36
37
	/**
38
	 * @return array
39
	 */
40
	public function internetArchiveIds() {
41
		return $this->getPropertyOfTypeExternalIdentifier(
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getPropert...OP_INTERNET_ARCHIVE_ID) could also return false which is incompatible with the documented return type array. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
42
			$this->getId(),
43
			self::PROP_INTERNET_ARCHIVE_ID
44
		);
45
	}
46
47
	/**
48
	 * Get information about the Wikisource sitelink.
49
	 * An edition should only ever be present on one Wikisource.
50
	 * @return string[]
51
	 */
52
	public function getWikisourceLink() {
53
		$entity = $this->getEntity( $this->id );
54
		if ( !isset( $entity['sitelinks'] ) ) {
55
			return [];
56
		}
57
		foreach ( $entity['sitelinks'] as $sitelink ) {
58
			if ( strpos( $sitelink['site'], 'wikisource' ) !== false ) {
59
				$lang = substr( $sitelink['site'], 0, strpos( $sitelink['site'], 'wikisource' ) );
60
				return [
61
					'title' => $sitelink['title'],
62
					'url' => "https://$lang.wikisource.org/wiki/".$sitelink['title'],
63
					'lang' => $lang,
64
				];
65
			}
66
		}
67
		return [];
68
	}
69
70
}
71