Completed
Push — master ( ef9f2b...6c3b36 )
by wen
02:34
created

ModelConfig::parseRows()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace Sco\Admin\Config;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Foundation\Application;
7
use JsonSerializable;
8
use Illuminate\Contracts\Support\Arrayable;
9
use Illuminate\Contracts\Support\Jsonable;
10
use Sco\Admin\Contracts\Config as ConfigContract;
11
use Sco\Attributes\HasAttributesTrait;
12
13
/**
14
 * Class ModelConfig
15
 *
16
 * @method static \Illuminate\Database\Eloquent\Model|Model getKeyName()
17
 */
18
class ModelConfig implements Arrayable, Jsonable, JsonSerializable
19
{
20
    use HasAttributesTrait;
21
22
    protected $app;
23
24
    protected $configFactory;
25
    /**
26
     * @var \Illuminate\Database\Eloquent\Model
27
     */
28
    protected $model;
29
30
    public function __construct(Application $app, ConfigContract $factory, Model $model)
31
    {
32
        $this->app = $app;
33
        $this->configFactory = $factory;
34
        $this->model = $model;
35
    }
36
37
    public function paginate($perPage = null)
38
    {
39
        $data = $this->model->paginate($perPage);
40
41
        $data->setCollection($this->parseRows($data->items()));
42
43
        return $data;
44
    }
45
46
    protected function parseRows($rows)
47
    {
48
        $data = collect();
49
        if ($rows) {
50
            foreach ($rows as $row) {
51
                $data->push($this->configFactory->getColumns()->parseRow($row));
52
            }
53
        }
54
        dd($data);
55
        return $data;
56
    }
57
58
    public function get()
59
    {
60
        $data = $this->model->get();
61
        return $data;
62
    }
63
64
    /**
65
     * Handle dynamic method calls into the model.
66
     *
67
     * @param  string  $method
68
     * @param  array  $parameters
69
     * @return mixed
70
     */
71
    public function __call($method, $parameters)
72
    {
73
        if (in_array($method, ['getKeyName'])) {
74
            return $this->model->$method(...$parameters);
75
        }
76
77
        $this->model->$method(...$parameters);
78
        return $this;
79
    }
80
81
    /**
82
     * Handle dynamic static method calls into the method.
83
     *
84
     * @param  string  $method
85
     * @param  array  $parameters
86
     * @return mixed
87
     */
88
    public static function __callStatic($method, $parameters)
89
    {
90
        return (new static)->$method(...$parameters);
0 ignored issues
show
Bug introduced by
The call to ModelConfig::__construct() misses some required arguments starting with $app.
Loading history...
91
    }
92
}
93