Completed
Push — dev ( 94208d...ada7da )
by James Ekow Abaka
02:35
created

SqliteInfo   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A columnExists() 0 8 3
A schemaExists() 0 1 1
A tableExists() 0 4 1
A foreignKeyExists() 0 12 2
A columnNulable() 0 11 4
1
<?php
2
3
/* 
4
 * The MIT License
5
 *
6
 * Copyright 2015 ekow.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
namespace yentu\tests\schema_info;
28
29
class SqliteInfo extends \yentu\tests\SchemaInfo
30
{
31
    /**
32
     * 
33
     * @param type $table
0 ignored issues
show
Bug introduced by
The type yentu\tests\schema_info\type 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...
34
     * @return boolean
35
     */
36
    public function foreignKeyExists($table) 
37
    {
38
        $tableQuery = $this->getPDO()->query(
39
            "SELECT sql FROM sqlite_master WHERE name = '{$table['table']}'"
40
        )->fetchAll(\PDO::FETCH_ASSOC);
41
        if(preg_match("/CONSTRAINT\s+`{$table['name']}`\s+FOREIGN KEY/", $tableQuery[0]['sql']))
42
        {
43
            return true;
44
        }
45
        else
46
        {
47
            return false;
48
        }
49
    }
50
51
    public function columnExists($column) 
52
    {
53
        $columns = $this->getPDO()->query("PRAGMA table_info({$this->table['table']})")->fetchAll(\PDO::FETCH_ASSOC);
54
        foreach($columns as $tableColumn)
55
        {
56
            if($column === $tableColumn['name']) return true;
57
        }
58
        return false;
59
    }
60
61
    public function schemaExists($table) {
62
        
63
    }
64
65
    public function tableExists($table) 
66
    {
67
        $count = $this->getPDO()->query("SELECT count(*) as c FROM sqlite_master WHERE name = '$table'")->fetchAll(\PDO::FETCH_ASSOC);
68
        return $count[0]['c'] == '1';
69
    }
70
71
    public function columnNulable($column, $nullability) 
72
    {
73
        $columns = $this->getPDO()->query("PRAGMA table_info({$this->table['table']})")->fetchAll(\PDO::FETCH_ASSOC);
74
        foreach($columns as $tableColumn)
75
        {
76
            if($column == $tableColumn['name'])
77
            {
78
                return ($tableColumn['notnull'] == '1' ? false : true) === $nullability;
79
            }
80
        }
81
        return false;        
82
    }
83
84
}