Test Failed
Push — feature-laravel-5.4 ( 556e60...89a18e )
by Kirill
03:48
created

Docs   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pages() 0 4 1
A setImporterConfigAttribute() 0 6 2
A getImporterConfigAttribute() 0 8 2
1
<?php
2
/**
3
 * This file is part of laravel.su package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace App\Models;
10
11
use Illuminate\Support\Str;
12
use Illuminate\Database\Eloquent\Model;
13
use Illuminate\Contracts\Support\Arrayable;
14
use Illuminate\Database\Eloquent\Relations\HasMany;
15
use Service\DocsImporter\DocsConnectionConfigInterface;
16
17
/**
18
 * Class Docs.
19
 */
20
class Docs extends Model
21
{
22
    /**
23
     * @var string
24
     */
25
    protected $table = 'docs';
26
27
    /**
28
     * @var array
29
     */
30
    protected $casts = [
31
        'importer_config' => 'collection',
32
    ];
33
34
    /**
35
     * @return HasMany
36
     */
37
    public function pages(): HasMany
38
    {
39
        return $this->hasMany(DocsPage::class);
40
    }
41
42
    /**
43
     * @param DocsConnectionConfigInterface|array $config
44
     */
45
    public function setImporterConfigAttribute($config)
46
    {
47
        $this->attributes['importer_config'] = $config instanceof Arrayable
48
            ? $config->toArray()
49
            : json_encode($config);
50
    }
51
52
    /**
53
     * @param  string $data
54
     * @return array
55
     */
56
    public function getImporterConfigAttribute(string $data): array
57
    {
58
        if ($data) {
59
            return json_decode($data, true);
60
        }
61
62
        return [];
63
    }
64
}
65