OclcResponseParser::doFilterResponseFor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 26
ccs 16
cts 16
cp 1
rs 9.7666
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace SCI\FilteredMetadata;
4
5
use Onoi\Remi\Oclc\OclcFilteredHttpResponseParser;
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 OclcResponseParser implements ResponseParser {
16
17
	/**
18
	 * @var OclcFilteredHttpResponseParser
19
	 */
20
	private $oclcFilteredHttpResponseParser;
21
22
	/**
23
	 * @since 1.0
24
	 *
25
	 * @param OclcFilteredHttpResponseParser $oclcFilteredHttpResponseParser
26
	 */
27 6
	public function __construct( OclcFilteredHttpResponseParser $oclcFilteredHttpResponseParser ) {
28 6
		$this->oclcFilteredHttpResponseParser = $oclcFilteredHttpResponseParser;
29 6
	}
30
31
	/**
32
	 * @since 1.0
33
	 *
34
	 * {@inheritDoc}
35
	 */
36 1
	public function usesCache() {
37 1
		return $this->oclcFilteredHttpResponseParser->usesCache();
38
	}
39
40
	/**
41
	 * @since 1.0
42
	 *
43
	 * {@inheritDoc}
44
	 */
45 1
	public function getMessages() {
46 1
		return $this->oclcFilteredHttpResponseParser->getMessages();
47
	}
48
49
	/**
50
	 * @since 1.0
51
	 *
52
	 * {@inheritDoc}
53
	 */
54 3
	public function getFilteredRecord() {
55 3
		return $this->oclcFilteredHttpResponseParser->getFilteredRecord();
56
	}
57
58
	/**
59
	 * @since 1.0
60
	 *
61
	 * {@inheritDoc}
62
	 */
63 1
	public function getRawResponse( $oclcID ) {
64 1
		return $this->oclcFilteredHttpResponseParser->getRawResponse( $oclcID );
65
	}
66
67
	/**
68
	 * @since 1.0
69
	 *
70
	 * {@inheritDoc}
71
	 */
72 4
	public function doFilterResponseFor( $oclcID ) {
73
74 4
		$resourceIdentifierFactory = new ResourceIdentifierFactory();
75
76 4
		$oclcValue = $resourceIdentifierFactory->newResourceIdentifierStringValueForType( 'oclc' );
77 4
		$oclcValue->setUserValue( $oclcID );
78
79 4
		if ( !$oclcValue->isValid() ) {
80 1
			return $this->oclcFilteredHttpResponseParser->addMessage( $oclcValue->getErrors() );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->oclcFilteredHttpR...oclcValue->getErrors()) targeting Onoi\Remi\FilteredHttpResponseParser::addMessage() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
81
		}
82
83 3
		$oclcID = $oclcValue->getWikiValue();
84
85 3
		$this->oclcFilteredHttpResponseParser->doFilterResponseFor( $oclcID );
86 3
		$filteredRecord = $this->oclcFilteredHttpResponseParser->getFilteredRecord();
87
88 3
		$filteredRecord->setTitleForPageCreation( 'OCLC:' . $oclcID );
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

88
		$filteredRecord->/** @scrutinizer ignore-call */ 
89
                   setTitleForPageCreation( 'OCLC:' . $oclcID );
Loading history...
89 3
		$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

89
		$filteredRecord->/** @scrutinizer ignore-call */ 
90
                   setSciteTransclusionHead(
Loading history...
90 3
			'OCLC' . $oclcID
91
		);
92
93 3
		$filteredRecord->addSearchMatchSet( 'oclc', $oclcID );
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

93
		$filteredRecord->/** @scrutinizer ignore-call */ 
94
                   addSearchMatchSet( 'oclc', $oclcID );
Loading history...
94 3
		$filteredRecord->set( 'oclc', $oclcID );
95
96 3
		$dateTimeUtc = new \DateTime( 'now', new \DateTimeZone( 'UTC' ) );
97 3
		$filteredRecord->set( 'retrieved-on', $dateTimeUtc->format( 'Y-m-d' ) );
98 3
	}
99
100
}
101