Skip to content

Commit

Permalink
Added comment dependency injection to ICommentPolicy, reformat of com…
Browse files Browse the repository at this point in the history
…ment controller
  • Loading branch information
iooe committed Mar 30, 2019
1 parent 974eae5 commit 41853fb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/Contracts/ICommentPolicy.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace tizis\laraComments\Contracts;
use tizis\laraComments\Entity\Comment;

/**
* Comment auth policy
Expand All @@ -10,11 +11,11 @@
*/
interface ICommentPolicy
{
public function edit($user, $comment);
public function edit($user, Comment $comment);

public function delete($user, $comment);
public function delete($user, Comment $comment);

public function reply($user, $comment);
public function reply($user, Comment $comment);

public function vote($user, $comment);
public function vote($user, Comment $comment);
}
3 changes: 1 addition & 2 deletions src/Http/Controllers/CommentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Auth;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use tizis\laraComments\Entity\Comment;
Expand All @@ -19,7 +18,7 @@

class CommentsController extends Controller
{
use ValidatesRequests, AuthorizesRequests;
use AuthorizesRequests;

protected $commentService;
protected $voteService;
Expand Down
14 changes: 7 additions & 7 deletions src/Policies/CommentPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ class CommentPolicy implements ICommentPolicy
{
/**
* @param $user
* @param $comment
* @param Comment $comment
* @return bool
*/
public function delete($user, $comment): bool
public function delete($user, Comment $comment): bool
{
return $user->id === $comment->commenter_id;
}

/**
* @param $user
* @param $comment
* @param Comment $comment
* @return bool
*/
public function edit($user, $comment): bool
public function edit($user, Comment $comment): bool
{
return $user->id === $comment->commenter_id;
}
Expand All @@ -32,17 +32,17 @@ public function edit($user, $comment): bool
* @param Comment $comment
* @return bool
*/
public function reply($user, $comment): bool
public function reply($user, Comment $comment): bool
{
return true;
}

/**
* @param $user
* @param $comment
* @param Comment $comment
* @return bool
*/
public function vote($user, $comment): bool
public function vote($user, Comment $comment): bool
{
return $user->id !== $comment->commenter_id;
}
Expand Down

0 comments on commit 41853fb

Please sign in to comment.