Test Setup Failed
Branch botk5 (3fe4ef)
by Enrico
02:33
created

AbstractModelTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 110
Duplicated Lines 36.36 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 40
loc 110
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetVocabulary() 0 15 1
A testSetVocabulary() 10 10 1
A testUnsetVocabulary() 10 10 1
A testGetUri() 0 6 1
A uris() 0 9 1
A testTurtleHeader() 10 10 2
A testTurtleHeaderWithBase() 10 10 2
A testasString() 0 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
class DummyModel extends BOTK\Model\AbstractModel
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
	public function asTurtle() { return '<urn:a:b> owl:sameAs <urn:a:b> .';}
6
}
7
8
class AbstractModelTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
	protected $vocabulary = array(
11
		'botk' 		=> 'http://http://linkeddata.center/botk/v1#',
12
		'schema'	=> 'http://schema.org/',
13
		'wgs' 		=> 'http://www.w3.org/2003/01/geo/wgs84_pos#',
14
		'xsd' 		=> 'http://www.w3.org/2001/XMLSchema#',
15
		'dct' 		=> 'http://purl.org/dc/terms/',
16
		'foaf' 		=> 'http://xmlns.com/foaf/0.1/',
17
	);
18
	
19
	
20
	public function testGetVocabulary()
21
	{
22
		$vocabulary = array(
0 ignored issues
show
Unused Code introduced by
$vocabulary is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
23
			'botk' 		=> 'http://http://linkeddata.center/botk/v1#',
24
			'schema'	=> 'http://schema.org/',
25
			'wgs' 		=> 'http://www.w3.org/2003/01/geo/wgs84_pos#',
26
			'xsd' 		=> 'http://www.w3.org/2001/XMLSchema#',
27
			'dct' 		=> 'http://purl.org/dc/terms/',
28
			'foaf' 		=> 'http://xmlns.com/foaf/0.1/',
29
		);
30
		
31
		$obj = new DummyModel(array());
32
		
33
		$this->assertEquals($this->vocabulary,  $obj->getVocabulary());
34
	}
35
	
36
	
37 View Code Duplication
	public function testSetVocabulary()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
	{
39
		$vocabulary = $this->vocabulary;
40
		$vocabulary['my'] = 'urn:test:';
41
		
42
		$obj = new DummyModel(array());
43
		$obj->setVocabulary('my','urn:test:');
44
		
45
		$this->assertEquals($vocabulary,  $obj->getVocabulary());
46
	}
47
	
48
	
49 View Code Duplication
	public function testUnsetVocabulary()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
	{
51
		$vocabulary = $this->vocabulary;
52
		unset($vocabulary['foaf']);
53
		
54
		$obj = new DummyModel(array());
55
		$obj->unsetVocabulary('foaf');
56
		
57
		$this->assertEquals($vocabulary,  $obj->getVocabulary());
58
	}
59
	
60
61
    /**
62
     * @dataProvider uris
63
     */	
64
	public function testGetUri($data, $expectedData)
65
	{
66
		$obj = new DummyModel($data);
67
		$obj->setIdGenerator(function($d){return'abc';});
0 ignored issues
show
Unused Code introduced by
The parameter $d is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
		$this->assertEquals($expectedData, $obj->getUri());
69
	}
70
71
	
72
	public function uris()
73
    {
74
    	return array( 
75
	    	array( array(),	'http://linkeddata.center/botk/resource/abc'),
76
	    	array( array('base'=>'http://example.com/resource/'),	'http://example.com/resource/abc'),
77
	    	array( array('base'=>'http://example.com/resource/', 'id'=>'efg'),	'http://example.com/resource/efg'),
78
	    	array( array('uri'=>'http://example.com/resource/ijk'),	'http://example.com/resource/ijk'),	
79
		);
80
   	}
81
82 View Code Duplication
	public function testTurtleHeader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
	{		
84
		$obj = new DummyModel(array());
85
		$s ="";
86
		foreach( $this->vocabulary as $p=>$v){
87
			$s.= "@prefix $p: <$v> .\n";
88
		}
89
		
90
		$this->assertEquals($s,  $obj->getTurtleHeader());
91
	}
92
	
93
	
94 View Code Duplication
	public function testTurtleHeaderWithBase()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
	{		
96
		$obj = new DummyModel(array());
97
		$s ="@base <urn:a:b> .\n";
98
		foreach( $this->vocabulary as $p=>$v){
99
			$s.= "@prefix $p: <$v> .\n";
100
		}
101
		
102
		$this->assertEquals($s,  $obj->getTurtleHeader('urn:a:b'));
103
	}
104
	
105
	
106
107
	public function testasString()
108
	{		
109
		$obj = new DummyModel(array());
110
		$s= $obj->getTurtleHeader() ."\n<urn:a:b> owl:sameAs <urn:a:b> .";
111
		
112
		$this->assertEquals($s,  (string)$obj);
113
	}
114
	
115
	
116
117
}
118
119