Code Duplication    Length = 41-41 lines in 2 locations

src/Database/Table/ColumnCollection.php 1 location

@@ 12-52 (lines=41) @@
9
 *
10
 * @package Zortje\MySQLKeeper\Database\Table
11
 */
12
class ColumnCollection extends Collection {
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
	public function add($column) {
27
		if (!is_object($column) || get_class($column) !== 'Zortje\MySQLKeeper\Database\Table\Column') {
28
			$argumentType = is_object($column) ? get_class($column) : gettype($column);
29
30
			throw new \InvalidArgumentException(sprintf('Collection may only contain "%s" objects, "%s" is not allowed', 'Zortje\MySQLKeeper\Database\Table\Column', $argumentType));
31
		}
32
33
		$this->collection[] = $column;
34
	}
35
36
	/**
37
	 * Get column collection with primary key columns
38
	 *
39
	 * @return ColumnCollection
40
	 */
41
	public function isPrimaryKey() {
42
		$columns = new ColumnCollection();
43
44
		foreach ($this->collection as $column) {
45
			if ($column->isPrimaryKey() === true) {
46
				$columns->add($column);
47
			}
48
		}
49
50
		return $columns;
51
	}
52
}
53

src/Database/Table/IndexCollection.php 1 location

@@ 12-52 (lines=41) @@
9
 *
10
 * @package Zortje\MySQLKeeper\Database\Table
11
 */
12
class IndexCollection extends Collection {
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
	public function add($index) {
27
		if (!is_object($index) || get_class($index) !== 'Zortje\MySQLKeeper\Database\Table\Index') {
28
			$argumentType = is_object($index) ? get_class($index) : gettype($index);
29
30
			throw new \InvalidArgumentException(sprintf('Collection may only contain "%s" objects, "%s" is not allowed', 'Zortje\MySQLKeeper\Database\Table\Index', $argumentType));
31
		}
32
33
		$this->collection[] = $index;
34
	}
35
36
	/**
37
	 * Get index collection with non primary key indices
38
	 *
39
	 * @return IndexCollection
40
	 */
41
	public function isNotPrimaryKey() {
42
		$indices = new IndexCollection();
43
44
		foreach ($this->collection as $index) {
45
			if ($index->isPrimaryKey() === false) {
46
				$indices->add($index);
47
			}
48
		}
49
50
		return $indices;
51
	}
52
}
53