Code Duplication    Length = 64-64 lines in 2 locations

src/Platfourm/Category/Repositories/Eloquent/TextRepository.php 1 location

@@ 19-82 (lines=64) @@
16
use Longman\Platfourm\Repository\Events\RepositoryEntityUpdated;
17
use Longman\Platfourm\Text\Models\Eloquent\Text;
18
19
class TextRepository extends BaseRepository implements Repository, RepositoryCriteria
20
{
21
22
    public function model()
23
    {
24
        if (class_exists(\App\Models\Text::class)) {
25
            return \App\Models\Text::class;
26
        }
27
28
        return Text::class;
29
    }
30
31
    /**
32
     * Update a entity in repository by id.
33
     *
34
     * @param  array $attributes
35
     * @param        $id
36
     * @return mixed
37
     */
38
    public function updateValue(array $options, $value)
39
    {
40
        $this->applyScope();
41
        $_skipPresenter = $this->skipPresenter;
42
43
        $this->skipPresenter(true);
44
45
        $model = $this->model->where($options)->first();
46
47
        $model->setAttribute('value', $value);
48
49
        $model->saveOrFail();
50
51
        $this->skipPresenter($_skipPresenter);
52
        $this->resetModel();
53
54
        event(new RepositoryEntityUpdated($this, $model));
55
56
        return $this->parserResult($model);
57
    }
58
59
    public function autosave($locales, $lang, $scope, array $data)
60
    {
61
        $ins          = [];
62
        $ins['scope'] = $scope;
63
        foreach ($data as $key) {
64
            foreach ($locales as $locale => $locale_data) {
65
                $model  = $this->model->newInstance();
66
                $exists = $model->where(['key' => $key, 'lang' => $locale])->exists();
67
                if ($exists) {
68
                    continue;
69
                }
70
71
                $ins['key']   = $key;
72
                $ins['lang']  = $locale;
73
                $ins['value'] = $key;
74
                $model->fill($ins);
75
                $model->save();
76
                $this->resetModel();
77
            }
78
        }
79
        return true;
80
    }
81
82
}
83

src/Platfourm/Text/Repositories/Eloquent/TextRepository.php 1 location

@@ 19-82 (lines=64) @@
16
use Longman\Platfourm\Repository\Events\RepositoryEntityUpdated;
17
use Longman\Platfourm\Text\Models\Eloquent\Text;
18
19
class TextRepository extends BaseRepository implements Repository, RepositoryCriteria
20
{
21
22
    public function model()
23
    {
24
        if (class_exists(\App\Models\Text::class)) {
25
            return \App\Models\Text::class;
26
        }
27
28
        return Text::class;
29
    }
30
31
    /**
32
     * Update a entity in repository by id.
33
     *
34
     * @param  array $attributes
35
     * @param        $id
36
     * @return mixed
37
     */
38
    public function updateValue(array $options, $value)
39
    {
40
        $this->applyScope();
41
        $_skipPresenter = $this->skipPresenter;
42
43
        $this->skipPresenter(true);
44
45
        $model = $this->model->where($options)->first();
46
47
        $model->setAttribute('value', $value);
48
49
        $model->saveOrFail();
50
51
        $this->skipPresenter($_skipPresenter);
52
        $this->resetModel();
53
54
        event(new RepositoryEntityUpdated($this, $model));
55
56
        return $this->parserResult($model);
57
    }
58
59
    public function autosave($locales, $lang, $scope, array $data)
60
    {
61
        $ins          = [];
62
        $ins['scope'] = $scope;
63
        foreach ($data as $key) {
64
            foreach ($locales as $locale => $locale_data) {
65
                $model  = $this->model->newInstance();
66
                $exists = $model->where(['key' => $key, 'lang' => $locale])->exists();
67
                if ($exists) {
68
                    continue;
69
                }
70
71
                $ins['key']   = $key;
72
                $ins['lang']  = $locale;
73
                $ins['value'] = $key;
74
                $model->fill($ins);
75
                $model->save();
76
                $this->resetModel();
77
            }
78
        }
79
        return true;
80
    }
81
82
}
83