Completed
Push — master ( dc0e70...5c8fc1 )
by Mahmoud
04:17
created

UpdateSettingsService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A findByKey() 0 6 1
A update() 0 10 1
A updateSomething() 0 4 1
1
<?php
2
3
namespace App\Containers\Settings\Services;
4
5
use App\Containers\Settings\Settings\Repositories\SettingsRepository;
6
use App\Port\Service\Abstracts\Service;
7
8
/**
9
 * Class UpdateSettingsService
10
 *
11
 * @author  Mahmoud Zalt  <[email protected]>
12
 */
13
class UpdateSettingsService extends Service
14
{
15
16
    /**
17
     * @var  \App\Containers\Settings\Settings\Repositories\SettingsRepository
18
     */
19
    private $settingsRepository;
20
21
    /**
22
     * FindSettingsService constructor.
23
     *
24
     * @param \App\Containers\Settings\Settings\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