ViafResponseParser::__construct()   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 1
crap 1
1
<?php
2
3
namespace SCI\FilteredMetadata;
4
5
use Onoi\Remi\Viaf\ViafFilteredHttpResponseParser;
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 ViafResponseParser implements ResponseParser {
16
17
	/**
18
	 * @var ViafFilteredHttpResponseParser
19
	 */
20
	private $viafFilteredHttpResponseParser;
21
22
	/**
23
	 * @since 1.0
24
	 *
25
	 * @param ViafFilteredHttpResponseParser $viafFilteredHttpResponseParser
26
	 */
27 5
	public function __construct( ViafFilteredHttpResponseParser $viafFilteredHttpResponseParser ) {
28 5
		$this->viafFilteredHttpResponseParser = $viafFilteredHttpResponseParser;
29 5
	}
30
31
	/**
32
	 * @since 1.0
33
	 *
34
	 * {@inheritDoc}
35
	 */
36 1
	public function usesCache() {
37 1
		return $this->viafFilteredHttpResponseParser->usesCache();
38
	}
39
40
	/**
41
	 * @since 1.0
42
	 *
43
	 * {@inheritDoc}
44
	 */
45 1
	public function getMessages() {
46 1
		return $this->viafFilteredHttpResponseParser->getMessages();
47
	}
48
49
	/**
50
	 * @since 1.0
51
	 *
52
	 * {@inheritDoc}
53
	 */
54 2
	public function getFilteredRecord() {
55 2
		return $this->viafFilteredHttpResponseParser->getFilteredRecord();
56
	}
57
58
	/**
59
	 * @since 1.0
60
	 *
61
	 * {@inheritDoc}
62
	 */
63 1
	public function getRawResponse( $viafID ) {
64 1
		return $this->viafFilteredHttpResponseParser->getRawResponse( $viafID );
65
	}
66
67
	/**
68
	 * @since 1.0
69
	 *
70
	 * {@inheritDoc}
71
	 */
72 3
	public function doFilterResponseFor( $viafID ) {
73
74 3
		$resourceIdentifierFactory = new ResourceIdentifierFactory();
75
76 3
		$viafValue = $resourceIdentifierFactory->newResourceIdentifierStringValueForType( 'viaf' );
77 3
		$viafValue->setUserValue( $viafID );
78
79 3
		if ( !$viafValue->isValid() ) {
80 1
			return $this->viafFilteredHttpResponseParser->addMessage( $viafValue->getErrors() );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->viafFilteredHttpR...viafValue->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 2
		$viafID = $viafValue->getWikiValue();
84
85 2
		$this->viafFilteredHttpResponseParser->doFilterResponseFor( $viafID );
86 2
		$filteredRecord = $this->viafFilteredHttpResponseParser->getFilteredRecord();
87
88 2
		$filteredRecord->setTitleForPageCreation( 'VIAF:' . $viafID );
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( 'VIAF:' . $viafID );
Loading history...
89 2
		$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 2
			'VIAF' . $viafID
91
		);
92
93 2
		$filteredRecord->addSearchMatchSet( 'viaf', $viafID );
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( 'viaf', $viafID );
Loading history...
94
95 2
		$dateTimeUtc = new \DateTime( 'now', new \DateTimeZone( 'UTC' ) );
96 2
		$filteredRecord->set( 'retrieved-on', $dateTimeUtc->format( 'Y-m-d' ) );
97 2
	}
98
99
}
100