NcbiPubMedResponseParser   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 30
c 0
b 0
f 0
dl 0
loc 101
ccs 35
cts 35
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilteredRecord() 0 2 1
A getRawResponse() 0 2 1
A getMessages() 0 2 1
A usesCache() 0 2 1
A __construct() 0 2 1
A doFilterResponseFor() 0 44 3
1
<?php
2
3
namespace SCI\FilteredMetadata;
4
5
use Onoi\Remi\Ncbi\NcbiPubMedFilteredHttpResponseParser;
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 NcbiPubMedResponseParser implements ResponseParser {
16
17
	/**
18
	 * @var NcbiPubMedFilteredHttpResponseParser
19
	 */
20
	private $ncbiPubMedFilteredHttpResponseParser;
21
22
	/**
23
	 * @since 1.0
24
	 *
25
	 * @param NcbiPubMedFilteredHttpResponseParser $ncbiPubMedFilteredHttpResponseParser
26
	 */
27 9
	public function __construct( NcbiPubMedFilteredHttpResponseParser $ncbiPubMedFilteredHttpResponseParser ) {
28 9
		$this->ncbiPubMedFilteredHttpResponseParser = $ncbiPubMedFilteredHttpResponseParser;
29 9
	}
30
31
	/**
32
	 * @since 1.0
33
	 *
34
	 * {@inheritDoc}
35
	 */
36 1
	public function usesCache() {
37 1
		return $this->ncbiPubMedFilteredHttpResponseParser->usesCache();
38
	}
39
40
	/**
41
	 * @since 1.0
42
	 *
43
	 * {@inheritDoc}
44
	 */
45 1
	public function getMessages() {
46 1
		return $this->ncbiPubMedFilteredHttpResponseParser->getMessages();
47
	}
48
49
	/**
50
	 * @since 1.0
51
	 *
52
	 * {@inheritDoc}
53
	 */
54 2
	public function getFilteredRecord() {
55 2
		return $this->ncbiPubMedFilteredHttpResponseParser->getFilteredRecord();
56
	}
57
58
	/**
59
	 * @since 1.0
60
	 *
61
	 * {@inheritDoc}
62
	 */
63 1
	public function getRawResponse( $id ) {
64 1
		return $this->ncbiPubMedFilteredHttpResponseParser->getRawResponse( $id );
65
	}
66
67
	/**
68
	 * @since 1.0
69
	 *
70
	 * {@inheritDoc}
71
	 */
72 7
	public function doFilterResponseFor( $id ) {
73
74 7
		$type = $this->ncbiPubMedFilteredHttpResponseParser->getFilteredRecord()->get(
75 7
			'ncbi-dbtype'
76
		);
77
78 7
		$resourceIdentifierFactory = new ResourceIdentifierFactory();
79
80 7
		$pubmedValue = $resourceIdentifierFactory->newResourceIdentifierStringValueForType( $type );
81 7
		$pubmedValue->setUserValue( $id );
82
83 7
		if ( !$pubmedValue->isValid() ) {
84 3
			return $this->ncbiPubMedFilteredHttpResponseParser->addMessage( $pubmedValue->getErrors() );
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->ncbiPubMedFiltere...bmedValue->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...
85
		}
86
87
		// NCBI requires to work without any prefix
88 4
		$id = str_replace( 'PMC', '', $pubmedValue->getWikiValue() );
89
90
		// We expect this type of either being PMC or PMID as
91
		// invoked by NcbiResponseContentParser
92 4
		$prefix = $type === 'pmc' ? 'PMC' : 'PMID';
93
94 4
		$this->ncbiPubMedFilteredHttpResponseParser->doFilterResponseFor( $id );
95 4
		$filteredRecord = $this->ncbiPubMedFilteredHttpResponseParser->getFilteredRecord();
96
97 4
		$filteredRecord->setTitleForPageCreation( $prefix . ':' . $id );
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

97
		$filteredRecord->/** @scrutinizer ignore-call */ 
98
                   setTitleForPageCreation( $prefix . ':' . $id );
Loading history...
98 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

98
		$filteredRecord->/** @scrutinizer ignore-call */ 
99
                   setSciteTransclusionHead(
Loading history...
99 4
			$prefix . $id
100
		);
101
102 4
		$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

102
		$filteredRecord->/** @scrutinizer ignore-call */ 
103
                   addSearchMatchSet(
Loading history...
103 4
			'doi',
104 4
			$this->ncbiPubMedFilteredHttpResponseParser->getFilteredRecord()->get( 'doi' )
105
		);
106
107 4
		$filteredRecord->addSearchMatchSet(
108 4
			$type,
109 4
			$prefix . $id
110
		);
111
112 4
		$filteredRecord->delete( 'ncbi-dbtype' );
113
114 4
		$dateTimeUtc = new \DateTime( 'now', new \DateTimeZone( 'UTC' ) );
115 4
		$filteredRecord->set( 'retrieved-on', $dateTimeUtc->format( 'Y-m-d' ) );
116 4
	}
117
118
}
119