1<?php
2
3namespace App\Repository;
4
5/**
6 * Repository class for fetching data from the bugdb_votes database table.
7 */
8class VoteRepository
9{
10    /**
11     * Database handle.
12     * @var \PDO
13     */
14    private $dbh;
15
16    /**
17     * Class constructor
18     */
19    public function __construct(\PDO $dbh)
20    {
21        $this->dbh = $dbh;
22    }
23
24    /**
25     * Find vote row by bug id and IP.
26     */
27    public function findOneByIdAndIp(int $id, string $ip): array
28    {
29        $sql = 'SELECT bug, ip FROM bugdb_votes WHERE bug = ? AND ip = ? LIMIT 1';
30
31        $statement = $this->dbh->prepare($sql);
32        $statement->execute([$id, $ip]);
33
34        $result = $statement->fetch();
35
36        return $result === false ? [] : $result;
37    }
38}
39