Test_VObjects   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 34.29 %

Coupling/Cohesion

Components 0
Dependencies 2
Metric Value
wmc 4
lcom 0
cbo 2
dl 24
loc 70
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 4 1
A testCrappyVCard() 12 12 1
A testEscapedParameters() 12 12 1
B testGroupProperty() 0 36 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
 * Copyright (c) 2013 Thomas Tanghus ([email protected])
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later.
6
 * See the COPYING-README file.
7
 */
8
9
use Test\TestCase;
10
11
/**
12
 * Class Test_VObjects
13
 * @group DB
14
 */
15
class Test_VObjects extends TestCase {
0 ignored issues
show
Coding Style introduced by
The class Test_VObjects is not named in CamelCase.

This check marks class names that have not been written in CamelCase.

In CamelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database connector becomes DatabaseConnector.

Loading history...
16
17
	public static function setUpBeforeClass() {
18
		parent::setUpBeforeClass();
19
		\Sabre\VObject\Component\VCard::$propertyMap['CATEGORIES'] = 'OCA\Contacts\VObject\GroupProperty';
20
	}
21
22 View Code Duplication
	public function testCrappyVCard() {
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...
23
		$cardData = file_get_contents(__DIR__ . '/../data/test3.vcf');
24
		$obj = \Sabre\VObject\Reader::read(
25
			$cardData,
26
			\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
27
		);
28
		$obj->validate($obj::REPAIR);
29
30
		$this->assertEquals('2.1', (string)$obj->VERSION);
31
		$this->assertEquals('Adèle Fermée', (string)$obj->FN);
32
		$this->assertEquals('Fermée;Adèle;;;', (string)$obj->N);
33
	}
34
35 View Code Duplication
	public function testEscapedParameters() {
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...
36
		$cardData = file_get_contents(__DIR__ . '/../data/test6.vcf');
37
		$obj = \Sabre\VObject\Reader::read(
38
			$cardData,
39
			\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
40
		);
41
		$obj->validate($obj::REPAIR);
42
43
		$this->assertEquals('3.0', (string)$obj->VERSION);
44
		$this->assertEquals('Parameters;Escaped;;;', (string)$obj->N);
45
		$this->assertEquals('TEL;TYPE=PREF\,WORK\,VOICE:123456789' . "\r\n", $obj->TEL->serialize());
46
	}
47
48
	public function testGroupProperty() {
49
		$arr = array(
50
			'Home',
51
			'work',
52
			'Friends, Family',
53
		);
54
55
		$vcard = new \OCA\Contacts\VObject\VCard();
0 ignored issues
show
Bug introduced by
The call to VCard::__construct() misses a required argument $name.

This check looks for function calls that miss required arguments.

Loading history...
56
57
		$property = $vcard->createProperty('CATEGORIES');
0 ignored issues
show
Bug introduced by
The method createProperty() does not exist on OCA\Contacts\VObject\VCard. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
58
		$property->setParts($arr);
59
60
		// Test parsing and serializing
61
		$this->assertEquals('Home,work,Friends\, Family', $property->getValue());
62
		$this->assertEquals('CATEGORIES:Home,work,Friends\, Family' . "\r\n", $property->serialize());
63
		$this->assertEquals(3, count($property->getParts()));
64
65
		// Test add
66
		$property->addGroup('Coworkers');
67
		$this->assertTrue($property->hasGroup('coworkers'));
68
		$this->assertEquals(4, count($property->getParts()));
69
		$this->assertEquals('Home,work,Friends\, Family,Coworkers', $property->getValue());
70
71
		// Test remove
72
		$this->assertTrue($property->hasGroup('Friends, fAmIlY'));
73
		$property->removeGroup('Friends, fAmIlY');
74
		$this->assertEquals(3, count($property->getParts()));
75
		$parts = $property->getParts();
76
		$this->assertEquals('Coworkers', $parts[2]);
77
78
		// Test rename
79
		$property->renameGroup('work', 'Work');
80
		$parts = $property->getParts();
81
		$this->assertEquals('Work', $parts[1]);
82
		//$this->assertEquals(true, false);
83
	}
84
}
85