OLResponseParser::getMessages()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace SCI\FilteredMetadata;
4
5
use Onoi\Remi\OpenLibrary\OLFilteredHttpResponseParser;
6
use Onoi\Remi\ResponseParser;
7
use SCI\DataValues\ResourceIdentifierFactory;
8
9
/**
10
 * @license GNU GPL v2+
11
 * @since 1.0
12
 *
13
 * @author mwjames
14
 */
15
class OLResponseParser implements ResponseParser {
16
17
	/**
18
	 * @var OLFilteredHttpResponseParser
19
	 */
20
	private $olFilteredHttpResponseParser;
21
22
	/**
23
	 * @since 1.0
24
	 *
25
	 * @param OLFilteredHttpResponseParser $olFilteredHttpResponseParser
26
	 */
27 6
	public function __construct( OLFilteredHttpResponseParser $olFilteredHttpResponseParser ) {
28 6
		$this->olFilteredHttpResponseParser = $olFilteredHttpResponseParser;
29 6
	}
30
31
	/**
32
	 * @since 1.0
33
	 *
34
	 * {@inheritDoc}
35
	 */
36 1
	public function usesCache() {
37 1
		return $this->olFilteredHttpResponseParser->usesCache();
38
	}
39
40
	/**
41
	 * @since 1.0
42
	 *
43
	 * {@inheritDoc}
44
	 */
45 1
	public function getMessages() {
46 1
		return $this->olFilteredHttpResponseParser->getMessages();
47
	}
48
49
	/**
50
	 * @since 1.0
51
	 *
52
	 * {@inheritDoc}
53
	 */
54 3
	public function getFilteredRecord() {
55 3
		return $this->olFilteredHttpResponseParser->getFilteredRecord();
56
	}
57
58
	/**
59
	 * @since 1.0
60
	 *
61
	 * {@inheritDoc}
62
	 */
63 1
	public function getRawResponse( $id ) {
64 1
		return $this->olFilteredHttpResponseParser->getRawResponse( $id );
65
	}
66
67
	/**
68
	 * @since 1.0
69
	 *
70
	 * {@inheritDoc}
71
	 */
72 4
	public function doFilterResponseFor( $olID ) {
73
74 4
		$this->olFilteredHttpResponseParser->doFilterResponseFor( $olID );
75 4
		$filteredRecord = $this->olFilteredHttpResponseParser->getFilteredRecord();
76
77
		// Fetch the OLID has one could search for an ISBN as well
78 4
		if ( $filteredRecord->has( 'olid' ) ) {
79 2
			$olID = $filteredRecord->get( 'olid' );
80
		}
81
82 4
		if ( is_array( $olID ) ) {
83 2
			$olID = end( $olID );
84
		}
85
86 4
		$filteredRecord->setTitleForPageCreation(
0 ignored issues
show
introduced by
The method setTitleForPageCreation() does not exist on Onoi\Remi\FilteredRecord. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
		$filteredRecord->/** @scrutinizer ignore-call */ 
87
                   setTitleForPageCreation(
Loading history...
87 4
			'OL:' . str_replace( 'OL', '', $olID )
88
		);
89
90 4
		$filteredRecord->setSciteTransclusionHead(
0 ignored issues
show
introduced by
The method setSciteTransclusionHead() does not exist on Onoi\Remi\FilteredRecord. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
		$filteredRecord->/** @scrutinizer ignore-call */ 
91
                   setSciteTransclusionHead(
Loading history...
91 4
			$olID
92
		);
93
94 4
		$filteredRecord->addSearchMatchSet( 'olid', $olID );
0 ignored issues
show
introduced by
The method addSearchMatchSet() does not exist on Onoi\Remi\FilteredRecord. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
		$filteredRecord->/** @scrutinizer ignore-call */ 
95
                   addSearchMatchSet( 'olid', $olID );
Loading history...
95
96 4
		if ( $filteredRecord->has( 'lccn' ) ) {
97 2
			$filteredRecord->addSearchMatchSet(
98 2
				'lccn',
99 2
				$filteredRecord->get( 'lccn' )
100
			);
101
		}
102
103 4
		$dateTimeUtc = new \DateTime( 'now', new \DateTimeZone( 'UTC' ) );
104 4
		$filteredRecord->set( 'retrieved-on', $dateTimeUtc->format( 'Y-m-d' ) );
105 4
	}
106
107
}
108