Code Duplication    Length = 30-32 lines in 4 locations

src/Http/Requests/CommentRequest.php 1 location

@@ 10-40 (lines=31) @@
7
use Illuminate\Auth\Access\AuthorizationException;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
class CommentRequest extends FormRequest
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @return bool
16
     */
17
    public function authorize(NewsService $newsService)
18
    {
19
        return $newsService->getNews()
20
            && $this->user()->can('view', $newsService->getNews());
21
    }
22
23
    /**
24
     * Get the validation rules that apply to the request.
25
     *
26
     * @return array
27
     */
28
    public function rules()
29
    {
30
        return [
31
            'news_id' => Helper::$idValidation,
32
            'comment' => 'required',
33
        ];
34
    }
35
36
    public function failedAuthorization()
37
    {
38
        throw new AuthorizationException('You do not have access to this article');
39
    }
40
}
41

src/Http/Requests/GetRequest.php 1 location

@@ 10-39 (lines=30) @@
7
use Illuminate\Auth\Access\AuthorizationException;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
class GetRequest extends FormRequest
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @return bool
16
     */
17
    public function authorize(NewsService $newsService)
18
    {
19
        return $newsService->getNews()
20
            && $this->user()->can('view', $newsService->getNews());
21
    }
22
23
    /**
24
     * Get the validation rules that apply to the request.
25
     *
26
     * @return array
27
     */
28
    public function rules()
29
    {
30
        return [
31
            'news_id' => Helper::$idValidation,
32
        ];
33
    }
34
35
    public function failedAuthorization()
36
    {
37
        throw new AuthorizationException('You do not have access to this article');
38
    }
39
}
40

src/Http/Requests/UpdateImageRequest.php 1 location

@@ 10-40 (lines=31) @@
7
use Illuminate\Auth\Access\AuthorizationException;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
class UpdateImageRequest extends FormRequest
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @return bool
16
     */
17
    public function authorize(NewsService $newsService)
18
    {
19
        return $newsService->getNews()
20
            && $this->user()->can('update', $newsService->getNews());
21
    }
22
23
    /**
24
     * Get the validation rules that apply to the request.
25
     *
26
     * @return array
27
     */
28
    public function rules()
29
    {
30
        return [
31
            'image' => 'required|base64image',
32
            'news_id' => Helper::$idValidation,
33
        ];
34
    }
35
36
    public function failedAuthorization()
37
    {
38
        throw new AuthorizationException('You do not have access to this article');
39
    }
40
}
41

src/Http/Requests/UpdateRequest.php 1 location

@@ 10-41 (lines=32) @@
7
use Illuminate\Auth\Access\AuthorizationException;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
class UpdateRequest extends FormRequest
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @return bool
16
     */
17
    public function authorize(NewsService $newsService)
18
    {
19
        return  $newsService->getNews()
20
            && $this->user()->can('update', $newsService->getNews());
21
    }
22
23
    /**
24
     * Get the validation rules that apply to the request.
25
     *
26
     * @return array
27
     */
28
    public function rules()
29
    {
30
        return [
31
            'title' => 'required|string|between:3,255',
32
            'news' => 'required|string',
33
            'news_id' => Helper::$idValidation,
34
        ];
35
    }
36
37
    public function failedAuthorization()
38
    {
39
        throw new AuthorizationException('You do not have access to this article');
40
    }
41
}
42