Completed
Push — master ( 5c8f9b...c72a1f )
by Christopher
01:11
created

Builder::lastMonth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Chriscreates\Blog\Builders;
4
5
use Carbon\Carbon;
6
use Chriscreates\Blog\Exceptions\ColumnNotFoundException;
7
use Illuminate\Database\Eloquent\Builder as BaseBuilder;
8
use Illuminate\Support\Facades\Schema;
9
10
class Builder extends BaseBuilder
11
{
12
    /**
13
     * Return results where created_at between now and last month.
14
     *
15
     * @return \Chriscreates\Blog\Builders\Builder
16
     */
17
    public function lastMonth() : Builder
18
    {
19
        return $this->whereBetween('created_at', [
0 ignored issues
show
Documentation Bug introduced by
The method whereBetween does not exist on object<Chriscreates\Blog\Builders\Builder>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
20
            Carbon::now()->subMonth(), Carbon::now(),
21
        ])->latest();
22
    }
23
24
    /**
25
     * Return results where created_at between now and last week.
26
     *
27
     * @return \Chriscreates\Blog\Builders\Builder
28
     */
29
    public function lastWeek() : Builder
30
    {
31
        return $this->whereBetween('created_at', [
0 ignored issues
show
Documentation Bug introduced by
The method whereBetween does not exist on object<Chriscreates\Blog\Builders\Builder>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
32
            Carbon::now()->subWeek(), Carbon::now(),
33
        ])->latest();
34
    }
35
36
    /**
37
     * Return results where slug matches.
38
     *
39
     * @param string $status
0 ignored issues
show
Bug introduced by
There is no parameter named $status. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
40
     * @return \Chriscreates\Blog\Builders\Builder
41
     */
42
    public function slug(string $slug) : Builder
43
    {
44
        // Check whether queried table has 'slug' column
45
        if ( ! Schema::hasColumn($this->model->getTable(), 'slug')) {
46
            $message = "Column 'slug' not found in {$this->model->getTable()} table";
47
48
            throw new ColumnNotFoundException($message);
49
        }
50
51
        return $this->where('slug', $slug);
52
    }
53
}
54