Code Duplication    Length = 39-41 lines in 2 locations

app/Containers/Settings/Tasks/UpdateSettingsByKeyTask.php 1 location

@@ 13-51 (lines=39) @@
10
 *
11
 * @author  Mahmoud Zalt  <[email protected]>
12
 */
13
class UpdateSettingsByKeyTask 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
     * @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

app/Containers/Settings/Tasks/UpdateWhateverSettingsTask.php 1 location

@@ 13-53 (lines=41) @@
10
 *
11
 * @author  Mahmoud Zalt  <[email protected]>
12
 */
13
class UpdateWhateverSettingsTask 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
     * @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