CrossRefResponseParser   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 24
c 0
b 0
f 0
dl 0
loc 87
ccs 29
cts 29
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRawResponse() 0 2 1
A usesCache() 0 2 1
A __construct() 0 2 1
A doFilterResponseFor() 0 30 2
A getFilteredRecord() 0 2 1
A getMessages() 0 2 1
1
<?php
2
3
namespace SCI\FilteredMetadata;
4
5
use Onoi\Remi\CrossRef\CrossRefFilteredHttpResponseParser;
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 CrossRefResponseParser implements ResponseParser {
16
17
	/**
18
	 * @var CrossRefFilteredHttpResponseParser
19
	 */
20
	private $crossRefFilteredHttpResponseParser;
21
22
	/**
23
	 * @since 1.0
24
	 *
25
	 * @param CrossRefFilteredHttpResponseParser $crossRefFilteredHttpResponseParser
26
	 */
27 5
	public function __construct( CrossRefFilteredHttpResponseParser $crossRefFilteredHttpResponseParser ) {
28 5
		$this->crossRefFilteredHttpResponseParser = $crossRefFilteredHttpResponseParser;
29 5
	}
30
31
	/**
32
	 * @since 1.0
33
	 *
34
	 * {@inheritDoc}
35
	 */
36 1
	public function usesCache() {
37 1
		return $this->crossRefFilteredHttpResponseParser->usesCache();
38
	}
39
40
	/**
41
	 * @since 1.0
42
	 *
43
	 * {@inheritDoc}
44
	 */
45 1
	public function getMessages() {
46 1
		return $this->crossRefFilteredHttpResponseParser->getMessages();
47
	}
48
49
	/**
50
	 * @since 1.0
51
	 *
52
	 * {@inheritDoc}
53
	 */
54 2
	public function getFilteredRecord() {
55 2
		return $this->crossRefFilteredHttpResponseParser->getFilteredRecord();
56
	}
57
58
	/**
59
	 * @since 1.0
60
	 *
61
	 * {@inheritDoc}
62
	 */
63 1
	public function getRawResponse( $doi ) {
64 1
		return $this->crossRefFilteredHttpResponseParser->getRawResponse( $doi );
65
	}
66
67
	/**
68
	 * @since 1.0
69
	 *
70
	 * {@inheritDoc}
71
	 */
72 3
	public function doFilterResponseFor( $doi ) {
73
74 3
		$resourceIdentifierFactory = new ResourceIdentifierFactory();
75
76 3
		$doiValue = $resourceIdentifierFactory->newResourceIdentifierStringValueForType( 'doi' );
77 3
		$doiValue->setUserValue( $doi );
78
79 3
		if ( !$doiValue->isValid() ) {
80 1
			return $this->crossRefFilteredHttpResponseParser->addMessage( $doiValue->getErrors() );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->crossRefFilteredH...$doiValue->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
		$doi = $doiValue->getWikiValue();
84
85 2
		$this->crossRefFilteredHttpResponseParser->doFilterResponseFor( $doi );
86 2
		$filteredRecord = $this->crossRefFilteredHttpResponseParser->getFilteredRecord();
87
88 2
		$filteredRecord->setTitleForPageCreation( 'DOI:' . md5( $doi ) );
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( 'DOI:' . md5( $doi ) );
Loading history...
89
90 2
		$filteredRecord->addSearchMatchSet(
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

90
		$filteredRecord->/** @scrutinizer ignore-call */ 
91
                   addSearchMatchSet(
Loading history...
91 2
			'doi',
92 2
			$doi
93
		);
94
95 2
		$filteredRecord->addSearchMatchSet(
96 2
			'reference',
97 2
			$this->crossRefFilteredHttpResponseParser->getFilteredRecord()->get( 'reference' )
98
		);
99
100 2
		$dateTimeUtc = new \DateTime( 'now', new \DateTimeZone( 'UTC' ) );
101 2
		$filteredRecord->set( 'retrieved-on', $dateTimeUtc->format( 'Y-m-d' ) );
102 2
	}
103
104
}
105