Passed
Push — master ( 7d362e...62822e )
by Omar El
02:41
created
app/Comment.php 1 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 1 patch
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.
app/Post.php 1 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 1 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/routes.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@
 block discarded – undo
12 12
 */
13 13
 
14 14
 // Home Page
15
-$app->get('/', function () use ($app){
15
+$app->get('/', function() use ($app){
16 16
 	return $app->version();
17 17
 });
18 18
 
19 19
 // Posts
20
-$app->get('/posts','PostController@index');
21
-$app->post('/posts','PostController@store');
22
-$app->get('/posts/{post_id}','PostController@show');
20
+$app->get('/posts', 'PostController@index');
21
+$app->post('/posts', 'PostController@store');
22
+$app->get('/posts/{post_id}', 'PostController@show');
23 23
 $app->put('/posts/{post_id}', 'PostController@update');
24 24
 $app->patch('/posts/{post_id}', 'PostController@update');
25 25
 $app->delete('/posts/{post_id}', 'PostController@destroy');
Please login to merge, or discard this patch.
app/User.php 1 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/Http/Controllers/PostCommentController.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,19 +7,19 @@  discard block
 block discarded – undo
7 7
 
8 8
 use Illuminate\Http\Request;
9 9
 
10
-class PostCommentController extends Controller{
10
+class PostCommentController extends Controller {
11 11
 
12
-	public function __construct(){
12
+	public function __construct() {
13 13
 		
14 14
 		$this->middleware('oauth', ['except' => ['index', 'show']]);
15
-		$this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]);
15
+		$this->middleware('authorize:'.__CLASS__, ['except' => ['index', 'show', 'store']]);
16 16
 	}
17 17
 
18
-	public function index($post_id){
18
+	public function index($post_id) {
19 19
 
20 20
 		$post = Post::find($post_id);
21 21
 
22
-		if(!$post){
22
+		if (!$post) {
23 23
 			return $this->error("The post with {$post_id} doesn't exist", 404);
24 24
 		}
25 25
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 		return $this->success($comments, 200);
28 28
 	}
29 29
 
30
-	public function store(Request $request, $post_id){
30
+	public function store(Request $request, $post_id) {
31 31
 		
32 32
 		$post = Post::find($post_id);
33 33
 
34
-		if(!$post){
34
+		if (!$post) {
35 35
 			return $this->error("The post with {$post_id} doesn't exist", 404);
36 36
 		}
37 37
 
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
 		return $this->success("The comment with id {$comment->id} has been created and assigned to the post with id {$post_id}", 201);
47 47
 	}
48 48
 
49
-	public function update(Request $request, $post_id, $comment_id){
49
+	public function update(Request $request, $post_id, $comment_id) {
50 50
 
51
-		$comment 	= Comment::find($comment_id);
52
-		$post 		= Post::find($post_id);
51
+		$comment = Comment::find($comment_id);
52
+		$post = Post::find($post_id);
53 53
 
54
-		if(!$comment || !$post){
54
+		if (!$comment || !$post) {
55 55
 			return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404);
56 56
 		}
57 57
 
@@ -66,16 +66,16 @@  discard block
 block discarded – undo
66 66
 		return $this->success("The comment with with id {$comment->id} has been updated", 200);
67 67
 	}
68 68
 
69
-	public function destroy($post_id, $comment_id){
69
+	public function destroy($post_id, $comment_id) {
70 70
 		
71
-		$comment 	= Comment::find($comment_id);
72
-		$post 		= Post::find($post_id);
71
+		$comment = Comment::find($comment_id);
72
+		$post = Post::find($post_id);
73 73
 
74
-		if(!$comment || !$post){
74
+		if (!$comment || !$post) {
75 75
 			return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404);
76 76
 		}
77 77
 
78
-		if(!$post->comments()->find($comment_id)){
78
+		if (!$post->comments()->find($comment_id)) {
79 79
 			return $this->error("The comment with id {$comment_id} isn't assigned to the post with id {$post_id}", 409);
80 80
 		}
81 81
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 		return $this->success("The comment with id {$comment_id} has been removed of the post {$post_id}", 200);
85 85
 	}
86 86
 
87
-	public function validateRequest(Request $request){
87
+	public function validateRequest(Request $request) {
88 88
 
89 89
 		$rules = [
90 90
 			'content' => 'required'
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		$this->validate($request, $rules);
94 94
 	}
95 95
 
96
-	public function isAuthorized(Request $request){
96
+	public function isAuthorized(Request $request) {
97 97
 
98 98
 		$resource  = "comments";
99 99
 		$comment   = Comment::find($this->getArgs($request)["comment_id"]);
Please login to merge, or discard this patch.