IndexCollection   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 0 Features 1
Metric Value
wmc 7
c 6
b 0
f 1
lcom 1
cbo 2
dl 41
loc 41
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 9 9 4
A isNotPrimaryKey() 11 11 3

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
namespace Zortje\MySQLKeeper\Database\Table;
4
5
use Zortje\MySQLKeeper\Common\Collection;
6
7
/**
8
 * Class IndexCollection
9
 *
10
 * @package Zortje\MySQLKeeper\Database\Table
11
 */
12 View Code Duplication
class IndexCollection extends Collection {
0 ignored issues
show
Duplication introduced by
This class 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...
13
14
	/**
15
	 * @var Index[] Table indices
16
	 */
17
	protected $collection = [];
18
19
	/**
20
	 * Add index to collection
21
	 *
22
	 * @param Index $index
23
	 *
24
	 * @throws \InvalidArgumentException if incorrect object type is added
25
	 */
26 2
	public function add($index) {
27 2
		if (!is_object($index) || get_class($index) !== 'Zortje\MySQLKeeper\Database\Table\Index') {
28 1
			$argumentType = is_object($index) ? get_class($index) : gettype($index);
29
30 1
			throw new \InvalidArgumentException(sprintf('Collection may only contain "%s" objects, "%s" is not allowed', 'Zortje\MySQLKeeper\Database\Table\Index', $argumentType));
31
		}
32
33 1
		$this->collection[] = $index;
34 1
	}
35
36
	/**
37
	 * Get index collection with non primary key indices
38
	 *
39
	 * @return IndexCollection
40
	 */
41 1
	public function isNotPrimaryKey() {
42 1
		$indices = new IndexCollection();
43
44 1
		foreach ($this->collection as $index) {
45 1
			if ($index->isPrimaryKey() === false) {
46 1
				$indices->add($index);
47 1
			}
48 1
		}
49
50 1
		return $indices;
51
	}
52
}
53