APIArticlesController::destroy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Ergare17\Articles\Http\Controllers;
4
5
use Ergare17\Articles\Http\Requests\DestroyArticle;
6
use Ergare17\Articles\Http\Requests\ListArticle;
7
use Ergare17\Articles\Http\Requests\ShowArticle;
8
use Ergare17\Articles\Http\Requests\StoreArticle;
9
use Ergare17\Articles\Http\Requests\UpdateArticle;
10
use Ergare17\Articles\Models\Article;
11
12
class APIArticlesController extends Controller
13
{
14
    public function index(ListArticle $request)
15
    {
16
        return Article::all();
17
    }
18
19
    public function show(ShowArticle $request, Article $article)
20
    {
21
        return $article;
22
    }
23
24
    // Injeccció de depèndències
25
    public function store(StoreArticle $request)
26
    {
27
        $request->validate([
28
            'title' => 'required',
29
        ]);
30
31
        $article = Article::create([
0 ignored issues
show
Bug introduced by
The method create() does not exist on Ergare17\Articles\Models\Article. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
32
            'title' => $request->title,
33
            'description' => $request->description,
34
            'user_id' => $request->user_id
35
        ]);
36
37
        return $article;
38
    }
39
40
    public function destroy(DestroyArticle $request, Article $article)
41
    {
42
        $article->delete();
43
        return $article;
44
    }
45
46
    public function update(UpdateArticle $request, Article $article)
47
    {
48
        $request->validate([
49
            'title' => 'required'
50
        ]);
51
        $article->title = $request->title;
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<Ergare17\Articles\Models\Article>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
52
        $article->save();
53
        return $article;
54
    }
55
}
56