TextRepository::updateValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 11

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 2
dl 20
loc 20
ccs 0
cts 13
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Laravel Platfourm package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\Platfourm\Text\Repositories\Eloquent;
12
13
use Longman\Platfourm\Contracts\Repository\Repository;
14
use Longman\Platfourm\Contracts\Repository\RepositoryCriteria;
15
use Longman\Platfourm\Repository\Eloquent\BaseRepository;
16
use Longman\Platfourm\Repository\Events\RepositoryEntityUpdated;
17
use Longman\Platfourm\Text\Models\Eloquent\Text;
18
19 View Code Duplication
class TextRepository extends BaseRepository implements Repository, RepositoryCriteria
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...
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
0 ignored issues
show
Bug introduced by
There is no parameter named $attributes. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $lang is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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