SettingsQueryBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 2
b 0
f 0
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A first() 0 12 2
A exists() 0 3 1
A find() 0 3 1
1
<?php
2
3
namespace Thinkone\NovaPageSettings\QueryAdapter;
4
5
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
6
use Illuminate\Database\Eloquent\Model;
7
8
/**
9
 * @extends \Illuminate\Database\Eloquent\Builder<Model>
10
 */
11
class SettingsQueryBuilder extends EloquentBuilder
12
{
13
14 2
    public function find($id, $columns = [ '*' ]): mixed
15
    {
16 2
        return $this->get()->firstWhere(InternalSettingsModel::ATTR_ID, $id);
17
    }
18
19 2
    public function first($columns = [ '*' ]): mixed
20
    {
21
        /* ad-hoc solution to prevent real call to database */
22 2
        $wheres = $this->query->wheres;
23 2
        $key    = InternalSettingsModel::ATTR_ID;
24 2
        $val    = collect($wheres)->firstWhere('column', "{$this->query->from}.{$key}");
0 ignored issues
show
Bug introduced by
$wheres of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
        $val    = collect(/** @scrutinizer ignore-type */ $wheres)->firstWhere('column', "{$this->query->from}.{$key}");
Loading history...
25
26 2
        if ($val) {
27 1
            return $this->find($val['value']);
28
        }
29
30 1
        return parent::first($columns);
31
    }
32
33 1
    public function exists(): bool
34
    {
35 1
        return !!$this->first();
36
    }
37
}
38