ColumnCollection   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 9
Bugs 0 Features 1
Metric Value
wmc 7
c 9
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 isPrimaryKey() 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 ColumnCollection
9
 *
10
 * @package Zortje\MySQLKeeper\Database\Table
11
 */
12 View Code Duplication
class ColumnCollection 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 Column[] Table columns
16
	 */
17
	protected $collection = [];
18
19
	/**
20
	 * Add column to collection
21
	 *
22
	 * @param Column $column
23
	 *
24
	 * @throws \InvalidArgumentException if incorrect object type is added
25
	 */
26 2
	public function add($column) {
27 2
		if (!is_object($column) || get_class($column) !== 'Zortje\MySQLKeeper\Database\Table\Column') {
28 1
			$argumentType = is_object($column) ? get_class($column) : gettype($column);
29
30 1
			throw new \InvalidArgumentException(sprintf('Collection may only contain "%s" objects, "%s" is not allowed', 'Zortje\MySQLKeeper\Database\Table\Column', $argumentType));
31
		}
32
33 1
		$this->collection[] = $column;
34 1
	}
35
36
	/**
37
	 * Get column collection with primary key columns
38
	 *
39
	 * @return ColumnCollection
40
	 */
41 1
	public function isPrimaryKey() {
42 1
		$columns = new ColumnCollection();
43
44 1
		foreach ($this->collection as $column) {
45 1
			if ($column->isPrimaryKey() === true) {
46 1
				$columns->add($column);
47 1
			}
48 1
		}
49
50 1
		return $columns;
51
	}
52
}
53