Docs   A
last analyzed

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\Database\Eloquent\Model;
12
use Illuminate\Contracts\Support\Arrayable;
13
use Illuminate\Database\Eloquent\Relations\HasMany;
14
use Service\DocsImporter\DocsConnectionConfigInterface;
15
16
/**
17
 * Class Docs.
18
 */
19
class Docs extends Model
20
{
21
    /**
22
     * @var string
23
     */
24
    protected $table = 'docs';
25
26
    /**
27
     * @var array
28
     */
29
    protected $casts = [
30
        'importer_config' => 'collection',
31
    ];
32
33
    /**
34
     * @return HasMany
35
     */
36
    public function pages(): HasMany
37
    {
38
        return $this->hasMany(DocsPage::class, 'docs_id', 'id');
39
    }
40
41
    /**
42
     * @param DocsConnectionConfigInterface|array $config
43
     */
44
    public function setImporterConfigAttribute($config)
45
    {
46
        $this->attributes['importer_config'] = $config instanceof Arrayable
47
            ? $config->toArray()
48
            : json_encode($config);
49
    }
50
51
    /**
52
     * @param  string $data
53
     * @return array
54
     */
55
    public function getImporterConfigAttribute(string $data): array
56
    {
57
        if ($data) {
58
            return json_decode($data, true);
59
        }
60
61
        return [];
62
    }
63
}
64