These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace ByJG\DbMigration\Database; |
||
4 | |||
5 | use ByJG\AnyDataset\Factory; |
||
6 | use ByJG\Util\Uri; |
||
7 | use Psr\Http\Message\UriInterface; |
||
8 | |||
9 | class MySqlDatabase extends AbstractDatabase |
||
10 | { |
||
11 | |||
12 | View Code Duplication | public static function prepareEnvironment(UriInterface $uri) |
|
0 ignored issues
–
show
|
|||
13 | { |
||
14 | $database = preg_replace('~^/~', '', $uri->getPath()); |
||
15 | |||
16 | $customUri = new Uri($uri->__toString()); |
||
17 | |||
18 | $dbDriver = Factory::getDbRelationalInstance($customUri->withPath('/')->__toString()); |
||
19 | $dbDriver->execute("CREATE SCHEMA IF NOT EXISTS `$database` DEFAULT CHARACTER SET utf8 ;"); |
||
20 | } |
||
21 | |||
22 | View Code Duplication | public function createDatabase() |
|
23 | { |
||
24 | $database = preg_replace('~^/~', '', $this->getDbDriver()->getUri()->getPath()); |
||
25 | |||
26 | $this->getDbDriver()->execute("CREATE SCHEMA IF NOT EXISTS `$database` DEFAULT CHARACTER SET utf8 ;"); |
||
27 | $this->getDbDriver()->execute("USE `$database`"); |
||
28 | } |
||
29 | |||
30 | public function dropDatabase() |
||
31 | { |
||
32 | $database = preg_replace('~^/~', '', $this->getDbDriver()->getUri()->getPath()); |
||
33 | |||
34 | $this->getDbDriver()->execute("drop database `$database`"); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @throws \ByJG\DbMigration\Exception\DatabaseNotVersionedException |
||
39 | * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException |
||
40 | */ |
||
41 | public function createVersion() |
||
42 | { |
||
43 | $this->getDbDriver()->execute('CREATE TABLE IF NOT EXISTS migration_version (version int, status varchar(20))'); |
||
44 | $this->checkExistsVersion(); |
||
45 | } |
||
46 | |||
47 | public function executeSql($sql) |
||
48 | { |
||
49 | $this->getDbDriver()->execute($sql); |
||
50 | } |
||
51 | } |
||
52 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.