Migration   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSchema() 0 3 1
A setConnection() 0 3 1
A getConnection() 0 3 1
A __construct() 0 5 1
A down() 0 7 2
A up() 0 8 2
1
<?php
2
3
namespace Ffcms\Core\Migrations;
4
5
use Apps\ActiveRecord\Migration as MigrationRecord;
0 ignored issues
show
Bug introduced by
The type Apps\ActiveRecord\Migration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Database\Capsule\Manager as DatabaseManager;
7
8
/**
9
 * Class Migration. Basic features for migration
10
 * @package Ffcms\Core\Migrations
11
 */
12
class Migration
13
{
14
    /** @var string */
15
    public $now;
16
    /** @var string|null */
17
    private $connection;
18
    /** @var string */
19
    private $name;
20
21
    /**
22
     * Migration constructor. Pass connection name inside if exist
23
     * @param null $connectionName
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $connectionName is correct as it would always require null to be passed?
Loading history...
24
     */
25
    public function __construct($migrationName, $connectionName = null)
26
    {
27
        $this->name = $migrationName;
28
        $this->connection = $connectionName;
29
        $this->now = date('Y-m-d H:i:s', time());
30
    }
31
32
    /**
33
     * Insert data into migration table
34
     */
35
    public function up()
36
    {
37
        $record = new MigrationRecord();
38
        if ($this->connection !== null) {
39
            $record->setConnection($this->connection);
40
        }
41
        $record->migration = $this->name;
42
        $record->save();
43
    }
44
45
    /**
46
     * Remove data from migration table
47
     */
48
    public function down()
49
    {
50
        $record = new MigrationRecord();
51
        if ($this->connection !== null) {
52
            $record->setConnection($this->connection);
53
        }
54
        $record->where('migration', $this->name)->delete();
55
    }
56
57
    /**
58
     * Set connection name
59
     * @param string|null $name
60
     * @return void
61
     */
62
    public function setConnection($name = null)
63
    {
64
        $this->connection = $name;
65
    }
66
67
    /**
68
     * Get database connection instance
69
     * @return \Illuminate\Database\Connection
70
     */
71
    public function getConnection()
72
    {
73
        return DatabaseManager::connection($this->connection);
74
    }
75
76
    /**
77
     * Get database connection schema builder for current instance of connection
78
     * @return \Illuminate\Database\Schema\Builder
79
     */
80
    public function getSchema()
81
    {
82
        return DatabaseManager::schema($this->connection);
83
    }
84
}
85