EncryptableQueryBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A where() 0 8 3
A __construct() 0 4 1
1
<?php
2
namespace Magros\Encryptable;
3
4
use Illuminate\Database\ConnectionInterface;
5
use Illuminate\Database\Query\Builder;
6
7
class EncryptableQueryBuilder extends Builder {
8
9
    private $model;
10
11
    /**
12
     * EncryptableQueryBuilder constructor.
13
     * @param ConnectionInterface $connection
14
     * @param Encryptable $model
15
     */
16
    public function __construct(ConnectionInterface $connection, $model)
17
    {
18
        parent::__construct($connection, $connection->getQueryGrammar(), $connection->getPostProcessor());
19
        $this->model = $model;
20
    }
21
22
    /**
23
     * @param array|\Closure|string $column
24
     * @param null $operator
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $operator is correct as it would always require null to be passed?
Loading history...
25
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
26
     * @param string $boolean
27
     * @return Builder
28
     * @throws \Exception
29
     */
30
    public function where($column, $operator = null, $value = null, $boolean = 'and')
31
    {
32
        if (method_exists($this->model, 'encryptable') && $this->model->encryptable($column)) {
33
            list($value, $operator) = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2);
34
            $value = $this->model->encryptAttribute($value);
35
        }
36
37
        return parent::where($column, $operator, $value, $boolean);
38
39
    }
40
}