ColumnCollection::isPrimaryKey()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 2
b 0
f 0
nc 3
nop 0
dl 11
loc 11
ccs 8
cts 8
cp 1
crap 3
rs 9.4285
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