PhpMigrationRunner   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 41
ccs 7
cts 7
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileExtension() 0 3 1
A run() 0 9 2
A getTemplate() 0 3 1
1
<?php
2
/**
3
 * This file is part of the DB-Migration library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/db-migration
9
 */
10
11
namespace ConsoleHelpers\DatabaseMigration;
12
13
14
class PhpMigrationRunner extends AbstractMigrationRunner
15
{
16
17
	/**
18
	 * Returns supported file extension.
19
	 *
20
	 * @return string
21
	 */
22 1
	public function getFileExtension()
23
	{
24 1
		return 'php';
25
	}
26
27
	/**
28
	 * Runs the migration.
29
	 *
30
	 * @param string           $migration_file Migration file.
31
	 * @param MigrationContext $context        Migration context.
32
	 *
33
	 * @return void
34
	 * @throws \LogicException When migration doesn't contain a closure.
35
	 */
36 2
	public function run($migration_file, MigrationContext $context)
37
	{
38 2
		$closure = require $migration_file;
39
40 2
		if ( !is_callable($closure) ) {
41 1
			throw new \LogicException('The "' . basename($migration_file) . '" migration doesn\'t return a closure.');
42
		}
43
44 1
		call_user_func($closure, $context);
45
	}
46
47
	/**
48
	 * Returns new migration template.
49
	 *
50
	 * @return string
51
	 */
52
	public function getTemplate()
53
	{
54
		return <<<EOT
55
<?php
56
use ConsoleHelpers\DatabaseMigration\MigrationContext;
57
58
return function (MigrationContext \$context) {
59
	// Write PHP code here.
60
};
61
EOT;
62
	}
63
64
}
65