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.
Completed
Pull Request — master (#9)
by David Cox
06:16
created

Builder::backupFieldsForCount()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 8
nop 0
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace Sofa\Eloquence\Query;
4
5
use Sofa\Eloquence\Subquery;
6
use Illuminate\Database\Query\Builder as BaseBuilder;
7
8
class Builder extends BaseBuilder
9
{
10
    /**
11
     * Backup some fields for the pagination count.
12
     *
13
     * @return void
14
     */
15
    protected function backupFieldsForCount()
16
    {
17
        foreach (['orders', 'limit', 'offset', 'columns'] as $field) {
18
            $this->backups[$field] = $this->{$field};
0 ignored issues
show
Bug introduced by
The property backups does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
19
20
            $this->{$field} = null;
21
        }
22
23
        $bindings = ($this->from instanceof Subquery) ? ['order'] : ['order', 'select'];
24
25
        foreach ($bindings as $key) {
26
            $this->bindingBackups[$key] = $this->bindings[$key];
0 ignored issues
show
Bug introduced by
The property bindingBackups does not seem to exist. Did you mean backups?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
27
28
            $this->bindings[$key] = [];
29
        }
30
    }
31
32
    /**
33
     * Restore some fields after the pagination count.
34
     *
35
     * @return void
36
     */
37
    protected function restoreFieldsForCount()
38
    {
39
        foreach ($this->backups as $field => $value) {
40
            $this->{$field} = $value;
41
        }
42
43
        foreach ($this->bindingBackups as $key => $value) {
0 ignored issues
show
Bug introduced by
The property bindingBackups does not seem to exist. Did you mean backups?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
44
            $this->bindings[$key] = $value;
45
        }
46
47
        $this->backups = $this->bindingBackups = [];
0 ignored issues
show
Bug introduced by
The property bindingBackups does not seem to exist. Did you mean backups?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
48
    }
49
50
    /**
51
     * Run a pagination count query.
52
     *
53
     * @param  array  $columns
54
     * @return array
55
     */
56
    protected function runPaginationCountQuery($columns = ['*'])
57
    {
58
        $bindings = $this->from instanceof Subquery ? ['order'] : ['select', 'order'];
59
60
        return $this->cloneWithout(['columns', 'orders', 'limit', 'offset'])
61
                    ->cloneWithoutBindings($bindings)
62
                    ->setAggregate('count', $this->withoutSelectAliases($columns))
63
                    ->get()->all();
64
    }
65
}
66