Completed
Push — master ( ec2395...0dfd17 )
by Sherif
02:09
created

PushNotificationDeviceController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 54
loc 54
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A insert() 4 4 1
A update() 4 4 1
A registerDevice() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace App\Modules\PushNotificationDevices\Http\Controllers;
4
5
use App\Modules\Core\BaseClasses\BaseApiController;
6
use App\Modules\PushNotificationDevices\Repositories\PushNotificationDeviceRepository;
7
use App\Modules\Core\Utl\CoreConfig;
8
use App\Modules\PushNotificationDevices\Http\Requests\RegisterDevice;
9
use App\Modules\PushNotificationDevices\Http\Requests\InsertPushNotificationDevice;
10
use App\Modules\PushNotificationDevices\Http\Requests\UpdatePushNotificationDevice;
11
12 View Code Duplication
class PushNotificationDeviceController 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...
13
{
14
    /**
15
     * List of all route actions that the base api controller
16
     * will skip permissions check for them.
17
     * @var array
18
     */
19
    protected $skipPermissionCheck = ['registerDevice'];
20
21
    /**
22
     * Init new object.
23
     *
24
     * @param   PushNotificationDeviceRepository $repo
25
     * @param   CoreConfig                       $config
26
     * @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...
27
     */
28
    public function __construct(PushNotificationDeviceRepository $repo, CoreConfig $config)
29
    {
30
        parent::__construct($repo, $config, 'App\Modules\PushNotificationDevices\Http\Resources\PushNotificationDevice');
31
    }
32
33
    /**
34
     * Insert the given model to storage.
35
     *
36
     * @param InsertPushNotificationDevice $request
37
     * @return \Illuminate\Http\Response
38
     */
39
    public function insert(InsertPushNotificationDevice $request)
40
    {
41
        return new $this->modelResource($this->repo->save($request->all()));
42
    }
43
44
    /**
45
     * Update the given model to storage.
46
     *
47
     * @param UpdatePushNotificationDevice $request
48
     * @return \Illuminate\Http\Response
49
     */
50
    public function update(UpdatePushNotificationDevice $request)
51
    {
52
        return new $this->modelResource($this->repo->save($request->all()));
53
    }
54
55
    /**
56
     * Register the given device to the logged in user.
57
     *
58
     * @param RegisterDevice $request
59
     * @return \Illuminate\Http\Response
60
     */
61
    public function registerDevice(RegisterDevice $request)
62
    {
63
        return new $this->modelResource($this->repo->registerDevice($request->all()));
64
    }
65
}
66