CrossRefCiteprocJsonProcessor   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 24
lcom 1
cbo 1
dl 0
loc 107
ccs 68
cts 68
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A doProcess() 0 3 1
C doProcessCiteproc() 0 60 17
B collectAuthors() 0 19 5
1
<?php
2
3
namespace Onoi\Remi\CrossRef;
4
5
use Onoi\Remi\FilteredRecord;
6
7
/**
8
 * @license GNU GPL v2+
9
 * @since 0.1
10
 *
11
 * @author mwjames
12
 */
13
class CrossRefCiteprocJsonProcessor {
14
15
	/**
16
	 * @var FilteredRecord
17
	 */
18
	private $filteredRecord;
19
20
	/**
21
	 * @since 0.1
22
	 *
23
	 * @param FilteredRecord $filteredRecord
24
	 */
25 4
	public function __construct( FilteredRecord $filteredRecord ) {
26 4
		$this->filteredRecord = $filteredRecord;
27 4
	}
28
29
	/**
30
	 * @since 0.1
31
	 *
32
	 * @param array $json
33
	 */
34 4
	public function doProcess( array $json ) {
35 4
		$this->doProcessCiteproc( $json );
36 4
	}
37
38 4
	private function doProcessCiteproc( $citeproc ) {
39
40 4
		foreach ( $citeproc as $key => $value ) {
41
42
			switch ( $key ) {
43 4
				case 'type':
44 4
					$this->filteredRecord->set( 'type', $value );
45 4
					break;
46 4
				case 'subject':
47 1
					$this->filteredRecord->set( 'subject', $value );
48 1
					break;
49 4
				case 'editor':
50 4
				case 'author':
51 4
					$this->collectAuthors( $key, $value );
52 4
					break;
53 4
				case 'title':
54 4
					$this->filteredRecord->set( 'title', $value );
55 4
					break;
56 4
				case 'issue':
57 2
					$this->filteredRecord->set( 'issue', $value );
58 2
					break;
59 4
				case 'volume':
60 2
					$this->filteredRecord->set( 'volume', $value );
61 2
					break;
62 4
				case 'page':
63 2
					$this->filteredRecord->set( 'pages', $value );
64 2
					break;
65 4
				case 'publisher':
66 4
					$this->filteredRecord->set( 'publisher', $value );
67 4
					break;
68 4
				case 'container-title':
69 3
					$this->filteredRecord->set( 'journal', $value );
70 3
					break;
71 4
				case 'DOI':
72 4
					$this->filteredRecord->set( 'doi', $value );
73 4
					break;
74 4
				case 'ISSN':
75 2
					$this->filteredRecord->set( 'issn', $value );
76 2
					break;
77 4
				case 'deposited': // Dataset
78 4
				case 'issued':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
79
80 4
					if ( isset( $value['raw'] ) ) {
81 1
						$this->filteredRecord->set( 'year', $value['raw'] );
82 1
					} else {
83 3
						$date = end( $value['date-parts'] );
84 3
						$this->filteredRecord->set( 'year', $date[0] );
85
					}
86
87 4
					break;
88
			}
89 4
		}
90
91
		// Part of the auto generated key
92 4
		$this->filteredRecord->append(
93 4
			'reference',
94 4
			$this->filteredRecord->get( 'year' ) .
95 4
			mb_substr( strtolower( $this->filteredRecord->get( 'title' ) ) , 0, 2 )
96 4
		);
97 4
	}
98
99 4
	private function collectAuthors( $name, array $values ) {
100
101 4
		$authors = array();
102
103 4
		foreach ( $values as $key => $value ) {
104
105
			// Literal set by dataset
106 4
			$familyName = isset( $value['literal'] ) ? $value['literal'] : $value['family'];
107
108
			// Part of the auto generated key
109 4
			if ( $key == 0 ) {
110 4
				$this->filteredRecord->set( 'reference', strtolower( $familyName ) );
111 4
			}
112
113 4
			$authors[] = ( isset( $value['given'] ) ? $value['given'] . ' ': '' ) . $familyName;
114 4
		}
115
116 4
		$this->filteredRecord->set( $name, $authors );
117 4
	}
118
119
}
120