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 — development ( bf19a3...ad65b0 )
by José
08:52
created

PostsController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace DoeSangue\Http\Controllers\API;
4
5
use Illuminate\Http\Request;
6
use DoeSangue\Http\Requests\CreatePostRequest;
7
use DoeSangue\Http\Requests\UpdatePostRequest;
8
use DoeSangue\Http\Controllers\Controller;
9
use DoeSangue\Models\Post;
10
11
class PostsController extends Controller
12
{
13
    public function __construct()
14
    {
15
        $this->middleware('jwt.auth', ['except' => ['index', 'show']]);
16
    }
17
18
    public function index()
19
    {
20
        $posts = Post::all();
21
22
        return response()->json(compact('posts'));
23
    }
24
25
    public function show($id)
26
    {
27
        $post = Post::find($id);
28
29
        if (!$post) {
30
          return response()->json(
31
            [
32
              'error_code' => '404',
33
              'message' => 'Post not found!'
34
            ], 404);
35
        }
36
37
        return response()->json(compact('post'));
38
    }
39
40
    public function store(CreatePostRequest $request)
41
    {
42
        $post = new Post();
43
        $post->title = $request[ 'title' ];
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<DoeSangue\Models\Post>. 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...
44
        $post->content = $request[ 'content' ];
0 ignored issues
show
Documentation introduced by
The property content does not exist on object<DoeSangue\Models\Post>. 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...
45
        $post->image = $request[ 'image' ];
0 ignored issues
show
Documentation introduced by
The property image does not exist on object<DoeSangue\Models\Post>. 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...
46
        $post->user_id = $request[ 'user_id' ];
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<DoeSangue\Models\Post>. 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...
47
48
        return response()->json(compact('post'));
49
    }
50
51
    /**
52
     * Update Post by ID
53
     *
54
     * @method update
55
     *
56
     * @param UpdatePostRequest $request
57
     * @param integer           $id
58
     *
59
     * @return \Illuminate\Http\JsonResponse
60
     */
61
62
    public function update(UpdatePostRequest $request, $id)
63
    {
64
        $post = Campaign::find($id);
65
        $post->title = $request[ 'title' ];
66
        $post->content = $request[ 'content' ];
67
        $post->image = $request[ 'image' ];
68
        $post->user_id = $request[ 'user_id' ];
69
        $post->save();
70
71
        return response()->json([ 'message' => 'Post Updated' ]);
72
    }
73
74
    public function destroy($id)
75
    {
76
        $post = Post::find($id);
77
78
79
        if (!$post) {
80
          return response()->json(
81
            [
82
              'error_code' => '404',
83
              'message' => 'Post not found!'
84
            ], 404);
85
        }
86
87
        $post->delete();
88
89
        return response()->json(
90
          [
91
            'title' => $post->title,
92
            'content' => $post->content,
93
            'image' => $post->image,
94
            'user_id' => $post->user_id,
95
            'message' => 'Post delected',
96
          ]);
97
    }
98
}
99