Passed
Push — main ( eb62dd...c996bf )
by Thierry
06:17 queued 04:13
created

Statement::rowCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Lagdo\DbAdmin\Driver\PgSql\Db\PgSql;
4
5
use Lagdo\DbAdmin\Driver\Db\StatementInterface;
6
use Lagdo\DbAdmin\Driver\Entity\StatementFieldEntity;
7
8
class Statement implements StatementInterface
9
{
10
    /**
11
     * @var resource
12
     */
13
    protected $result;
14
15
    /**
16
     * @var int
17
     */
18
    protected $offset = 0;
19
20
    /**
21
     * The constructor
22
     *
23
     * @param resource $result
24
     */
25
    public function __construct($result)
26
    {
27
        $this->result = $result;
28
    }
29
30
    /**
31
     * @inheritDoc
32
     */
33
    public function rowCount()
34
    {
35
        return pg_num_rows($this->result);
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    public function fetchAssoc()
42
    {
43
        return pg_fetch_assoc($this->result);
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49
    public function fetchRow()
50
    {
51
        return pg_fetch_row($this->result);
52
    }
53
54
    /**
55
     * @inheritDoc
56
     */
57
    public function fetchField()
58
    {
59
        $column = $this->offset++;
60
        // $table = function_exists('pg_field_table') ? pg_field_table($this->result, $column) : '';
61
        $table = pg_field_table($this->result, $column);
62
        $name = pg_field_name($this->result, $column);
63
        $type = pg_field_type($this->result, $column);
64
        return new StatementFieldEntity($type, $type === "bytea", $name, $name, $table, $table);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Lagdo\DbAdmin... $name, $table, $table) returns the type Lagdo\DbAdmin\Driver\Entity\StatementFieldEntity which is incompatible with the return type mandated by Lagdo\DbAdmin\Driver\Db\...Interface::fetchField() of Lagdo\DbAdmin\Driver\Db\StatementFieldEntity.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
65
    }
66
67
    /**
68
     * The destructor
69
     */
70
    public function __destruct()
71
    {
72
        pg_free_result($this->result);
73
    }
74
}
75