Completed
Push — master ( 2d22de...e2d103 )
by Sherif
02:14
created

PushNotificationDevicesController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace App\Modules\Notifications\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\Modules\Core\Http\Controllers\BaseApiController;
7
use \App\Modules\Notifications\Repositories\PushNotificationDeviceRepository;
8
use App\Modules\Core\Utl\CoreConfig;
9
10 View Code Duplication
class PushNotificationDevicesController extends BaseApiController
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    /**
13
     * List of all route actions that the base api controller
14
     * will skip permissions check for them.
15
     * @var array
16
     */
17
    protected $skipPermissionCheck = ['registerDevice'];
18
19
    /**
20
     * The validations rules used by the base api controller
21
     * to check before add.
22
     * @var array
23
     */
24
    protected $validationRules = [
25
    'device_token' => 'required|string|max:255',
26
    'user_id'      => 'required|exists:users,id'
27
    ];
28
29
    /**
30
     * Init new object.
31
     *
32
     * @param   PushNotificationDeviceRepository $repo
33
     * @param   CoreConfig                       $config
34
     * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
35
     */
36
    public function __construct(PushNotificationDeviceRepository $repo, CoreConfig $config)
37
    {
38
        parent::__construct($repo, $config, 'App\Modules\Notifications\Http\Resources\PushNotificationDevice');
39
    }
40
41
    /**
42
     * Register the given device to the logged in user.
43
     *
44
     * @param  \Illuminate\Http\Request  $request
45
     * @return \Illuminate\Http\Response
46
     */
47
    public function registerDevice(Request $request)
48
    {
49
        $this->validate($request, [
50
            'device_token' => 'required|string|max:255'
51
            ]);
52
53
        return new $this->modelResource($this->repo->registerDevice($request->all()));
54
    }
55
}
56