Completed
Push — master ( 9de5b8...ddab96 )
by Matteo
03:46
created

DummyObject::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
class FetchTest extends BridgeTestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    public function testFetchArray()
6
    {
7
        $query = 'SELECT * FROM test_table WHERE id <= 3';
8
        $result = $this->bridge->query($query);
9
10
        $this->assertEquals(
11
            [
12
                0           => "1",
13
                1           => "test 1",
14
                "id"        => "1",
15
                "testfield" => "test 1",
16
            ],
17
            $this->bridge->fetchArray($result)
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 8 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchArray() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
18
        );
19
20
        $this->assertEquals(
21
            [
22
                "id"        => "2",
23
                "testfield" => "test 2",
24
            ],
25
            $this->bridge->fetchArray($result, MYSQL_ASSOC)
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 8 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchArray() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
26
        );
27
28
        $this->assertEquals(
29
            [
30
                0 => "3",
31
                1 => "test 3",
32
            ],
33
            $this->bridge->fetchArray($result, MYSQL_NUM)
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 8 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchArray() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
34
        );
35
        
36
        $this->assertFalse($this->bridge->fetchArray($result));
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 8 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchArray() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
37
    }
38
39
    public function testFetchAssoc()
40
    {
41
        $query = 'SELECT * FROM test_table WHERE id = 4';
42
        $result = $this->bridge->query($query);
43
44
        $this->assertEquals(
45
            [
46
                'id'        => '4',
47
                'testfield' => 'test 4'
48
            ],
49
            $this->bridge->fetchAssoc($result)
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 42 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchAssoc() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
50
        );
51
    }
52
53
    public function testFetchField()
54
    {
55
        $query = 'SELECT * FROM test_table';
56
        $result = $this->bridge->query($query);
57
58
        $this->assertAttributeEquals(1, 'primary_key', $this->bridge->fetchField($result));
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 56 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchField() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Deprecated Code introduced by
The method Mattbit\MysqlCompat\Bridge::fetchField() has been deprecated.

This method has been deprecated.

Loading history...
59
        $this->assertAttributeEquals('id', 'name', $this->bridge->fetchField($result));
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 56 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchField() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Deprecated Code introduced by
The method Mattbit\MysqlCompat\Bridge::fetchField() has been deprecated.

This method has been deprecated.

Loading history...
60
        $this->assertAttributeEquals('testfield', 'name', $this->bridge->fetchField($result, 1));
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 56 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchField() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Deprecated Code introduced by
The method Mattbit\MysqlCompat\Bridge::fetchField() has been deprecated.

This method has been deprecated.

Loading history...
61
    }
62
63 View Code Duplication
    public function testFetchLengths()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
64
    {
65
        $query = 'SELECT * FROM test_table WHERE id = 10';
66
        $result = $this->bridge->query($query);
67
        $this->bridge->fetchAssoc($result);
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 66 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchAssoc() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
68
69
        $this->assertEquals([0 => 2, 1 => 7], $this->bridge->fetchLengths($result));
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 66 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchLengths() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
70
    }
71
72
    public function testFetchObject()
73
    {
74
        $query = 'SELECT * FROM test_table WHERE id = 5';
75
        $result = $this->bridge->query($query);
76
77
        $object = $this->bridge->fetchObject($result);
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 75 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchObject() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
78
79
        $this->assertInstanceOf(stdClass::class, $object);
80
        $this->assertEquals('5', $object->id);
81
        $this->assertEquals('test 5', $object->testfield);
82
83
        $query = 'SELECT * FROM test_table WHERE id = 5';
84
        $result = $this->bridge->query($query);
85
86
        $object = $this->bridge->fetchObject($result, DummyObject::class, [1, 2]);
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 84 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchObject() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
87
88
        $this->assertInstanceOf(DummyObject::class, $object);
89
        $this->assertEquals('5', $object->id);
90
        $this->assertEquals('test 5', $object->testfield);
91
        $this->assertEquals(1, $object->one);
92
        $this->assertEquals(2, $object->two);
93
    }
94
95 View Code Duplication
    public function testFetchRow()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
96
    {
97
        $query = 'SELECT * FROM test_table WHERE id = 6';
98
        $result = $this->bridge->query($query);
99
100
        $this->assertEquals(
101
            [
102
                0 => '6',
103
                1 => 'test 6'
104
            ],
105
            $this->bridge->fetchRow($result)
0 ignored issues
show
Bug introduced by
It seems like $result defined by $this->bridge->query($query) on line 98 can also be of type false or null; however, Mattbit\MysqlCompat\Bridge::fetchRow() does only seem to accept object<Mattbit\MysqlCompat\Result>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
106
        );
107
    }
108
109
    /** @expectedException \Mattbit\MysqlCompat\Exception\NotSupportedException */
110
    public function testDataSeek()
111
    {
112
        $result = $this->bridge->query('SELECT * FROM test_table');
113
114
        $this->bridge->dataSeek($result, 5);
0 ignored issues
show
Unused Code introduced by
The call to Bridge::dataSeek() has too many arguments starting with $result.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
115
    }
116
}
117
118
class DummyObject {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
119
    public $one;
120
    public $two;
121
    public function __construct($one, $two)
122
    {
123
        $this->one = $one;
124
        $this->two = $two;
125
    }
126
}