Completed
Push — master ( 692c26...a8a0c2 )
by Omar El
02:51
created
app/Listeners/ExampleListener.php 1 patch
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,6 @@
 block discarded – undo
3 3
 namespace App\Listeners;
4 4
 
5 5
 use App\Events\ExampleEvent;
6
-use Illuminate\Queue\InteractsWithQueue;
7
-use Illuminate\Contracts\Queue\ShouldQueue;
8 6
 
9 7
 class ExampleListener
10 8
 {
Please login to merge, or discard this patch.
app/User.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,6 @@
 block discarded – undo
7 7
 use Illuminate\Database\Eloquent\Model;
8 8
 use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
9 9
 use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
10
-
11 10
 use Illuminate\Support\Facades\Hash;
12 11
 
13 12
 class User extends Model implements AuthenticatableContract, AuthorizableContract{
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,11 +40,11 @@
 block discarded – undo
40 40
      * @return int|boolean
41 41
      * @see    https://github.com/lucadegasperi/oauth2-server-laravel/blob/master/docs/authorization-server/password.md
42 42
      */
43
-    public function verify($email, $password){
43
+    public function verify($email, $password) {
44 44
 
45 45
         $user = User::where('email', $email)->first();
46 46
 
47
-        if($user && Hash::check($password, $user->password)){
47
+        if ($user && Hash::check($password, $user->password)) {
48 48
             return $user->id;
49 49
         }
50 50
 
Please login to merge, or discard this patch.
app/Comment.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,22 +9,22 @@
 block discarded – undo
9 9
      *
10 10
      * @var array
11 11
      */
12
-	protected $fillable = ['id', 'post_id', 'user_id', 'content'];
12
+    protected $fillable = ['id', 'post_id', 'user_id', 'content'];
13 13
 
14 14
     /**
15 15
      * The attributes excluded from the model's JSON form.
16 16
      *
17 17
      * @var array
18 18
      */
19
-	protected $hidden   = ['created_at', 'updated_at'];
19
+    protected $hidden   = ['created_at', 'updated_at'];
20 20
 
21 21
     /**
22 22
      * Define an inverse one-to-many relationship with App\Post.
23 23
      *
24 24
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
25 25
      */
26
-	public function post(){
27
-		return $this->belongsTo('App\Post');
28
-	}
26
+    public function post(){
27
+        return $this->belongsTo('App\Post');
28
+    }
29 29
 
30 30
 }
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 use Illuminate\Database\Eloquent\Model;
4 4
 
5
-class Comment extends Model{
5
+class Comment extends Model {
6 6
 
7 7
     /**
8 8
      * The attributes that are mass assignable.
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
      *
17 17
      * @var array
18 18
      */
19
-	protected $hidden   = ['created_at', 'updated_at'];
19
+	protected $hidden = ['created_at', 'updated_at'];
20 20
 
21 21
     /**
22 22
      * Define an inverse one-to-many relationship with App\Post.
23 23
      *
24 24
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
25 25
      */
26
-	public function post(){
26
+	public function post() {
27 27
 		return $this->belongsTo('App\Post');
28 28
 	}
29 29
 
Please login to merge, or discard this patch.
app/Exceptions/Handler.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,15 +48,15 @@
 block discarded – undo
48 48
      */
49 49
     public function render($request, Exception $e)
50 50
     {
51
-        if(env('APP_DEBUG')){
51
+        if (env('APP_DEBUG')) {
52 52
             return parent::render($request, $e);
53 53
         }
54 54
 
55
-        if($e instanceof NotFoundHttpException){
55
+        if ($e instanceof NotFoundHttpException) {
56 56
             return response()->json(['message' => 'Bad Request', 'code' => 400], 400);
57 57
         }
58 58
 
59
-        if($e instanceof MethodNotAllowedHttpException){
59
+        if ($e instanceof MethodNotAllowedHttpException) {
60 60
             return response()->json(['message' => 'Not Found', 'code' => 404], 404);
61 61
         }
62 62
 
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,6 @@
 block discarded – undo
7 7
 use Illuminate\Database\Eloquent\Model;
8 8
 use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
9 9
 use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
10
-
11 10
 use Illuminate\Support\Facades\Hash;
12 11
 
13 12
 class User extends Model implements AuthenticatableContract, AuthorizableContract{
Please login to merge, or discard this patch.
app/Post.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,22 +9,22 @@
 block discarded – undo
9 9
      *
10 10
      * @var array
11 11
      */
12
-	protected $fillable = ['id', 'user_id', 'title', 'content'];
12
+    protected $fillable = ['id', 'user_id', 'title', 'content'];
13 13
 
14 14
     /**
15 15
      * The attributes excluded from the model's JSON form.
16 16
      *
17 17
      * @var array
18 18
      */
19
-	protected $hidden   = ['created_at', 'updated_at'];
19
+    protected $hidden   = ['created_at', 'updated_at'];
20 20
 
21 21
     /**
22 22
      * Define a one-to-many relationship with App\Comment
23 23
      *
24 24
      * @return \Illuminate\Database\Eloquent\Relations\HasMany
25 25
      */
26
-	public function comments(){
27
-		return $this->hasMany('App\Comment');
28
-	}
26
+    public function comments(){
27
+        return $this->hasMany('App\Comment');
28
+    }
29 29
 
30 30
 }
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 
3 3
 use Illuminate\Database\Eloquent\Model;
4 4
 
5
-class Post extends Model{
5
+class Post extends Model {
6 6
 
7 7
     /**
8 8
      * The attributes that are mass assignable.
@@ -16,14 +16,14 @@  discard block
 block discarded – undo
16 16
      *
17 17
      * @var array
18 18
      */
19
-	protected $hidden   = ['created_at', 'updated_at'];
19
+	protected $hidden = ['created_at', 'updated_at'];
20 20
 
21 21
     /**
22 22
      * Define a one-to-many relationship with App\Comment
23 23
      *
24 24
      * @return \Illuminate\Database\Eloquent\Relations\HasMany
25 25
      */
26
-	public function comments(){
26
+	public function comments() {
27 27
 		return $this->hasMany('App\Comment');
28 28
 	}
29 29
 
Please login to merge, or discard this patch.
app/Providers/AuthServiceProvider.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      * @param  array  $arguments
57 57
      * @return boolean
58 58
      */
59
-    private function isOwner($arguments = []){
59
+    private function isOwner($arguments = []) {
60 60
 
61 61
         foreach ($arguments as $resource => $actions) {
62 62
             foreach ($actions as $action) {
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
                 //     }
68 68
                 // });
69 69
 
70
-                Gate::define($this->ability($action, $resource), function ($user, $arg) {
70
+                Gate::define($this->ability($action, $resource), function($user, $arg) {
71 71
                    
72
-                    if(is_null($arg))  { return false; }
72
+                    if (is_null($arg)) { return false; }
73 73
 
74 74
                     return $arg->user_id === $user->id || $user->is_admin;
75 75
                 });            
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
      * @param  array  $arguments
84 84
      * @return boolean
85 85
      */
86
-    private function isAdmin($arguments){
86
+    private function isAdmin($arguments) {
87 87
 
88 88
         foreach ($arguments as $resource => $actions) {
89 89
             foreach ($actions as $action) {
90
-                Gate::define($this->ability($action, $resource), function ($user) {
90
+                Gate::define($this->ability($action, $resource), function($user) {
91 91
                     return $user->is_admin;
92 92
                 });
93 93
             }
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      * @param  string  $resource
102 102
      * @return string
103 103
      */
104
-    private function ability($action, $resource){
104
+    private function ability($action, $resource) {
105 105
         return "{$action}-{$resource}";
106 106
     }
107 107
     
Please login to merge, or discard this patch.
app/Http/Middleware/Authorize.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@
 block discarded – undo
11 11
      * @param  \Closure  $next
12 12
      * @return mixed
13 13
      */
14
-    public function handle($request, Closure $next, $controller){
14
+    public function handle($request, Closure $next, $controller) {
15 15
 
16 16
         $controller = new $controller();
17 17
 
18
-        if(!$controller->isAuthorized($request)){
18
+        if (!$controller->isAuthorized($request)) {
19 19
             return $controller->error("You aren't allowed to perform the requested action", 403);
20 20
         }
21 21
 
Please login to merge, or discard this patch.
app/Http/Controllers/CommentController.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -4,20 +4,20 @@
 block discarded – undo
4 4
 
5 5
 class CommentController extends Controller{
6 6
 
7
-	public function index(){
7
+    public function index(){
8 8
 		
9
-		$comments = Comment::all();
10
-		return $this->success($comments, 200);
11
-	}
9
+        $comments = Comment::all();
10
+        return $this->success($comments, 200);
11
+    }
12 12
 
13
-	public function show($id){
13
+    public function show($id){
14 14
 
15
-		$comment = Comment::find($id);
15
+        $comment = Comment::find($id);
16 16
 
17
-		if(!$comment){
18
-			return $this->error("The comment with {$id} doesn't exist", 404);
19
-		}
17
+        if(!$comment){
18
+            return $this->error("The comment with {$id} doesn't exist", 404);
19
+        }
20 20
 
21
-		return $this->success($comment, 200);
22
-	}
21
+        return $this->success($comment, 200);
22
+    }
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -2,19 +2,19 @@
 block discarded – undo
2 2
 
3 3
 use App\Comment;
4 4
 
5
-class CommentController extends Controller{
5
+class CommentController extends Controller {
6 6
 
7
-	public function index(){
7
+	public function index() {
8 8
 		
9 9
 		$comments = Comment::all();
10 10
 		return $this->success($comments, 200);
11 11
 	}
12 12
 
13
-	public function show($id){
13
+	public function show($id) {
14 14
 
15 15
 		$comment = Comment::find($id);
16 16
 
17
-		if(!$comment){
17
+		if (!$comment) {
18 18
 			return $this->error("The comment with {$id} doesn't exist", 404);
19 19
 		}
20 20
 
Please login to merge, or discard this patch.
app/Http/Controllers/PostController.php 3 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -6,92 +6,92 @@
 block discarded – undo
6 6
 
7 7
 class PostController extends Controller{
8 8
 
9
-	public function __construct(){
9
+    public function __construct(){
10 10
 
11
-		$this->middleware('oauth', ['except' => ['index', 'show']]);
12
-		$this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]);
13
-	}
11
+        $this->middleware('oauth', ['except' => ['index', 'show']]);
12
+        $this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]);
13
+    }
14 14
 
15
-	public function index(){
15
+    public function index(){
16 16
 
17
-		$posts = Post::all();
18
-		return $this->success($posts, 200);
19
-	}
17
+        $posts = Post::all();
18
+        return $this->success($posts, 200);
19
+    }
20 20
 
21
-	public function store(Request $request){
21
+    public function store(Request $request){
22 22
 
23
-		$this->validateRequest($request);
23
+        $this->validateRequest($request);
24 24
 
25
-		$post = Post::create([
26
-					'title' => $request->get('title'),
27
-					'content'=> $request->get('content'),
28
-					'user_id' => $this->getUserId()
29
-				]);
25
+        $post = Post::create([
26
+                    'title' => $request->get('title'),
27
+                    'content'=> $request->get('content'),
28
+                    'user_id' => $this->getUserId()
29
+                ]);
30 30
 
31
-		return $this->success("The post with with id {$post->id} has been created", 201);
32
-	}
31
+        return $this->success("The post with with id {$post->id} has been created", 201);
32
+    }
33 33
 
34
-	public function show($id){
34
+    public function show($id){
35 35
 
36
-		$post = Post::find($id);
36
+        $post = Post::find($id);
37 37
 
38
-		if(!$post){
39
-			return $this->error("The post with {$id} doesn't exist", 404);
40
-		}
38
+        if(!$post){
39
+            return $this->error("The post with {$id} doesn't exist", 404);
40
+        }
41 41
 
42
-		return $this->success($post, 200);
43
-	}
42
+        return $this->success($post, 200);
43
+    }
44 44
 
45
-	public function update(Request $request, $id){
45
+    public function update(Request $request, $id){
46 46
 
47
-		$post = Post::find($id);
47
+        $post = Post::find($id);
48 48
 
49
-		if(!$post){
50
-			return $this->error("The post with {$id} doesn't exist", 404);
51
-		}
49
+        if(!$post){
50
+            return $this->error("The post with {$id} doesn't exist", 404);
51
+        }
52 52
 
53
-		$this->validateRequest($request);
53
+        $this->validateRequest($request);
54 54
 
55
-		$post->title 		= $request->get('title');
56
-		$post->content 		= $request->get('content');
57
-		$post->user_id 		= $this->getUserId();
55
+        $post->title 		= $request->get('title');
56
+        $post->content 		= $request->get('content');
57
+        $post->user_id 		= $this->getUserId();
58 58
 
59
-		$post->save();
59
+        $post->save();
60 60
 
61
-		return $this->success("The post with with id {$post->id} has been updated", 200);
62
-	}
61
+        return $this->success("The post with with id {$post->id} has been updated", 200);
62
+    }
63 63
 
64
-	public function destroy($id){
64
+    public function destroy($id){
65 65
 
66
-		$post = Post::find($id);
66
+        $post = Post::find($id);
67 67
 
68
-		if(!$post){
69
-			return $this->error("The post with {$id} doesn't exist", 404);
70
-		}
68
+        if(!$post){
69
+            return $this->error("The post with {$id} doesn't exist", 404);
70
+        }
71 71
 
72
-		// no need to delete the comments for the current post,
73
-		// since we used on delete cascase on update cascase.
74
-		// $post->comments()->delete();
75
-		$post->delete();
72
+        // no need to delete the comments for the current post,
73
+        // since we used on delete cascase on update cascase.
74
+        // $post->comments()->delete();
75
+        $post->delete();
76 76
 
77
-		return $this->success("The post with with id {$id} has been deleted along with it's comments", 200);
78
-	}
77
+        return $this->success("The post with with id {$id} has been deleted along with it's comments", 200);
78
+    }
79 79
 
80
-	public function validateRequest(Request $request){
80
+    public function validateRequest(Request $request){
81 81
 
82
-		$rules = [
83
-			'title' => 'required', 
84
-			'content' => 'required'
85
-		];
82
+        $rules = [
83
+            'title' => 'required', 
84
+            'content' => 'required'
85
+        ];
86 86
 
87
-		$this->validate($request, $rules);
88
-	}
87
+        $this->validate($request, $rules);
88
+    }
89 89
 
90
-	public function isAuthorized(Request $request){
90
+    public function isAuthorized(Request $request){
91 91
 
92
-		$resource = "posts";
93
-		$post     = Post::find($this->getArgs($request)["post_id"]);
92
+        $resource = "posts";
93
+        $post     = Post::find($this->getArgs($request)["post_id"]);
94 94
 
95
-		return $this->authorizeUser($request, $resource, $post);
96
-	}
95
+        return $this->authorizeUser($request, $resource, $post);
96
+    }
97 97
 }
98 98
\ No newline at end of file
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,6 @@
 block discarded – undo
7 7
 use Illuminate\Database\Eloquent\Model;
8 8
 use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
9 9
 use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
10
-
11 10
 use Illuminate\Support\Facades\Hash;
12 11
 
13 12
 class User extends Model implements AuthenticatableContract, AuthorizableContract{
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -6,21 +6,21 @@  discard block
 block discarded – undo
6 6
 
7 7
 use Illuminate\Http\Request;
8 8
 
9
-class PostController extends Controller{
9
+class PostController extends Controller {
10 10
 
11
-	public function __construct(){
11
+	public function __construct() {
12 12
 
13 13
 		$this->middleware('oauth', ['except' => ['index', 'show']]);
14
-		$this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]);
14
+		$this->middleware('authorize:'.__CLASS__, ['except' => ['index', 'show', 'store']]);
15 15
 	}
16 16
 
17
-	public function index(){
17
+	public function index() {
18 18
 
19 19
 		$posts = Post::all();
20 20
 		return $this->success($posts, 200);
21 21
 	}
22 22
 
23
-	public function store(Request $request){
23
+	public function store(Request $request) {
24 24
 
25 25
 		$this->validateRequest($request);
26 26
 
@@ -33,28 +33,28 @@  discard block
 block discarded – undo
33 33
 		return $this->success("The post with with id {$post->id} has been created", 201);
34 34
 	}
35 35
 
36
-	public function show($id){
36
+	public function show($id) {
37 37
 
38 38
 		$post = Post::find($id);
39 39
 
40
-		if(!$post){
40
+		if (!$post) {
41 41
 			return $this->error("The post with {$id} doesn't exist", 404);
42 42
 		}
43 43
 
44 44
 		return $this->success($post, 200);
45 45
 	}
46 46
 
47
-	public function update(Request $request, $id){
47
+	public function update(Request $request, $id) {
48 48
 
49 49
 		$post = Post::find($id);
50 50
 
51
-		if(!$post){
51
+		if (!$post) {
52 52
 			return $this->error("The post with {$id} doesn't exist", 404);
53 53
 		}
54 54
 
55 55
 		$this->validateRequest($request);
56 56
 
57
-		$post->title 		= $request->get('title');
57
+		$post->title = $request->get('title');
58 58
 		$post->content 		= $request->get('content');
59 59
 		$post->user_id 		= $this->getUserId();
60 60
 
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
 		return $this->success("The post with with id {$post->id} has been updated", 200);
64 64
 	}
65 65
 
66
-	public function destroy($id){
66
+	public function destroy($id) {
67 67
 
68 68
 		$post = Post::find($id);
69 69
 
70
-		if(!$post){
70
+		if (!$post) {
71 71
 			return $this->error("The post with {$id} doesn't exist", 404);
72 72
 		}
73 73
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 		return $this->success("The post with with id {$id} has been deleted along with it's comments", 200);
80 80
 	}
81 81
 
82
-	public function validateRequest(Request $request){
82
+	public function validateRequest(Request $request) {
83 83
 
84 84
 		$rules = [
85 85
 			'title' => 'required', 
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 		$this->validate($request, $rules);
90 90
 	}
91 91
 
92
-	public function isAuthorized(Request $request){
92
+	public function isAuthorized(Request $request) {
93 93
 
94 94
 		$resource = "posts";
95 95
 		$post     = Post::find($this->getArgs($request)["post_id"]);
Please login to merge, or discard this patch.