Migrator::setMigrationType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace Codengine\CustomMigrations;
2
3
/**
4
 * Class Migrator
5
 * The custom Migrator filters migrations of a specific type
6
 *
7
 * @package Codengine\CustomMigrations
8
 */
9
class Migrator extends \Illuminate\Database\Migrations\Migrator {
10
	/**
11
	 * @var string
12
	 */
13
	protected $migrationType = 'default';
14
15
	/**
16
	 * Sets the migration type filter
17
	 *
18
	 * @param string $type
19
	 */
20
	public function setMigrationType($type)
21
	{
22
		$this->migrationType = $type;
23
	}
24
25
	/**
26
	 * Returns the migration type filter
27
	 *
28
	 * @return string
29
	 */
30
	public function getMigrationType()
31
	{
32
		return $this->migrationType;
33
	}
34
35
	/**
36
	 * Resolves the migration and filters those that don't match the migration type
37
	 *
38
	 * @param string $migration
39
	 * @return bool Returns TRUE on a match, else FALSE
40
	 */
41
	protected function filterMigrations($migration)
42
	{
43
		$instance = $this->resolve($migration);
44
		if(empty($instance->type))
45
		{
46
			$instance->type = 'default';
47
		}
48
49
		if($this->migrationType != $instance->type)
50
		{
51
			return false;
52
		} else {
53
			return true;
54
		}
55
	}
56
57
	/**
58
	 * Gets a filtered list of migrations and runs them
59
	 *
60
	 * @param array $migrations
61
	 * @param bool $pretend
0 ignored issues
show
Bug introduced by
There is no parameter named $pretend. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
62
	 */
63
	public function runMigrationList($migrations, array $options=[])
64
	{
65
		$this->note("Running " . ($this->migrationType == "default" ? "default" : "custom") . " migrations for DB " . $this->connection);
66
		$migrations = array_filter($migrations, array($this, "filterMigrations"));
67
		parent::runMigrationList($migrations, $options);
68
	}
69
}