Completed
Push — master ( d8e2a0...679457 )
by Mahmoud
04:23
created

UpdateSettingsTask::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
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 UpdateSettingsTask
10
 *
11
 * @author  Mahmoud Zalt  <[email protected]>
12
 */
13
class UpdateSettingsTask extends Task
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
     *
34
     * @return  mixed
35
     */
36
    private function findByKey($key)
37
    {
38
        $result = $this->settingsRepository->findWhere(['key' => $key])->first();
39
40
        return $result;
41
    }
42
43
    /**
44
     * @param $key
45
     * @param $value
46
     *
47
     * @return  mixed
48
     */
49
    public function update($key, $value)
50
    {
51
        $setting = $this->findByKey($key);
52
53
        $result = $this->settingsRepository->update([
54
            'value' => $value
55
        ], $setting->id);
56
57
        return $result;
58
    }
59
60
    /**
61
     * @param $value
62
     *
63
     * @return  mixed
64
     */
65
    public function updateSomething($value)
66
    {
67
        return $this->update('something', $value);
68
    }
69
70
}
71