Completed
Push — master ( fda7e1...904ceb )
by wen
03:37
created

ModelConfig::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace Sco\Admin\Config;
4
5
use Illuminate\Config\Repository as ConfigRepository;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Foundation\Application;
8
use JsonSerializable;
9
use Illuminate\Contracts\Support\Arrayable;
10
use Illuminate\Contracts\Support\Jsonable;
11
use Sco\Admin\Contracts\Config as ConfigContract;
12
use Sco\Admin\Contracts\Repository as RepositoryContract;
13
use Sco\Attributes\HasAttributesTrait;
14
15
/**
16
 * Class ModelConfig
17
 *
18
 * @method static \Illuminate\Database\Eloquent\Model|Model getKeyName()
19
 */
20
class ModelConfig implements Arrayable, Jsonable, JsonSerializable
21
{
22
    use HasAttributesTrait;
23
24
    /**
25
     * @var \Illuminate\Foundation\Application
26
     */
27
    protected $app;
28
29
    /**
30
     * @var \Sco\Admin\Contracts\Config
31
     */
32
    protected $configFactory;
33
    /**
34
     * @var \Illuminate\Database\Eloquent\Model
35
     */
36
    //protected $model;
37
38
    /**
39
     * @var mixed|\Sco\Admin\Contracts\Repository
40
     */
41
    protected $repository;
42
43
    protected $config;
44
45
    public function __construct(Application $app, ConfigContract $factory)
46
    {
47
        $this->app = $app;
48
        $this->configFactory = $factory;
49
        //$this->model = $model;
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
50
        $this->config = new ConfigRepository(
51
            $this->getModelConfig()
0 ignored issues
show
Bug introduced by
The method getModelConfig() does not seem to exist on object<Sco\Admin\Config\ModelConfig>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
        );
53
54
        $this->repository = $this->app->make(RepositoryContract::class);
55
56
        $this->repository->setClass(
57
            $factory->getConfigRepository()->get('model')
58
        );
59
    }
60
61
    public function getRepository()
62
    {
63
        return $this->repository;
64
    }
65
66
    public function paginate($perPage = null)
67
    {
68
        $data = $this->model->paginate($perPage);
0 ignored issues
show
Bug introduced by
The property model does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
69
70
        $data->setCollection($this->parseRows($data->items()));
71
72
        return $data;
73
    }
74
75
    protected function parseRows($rows)
76
    {
77
        $data = collect();
78
        if ($rows) {
79
            foreach ($rows as $row) {
80
                $newRow = collect();
81
                foreach ($this->configFactory->getColumns() as $column) {
82
                    $newRow->put($column->getName(), $column->setModel($row)->render());
83
                }
84
                $data->push($newRow);
85
            }
86
        }
87
        return $data;
88
    }
89
90
    public function get()
91
    {
92
        $data = $this->model->get();
93
        return $data;
94
    }
95
96
    public function delete($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id 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...
97
    {
98
99
    }
100
101
    /**
102
     * Handle dynamic method calls into the model.
103
     *
104
     * @param  string  $method
105
     * @param  array  $parameters
106
     * @return mixed
107
     */
108
    /*public function __call($method, $parameters)
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
109
    {
110
        if (in_array($method, ['getKeyName'])) {
111
            return $this->model->$method(...$parameters);
112
        }
113
114
        $this->model = $this->model->$method(...$parameters);
115
        return $this;
116
    }*/
117
118
    /**
119
     * Handle dynamic static method calls into the method.
120
     *
121
     * @param  string  $method
122
     * @param  array  $parameters
123
     * @return mixed
124
     */
125
    /*public static function __callStatic($method, $parameters)
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
126
    {
127
        return (new static)->$method(...$parameters);
128
    }*/
129
}
130