MigrationEvent::getMigrations()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace RDV\Bundle\MigrationBundle\Event;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\DBALException;
7
use RDV\Bundle\MigrationBundle\Migration\Migration;
8
use Symfony\Component\EventDispatcher\Event;
9
10
class MigrationEvent extends Event
11
{
12
    /**
13
     * @var Migration[]
14
     */
15
    protected $migrations = [];
16
17
    /**
18
     * @var Connection
19
     */
20
    protected $connection;
21
22
    /**
23
     * @param Connection $connection
24
     */
25
    public function __construct(Connection $connection)
26
    {
27
        $this->connection = $connection;
28
    }
29
30
    /**
31
     * Adds a migration
32
     *
33
     * @param Migration $migration
34
     * @param bool      $prepend If TRUE a migration is added to the beginning of the list
35
     */
36
    public function addMigration(Migration $migration, $prepend = false)
37
    {
38
        if ($prepend) {
39
            array_unshift($this->migrations, $migration);
40
        } else {
41
            array_push($this->migrations, $migration);
42
        }
43
    }
44
45
    /**
46
     * Gets all migrations
47
     *
48
     * @return Migration[]
49
     */
50
    public function getMigrations()
51
    {
52
        return $this->migrations;
53
    }
54
55
    /**
56
     * Prepares and executes an SQL query and returns the result as an associative array.
57
     *
58
     * @param string $sql    The SQL query.
59
     * @param array  $params The query parameters.
60
     * @param array  $types  The query parameter types.
61
     * @return array
62
     */
63
    public function getData($sql, array $params = array(), $types = array())
64
    {
65
        $this->connection->connect();
66
67
        return $this->connection->fetchAll($sql, $params, $types);
68
    }
69
70
    /**
71
     * Check if the given table exists in a database
72
     *
73
     * @param string $tableName
74
     * @return bool TRUE if a table exists; otherwise, FALSE
75
     */
76
    public function isTableExist($tableName)
77
    {
78
        if (!empty($tableName)) {
79
            try {
80
                $this->connection->connect();
81
                return $this->connection->getSchemaManager()->tablesExist($tableName);
0 ignored issues
show
Documentation introduced by
$tableName is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
82
            } catch (\PDOException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
83
            } catch (DBALException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
84
            }
85
        }
86
87
        return false;
88
    }
89
}
90