console-helpers /
db-migration
| 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 SqlMigrationRunner extends AbstractMigrationRunner |
||
| 15 | { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Returns supported file extension. |
||
| 19 | * |
||
| 20 | * @return string |
||
| 21 | */ |
||
| 22 | 1 | public function getFileExtension() |
|
| 23 | { |
||
| 24 | 1 | return 'sql'; |
|
| 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 an empty migration is discovered. |
||
| 35 | */ |
||
| 36 | 2 | public function run($migration_file, MigrationContext $context) |
|
| 37 | { |
||
| 38 | 2 | $sqls = file_get_contents($migration_file); |
|
| 39 | 2 | $sqls = array_filter(preg_split('/;\s+/', $sqls)); |
|
| 40 | |||
| 41 | 2 | if ( !$sqls ) { |
|
|
0 ignored issues
–
show
|
|||
| 42 | 1 | throw new \LogicException('The "' . basename($migration_file) . '" migration contains no SQL statements.'); |
|
| 43 | } |
||
| 44 | |||
| 45 | 1 | $db = $context->getDatabase(); |
|
| 46 | |||
| 47 | 1 | foreach ( $sqls as $sql ) { |
|
| 48 | 1 | $db->perform($sql); |
|
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | } |
||
| 53 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.