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

UpdateSettingsByKeyTask::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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 UpdateSettingsByKeyTask
10
 *
11
 * @author  Mahmoud Zalt  <[email protected]>
12
 */
13 View Code Duplication
class UpdateSettingsByKeyTask 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($key, $value)
38
    {
39
        // TODO: replace both queries with a single UpdateWhere instead of find and update.
40
        //       this UpdateWhere will need to be added to the repository package (contribution).
41
42
        $setting = $this->settingsRepository->findWhere(['key' => $key])->first();
43
44
        $result = $this->settingsRepository->update([
45
            'value' => $value
46
        ], $setting->id);
47
48
        return $result;
49
    }
50
51
}
52