GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 698fd2...95f32c )
by Christian
10:54 queued 08:21
created

DB::insertHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A DB::deleteHashes() 0 3 1
1
<?php
2
3
namespace Omatech\Enigma\Database\Eloquent;
4
5
use Illuminate\Support\Facades\DB as Query;
6
7
final class DB extends DBAbstract
8
{
9
    private $table;
10
11
    /**
12
     * DB constructor.
13
     * @param string $table
14
     */
15 44
    public function __construct(string $table)
16
    {
17 44
        $this->table = $table.'_index';
18 44
    }
19
20
    /**
21
     * @param int $modelId
22
     * @param string $column
23
     * @param array $hashes
24
     * @return void
25
     */
26 44
    public function insertHashes(int $modelId, string $column, array $hashes): void
27
    {
28 44
        foreach (array_chunk($hashes, 100) as $chunks) {
29
            $insert = array_map(function ($hash) use ($modelId, $column) {
30 44
                return "('$modelId', '$column', '$hash')";
31 44
            }, $chunks);
32
33 44
            Query::statement("INSERT INTO $this->table (model_id, name, hash) VALUES ".implode(',', $insert));
34
        }
35 44
    }
36
37
    /**
38
     * @param int $modelId
39
     * @param string $column
40
     * @return void
41
     */
42 44
    public function deleteHashes(int $modelId, string $column): void
43
    {
44 44
        Query::statement("DELETE FROM $this->table WHERE model_id = $modelId AND name = '$column'");
45 44
    }
46
47
    /**
48
     * @param string $column
49
     * @param string $hash
50
     * @return array
51
     */
52 24
    public function findByHash(string $column, string $hash): array
53
    {
54 24
        $query = Query::select(
55 24
            "SELECT model_id FROM $this->table
56 24
            WHERE name = '$column' AND
57 24
                  hash = '$hash' AND
58
                  model_id IS NOT NULL"
59
        );
60
61
        return array_map(static function ($row) {
62 20
            return $row->model_id;
63 24
        }, $query ?? []);
64
    }
65
}
66