Completed
Push — master ( 985ed1...fcadec )
by Mahmoud
03:02
created

UpdateWhateverSettingsTask   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 1
dl 41
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A run() 15 15 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\Containers\Settings\Tasks;
4
5
use App\Containers\Settings\Data\Repositories\SettingsRepository;
6
use App\Port\Task\Abstracts\Task;
7
8
/**
9
 * Class UpdateWhateverSettingsTask
10
 *
11
 * @author  Mahmoud Zalt  <[email protected]>
12
 */
13 View Code Duplication
class UpdateWhateverSettingsTask extends Task
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...
14
{
15
16
    /**
17
     * @var  \App\Containers\Settings\Data\Repositories\SettingsRepository
18
     */
19
    private $settingsRepository;
20
21
    /**
22
     * FindSettingsTask constructor.
23
     *
24
     * @param \App\Containers\Settings\Data\Repositories\SettingsRepository $settingsRepository
25
     */
26
    public function __construct(SettingsRepository $settingsRepository)
27
    {
28
        $this->settingsRepository = $settingsRepository;
29
    }
30
31
    /**
32
     * @param $key
33
     * @param $value
34
     *
35
     * @return  mixed
36
     */
37
    public function run($value)
38
    {
39
        $key = 'whatever';
40
41
        // TODO: replace both queries with a single UpdateWhere instead of find and update.
42
        //       this UpdateWhere will need to be added to the repository package (contribution).
43
44
        $setting = $this->settingsRepository->findWhere(['key' => $key])->first();
45
46
        $result = $this->settingsRepository->update([
47
            'value' => $value
48
        ], $setting->id);
49
50
        return $result;
51
    }
52
53
}
54