Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 4f93b1...14a25e )
by Mark
02:33
created

ArticleRepository   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 153
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 153
rs 10
c 0
b 0
f 0
wmc 15
lcom 1
cbo 1

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A publicArticles() 0 12 1
A whereSitemappable() 0 4 1
A latest() 0 4 1
A mostViewed() 0 4 1
A uniqueCreators() 0 4 1
A viewable() 0 4 1
A paginateLatest() 0 4 1
A activeCategories() 0 4 1
A publishedArticlesCount() 0 4 1
A whereStatusActive() 0 4 1
A collectArticle() 0 4 1
A searchThenPaginate() 0 4 1
A whereCreatorId() 0 7 1
A whereCategoryId() 0 7 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Marky
5
 * Date: 16/02/2018
6
 * Time: 16:00.
7
 */
8
9
namespace App\Classes\Repositories;
10
11
use App\Model\Menu;
12
use App\Model\Article;
13
use Illuminate\Support\Collection;
14
use Illuminate\Database\Eloquent\Builder;
15
use Illuminate\Support\Facades\DB;
16
17
/**
18
 * Class ArticleRepository.
19
 */
20
class ArticleRepository extends BaseRepository
21
{
22
    /**
23
     * @var Article|Builder|Collection
24
     */
25
    protected $model;
26
27
    /**
28
     * PageRepository constructor.
29
     *
30
     * @param Article|Menu $model
0 ignored issues
show
Documentation introduced by
Consider making the type for parameter $model a bit more specific; maybe use Article.
Loading history...
31
     */
32
    public function __construct(Article $model)
33
    {
34
        $this->model = $model;
35
    }
36
37
    /**
38
     * Load all the articles that will be displayed dont he front page based on the criteria of being an public post.
39
     *
40
     * @ver 5.2.0
41
     * @date 14/05/2018
42
     * @return Builder|Collection
43
     */
44
    private function publicArticles()
45
    {
46
        return $this->model->where([
0 ignored issues
show
Bug introduced by
The method where does only exist in Illuminate\Database\Eloq...nate\Support\Collection, but not in App\Model\Article.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
47
            ['status', Article::STATUS_PUBLIC],
48
            ['publish_date', '<=', DB::raw('NOW()')],
49
            ['unpublish_date', '>=', DB::raw('NOW()')]
50
        ])->orWhere([
51
            ['status', Article::STATUS_PUBLIC],
52
            ['publish_date', '<=', DB::raw('NOW()')],
53
            ['unpublish_date', '=', null]]
54
        );
55
    }
56
57
    public function whereSitemappable()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
58
    {
59
        return $this->model->where(['sitemap' => true, 'status' => true])->get();
0 ignored issues
show
Bug introduced by
The method where does only exist in Illuminate\Database\Eloq...nate\Support\Collection, but not in App\Model\Article.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
60
    }
61
62
    /**
63
     * @ver 5.0.2
64
     * @date 08/03/2018
65
     * @param int $count
66
     * @return \Illuminate\Database\Eloquent\Collection|Collection|static[]
67
     */
68
    public function latest($count = 7)
69
    {
70
        return $this->publicArticles()->take($count)->orderBy('created_at', 'desc')->get();
0 ignored issues
show
Bug introduced by
The method take does only exist in Illuminate\Support\Collection, but not in Illuminate\Database\Eloquent\Builder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
71
    }
72
73
    /**
74
     * @ver 5.0.2
75
     * @date 08/03/2018
76
     * @param int $count
77
     * @return \Illuminate\Database\Eloquent\Collection|Collection|static[]
78
     */
79
    public function mostViewed($count = 7)
80
    {
81
        return $this->publicArticles()->orderBy('views', 'desc')->take($count)->get();
82
    }
83
84
    /**
85
     * @ver 5.1.13
86
     * @date 19/03/2018
87
     * @return mixed
88
     */
89
    public function uniqueCreators()
90
    {
91
        return $this->model->all()->unique('creator_id');
0 ignored issues
show
Bug introduced by
The method all does only exist in App\Model\Article and Il...nate\Support\Collection, but not in Illuminate\Database\Eloquent\Builder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
92
    }
93
94
    /**
95
     * @ver 5.1.14
96
     * @date 19/03/2018
97
     * @return mixed
98
     */
99
    public function viewable()
100
    {
101
        return $this->model->where('status', Article::STATUS_PUBLIC)->get();
0 ignored issues
show
Bug introduced by
The method where does only exist in Illuminate\Database\Eloq...nate\Support\Collection, but not in App\Model\Article.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
102
    }
103
104
    /**
105
     * @param int $count
106
     * @return \Illuminate\Contracts\Pagination\Paginator
107
     */
108
    public function paginateLatest(int $count)
109
    {
110
        return $this->publicArticles()->orderBy('created_at', 'desc')->simplePaginate($count);
111
    }
112
113
    /**
114
     * @ver 5.1.13
115
     * @date 19/03/2018
116
     * @return mixed
117
     */
118
    public function activeCategories()
119
    {
120
        return app(ArticleCategoryRepository::class)->whereStatusActive();
121
    }
122
123
    /**
124
     * @ver 5.1.15
125
     * @date 19/03/2018
126
     * @param int $creator_id
127
     * @return int
128
     */
129
    public function publishedArticlesCount(int $creator_id)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $creator_id is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
130
    {
131
        return $this->publicArticles()->where('creator_id', $creator_id)->count();
132
    }
133
134
    /**
135
     * @return \Illuminate\Database\Eloquent\Collection|mixed|static[]
136
     */
137
    public function whereStatusActive()
138
    {
139
        return $this->model->where('status', true)->get();
0 ignored issues
show
Bug introduced by
The method where does only exist in Illuminate\Database\Eloq...nate\Support\Collection, but not in App\Model\Article.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
140
    }
141
142
    public function collectArticle(string $slug)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
143
    {
144
        return $this->publicArticles()->where('slug', $slug)->orderBy('created_at', 'desc')->first();
145
    }
146
147
    /**
148
     * @param string $text
149
     * @param int $paginate
150
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
151
     */
152
    public function searchThenPaginate(string $text, int $paginate = 7)
153
    {
154
        return $this->publicArticles()->search($text)->orderBy('created_at', 'desc')->paginate($paginate);
0 ignored issues
show
Bug introduced by
The method search does only exist in Illuminate\Support\Collection, but not in Illuminate\Database\Eloquent\Builder.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
155
    }
156
157
    public function whereCreatorId(int $creator_id, int $paginate = 5)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Coding Style Naming introduced by
The parameter $creator_id is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
158
    {
159
        return $this->publicArticles()
160
            ->orderBy('created_at', 'desc')
161
            ->where('creator_id', $creator_id)
162
            ->simplePaginate($paginate);
163
    }
164
165
    public function whereCategoryId(int $id, int $paginate = 5)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
166
    {
167
        return $this->publicArticles()
168
            ->where('category_id', $id)
169
            ->orderBy('created_at', 'desc')
170
            ->simplePaginate($paginate);
171
    }
172
}
173