Passed
Pull Request — master (#1)
by Peter
07:07
created

FoundRows   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 30
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A get() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Databases\Queries;
6
7
use Opulence\Databases\ConnectionPools\ConnectionPool;
8
9
class FoundRows
10
{
11
    /** @var ConnectionPool */
12
    protected $connectionPool;
13
14
    /**
15
     * FoundRows constructor.
16
     *
17
     * @param ConnectionPool $connectionPool
18
     */
19
    public function __construct(ConnectionPool $connectionPool)
20
    {
21
        $this->connectionPool = $connectionPool;
22
    }
23
24
    /**
25
     * @return int
26
     */
27
    public function get(): int
28
    {
29
        $sql = 'SELECT FOUND_ROWS()';
30
31
        $connection = $this->connectionPool->getReadConnection();
32
        $statement  = $connection->prepare($sql);
33
34
        if (!$statement->execute()) {
35
            return 0;
36
        }
37
38
        return (int)$statement->fetchColumn();
39
    }
40
}
41