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.

Builder::findByHash()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
eloc 14
c 3
b 0
f 0
nc 4
nop 4
dl 0
loc 24
ccs 15
cts 15
cp 1
crap 3
rs 9.7998
1
<?php
2
3
namespace Omatech\Enigma\Database\Query;
4
5
use Omatech\Enigma\CipherSweet\Index;
6
use Omatech\Enigma\Enigma;
7
8
class Builder extends \Illuminate\Database\Query\Builder
9
{
10
    /**
11
     * @param string $column
12
     * @param string $value
13
     * @param Index $index
14
     * @param string $boolean
15
     * @return $this
16
     * @throws \ParagonIE\CipherSweet\Exception\BlindIndexNameCollisionException
17
     * @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException
18
     */
19 8
    public function whereEnigma(string $column, string $value, Index $index, string $boolean = 'and'): self
20
    {
21 8
        $this->findByHash($column, $value, $index, $boolean);
22
23 8
        return $this;
24
    }
25
26
    /**
27
     * @param string $column
28
     * @param string $value
29
     * @param Index $index
30
     * @return $this
31
     * @throws \ParagonIE\CipherSweet\Exception\BlindIndexNameCollisionException
32
     * @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException
33
     */
34 4
    public function orWhereEnigma(string $column, string $value, Index $index): self
35
    {
36 4
        return $this->whereEnigma($column, $value, $index, 'or');
37
    }
38
39
    /**
40
     * @param string $column
41
     * @param string $value
42
     * @param Index $index
43
     * @param string $boolean
44
     * @return Builder
45
     * @throws \ParagonIE\CipherSweet\Exception\BlindIndexNameCollisionException
46
     * @throws \ParagonIE\CipherSweet\Exception\CryptoOperationException
47
     */
48 8
    private function findByHash(string $column, string $value, Index $index, string $boolean): self
49
    {
50 8
        $table = $this->from;
51 8
        $tableColumn = explode('.', $column);
52
53 8
        if (count($tableColumn) === 2) {
54 4
            [$table, $column] = $tableColumn;
55
        }
56
57 8
        $parts = explode(' as ', $table);
58 8
        $table = $parts[0];
59 8
        $alias = $parts[1] ?? null;
60
61 8
        $ids = (new Enigma)->search($table, $column, $value, $index);
62
63
        $closure = static function (self $query) use ($table, $alias, $ids) {
64 8
            $query->whereRaw(($alias ?? $table).".id IN ($ids)");
65 8
        };
66
67 8
        $boolean === 'and'
68 8
        ? $this->where($closure)
69 4
        : $this->orWhere($closure);
70
71 8
        return $this;
72
    }
73
}
74