Completed
Push — master ( 28a127...2ccb51 )
by ARCANEDEV
03:03
created

PostsController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 0
crap 2
1
<?php namespace Arcanesoft\Blog\Http\Controllers\Foundation;
2
3
use Arcanesoft\Blog\Bases\FoundationController;
4
use Arcanesoft\Blog\Models\Post;
5
6
/**
7
 * Class     PostsController
8
 *
9
 * @package  Arcanesoft\Blog\Http\Controllers\Foundation
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class PostsController extends FoundationController
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Properties
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /**
19
     * The post model.
20
     *
21
     * @var \Arcanesoft\Blog\Models\Post
22
     */
23
    private $post;
24
25
    /* ------------------------------------------------------------------------------------------------
26
     |  Constructor
27
     | ------------------------------------------------------------------------------------------------
28
     */
29
    /**
30
     * Instantiate the controller.
31
     *
32
     * @param Post $post
33
     */
34
    public function __construct(Post $post)
35
    {
36
        parent::__construct();
37
38
        $this->post = $post;
39
40
        $this->setCurrentPage('blog-posts');
41
        $this->addBreadcrumbRoute('Posts', 'blog::foundation.posts.index');
42
    }
43
44
    /* ------------------------------------------------------------------------------------------------
45
     |  Main Functions
46
     | ------------------------------------------------------------------------------------------------
47
     */
48
    /**
49
     * List the posts.
50
     *
51
     * @param  bool  $trashed
52
     *
53
     * @return \Illuminate\View\View
54
     */
55
    public function index($trashed = false)
56
    {
57
        $this->authorize('blog.posts.list');
58
59
        $posts = $trashed
60
            ? $this->post->onlyTrashed()->paginate(30)
0 ignored issues
show
Bug introduced by
The method paginate does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\SoftDeletes.

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...
61
            : $this->post->paginate(30);
0 ignored issues
show
Documentation Bug introduced by
The method paginate does not exist on object<Arcanesoft\Blog\Models\Post>? 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...
62
63
        $title = 'List of posts' . ($trashed ? ' - Trashed' : '');
64
        $this->setTitle($title);
65
        $this->addBreadcrumb($title);
66
67
        return $this->view('foundation.posts.list', compact('trashed', 'posts'));
68
    }
69
70
    /**
71
     * List the trashed posts.
72
     *
73
     * @return \Illuminate\View\View
74
     */
75
    public function trash()
76
    {
77
        return $this->index(true);
78
    }
79
80
    public function create()
81
    {
82
        //
83
    }
84
85
    public function store()
86
    {
87
        //
88
    }
89
90
    public function show($post)
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
91
    {
92
        //
93
    }
94
95
    public function edit($post)
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
96
    {
97
        //
98
    }
99
100
    public function update($post)
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
101
    {
102
        //
103
    }
104
105
    public function publish($post)
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
106
    {
107
        //
108
    }
109
110
    public function restore($post)
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111
    {
112
        //
113
    }
114
115
    public function delete($post)
0 ignored issues
show
Unused Code introduced by
The parameter $post is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
116
    {
117
        //
118
    }
119
}
120