ResourceIdentifierFactory   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
eloc 24
c 0
b 0
f 0
dl 0
loc 42
ccs 24
cts 24
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B newResourceIdentifierStringValueForType() 0 32 11
1
<?php
2
3
namespace SCI\DataValues;
4
5
use RuntimeException;
6
use SMW\PropertyRegistry;
0 ignored issues
show
Bug introduced by
The type SMW\PropertyRegistry was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use SMW\DIProperty;
0 ignored issues
show
Bug introduced by
The type SMW\DIProperty was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use SMW\DataValueFactory;
0 ignored issues
show
Bug introduced by
The type SMW\DataValueFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
/**
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class ResourceIdentifierFactory {
17
18
	/**
19
	 * @since 1.0
20
	 *
21
	 * @param string $type
22
	 *
23
	 * @return ResourceIdentifierStringValue
24
	 * @throws RuntimeException
25
	 */
26 14
	public function newResourceIdentifierStringValueForType( $type ) {
27
28 14
		$propertyRegistry = PropertyRegistry::getInstance();
29 14
		$property = null;
30
31 14
		switch ( strtoupper( $type ) ) {
32 14
			case 'OCLC':
33 11
			case 'VIAF':
34 9
			case 'DOI':
35 7
			case 'OLID':
36 8
				$property = $propertyRegistry->findPropertyIdByLabel( $type );
37 8
				break;
38 6
			case 'PUBMED':
39 5
			case 'PMID':
40 2
				$property = $propertyRegistry->findPropertyIdByLabel( 'PMID' );
41 2
				break;
42 4
			case 'PMC':
43 2
			case 'PMCID':
44 3
				$property = $propertyRegistry->findPropertyIdByLabel( 'PMCID' );
45 3
				break;
46
		}
47
48 14
		$typeId = $propertyRegistry->getPropertyTypeId( $property );
49
50 14
		if ( $typeId === null || $typeId === '' ) {
51 1
			throw new RuntimeException( "{$type} is an unmatched type for ResourceIdentifierStringValue" );
52
		}
53
54 13
		$resourceIdentifierStringValue = DataValueFactory::getInstance()->newDataValueByType( $typeId );
55 13
		$resourceIdentifierStringValue->setProperty( new DIProperty( $property ) );
56
57 13
		return $resourceIdentifierStringValue;
58
	}
59
60
}
61