PhpMigrationRunner::run()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
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