Document::isElectronic()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Colligator;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Document extends Model
8
{
9
    /**
10
     * The attributes that are mass assignable.
11
     *
12
     * @var array
13
     */
14
    protected $fillable = ['bibsys_id', 'bibliographic', 'holdings'];
15
16
    /**
17
     * The attributes that should be casted to native types.
18
     *
19
     * @var array
20
     */
21
    protected $casts = [
22
        'id'            => 'integer',
23
        'bibliographic' => 'array',
24
        'holdings'      => 'array',
25
        'xisbn'         => 'array',
26
        'description'   => 'array',
27
    ];
28
29
    /**
30
     * Get subjects associated with this document.
31
     */
32
    public function subjects()
33
    {
34
        return $this->morphedByMany('Colligator\Subject', 'entity')->withTimestamps();
35
    }
36
37
    /**
38
     * Get genres associated with this document.
39
     */
40
    public function genres()
41
    {
42
        return $this->morphedByMany('Colligator\Genre', 'entity')->withTimestamps();
43
    }
44
45
    /**
46
     * The cover belonging to the document.
47
     */
48
    public function cover()
49
    {
50
        return $this->hasOne('Colligator\Cover');
51
    }
52
53
    /**
54
     * Get enrichments associated with this document.
55
     */
56
    public function enrichments()
57
    {
58
        return $this->hasMany('Colligator\Enrichment');
59
    }
60
61
    /**
62
     * Get enrichments associated with this document.
63
     */
64
    public function enrichmentsByService($serviceName)
65
    {
66
        return $this->enrichments()->where('service_name', '=', $serviceName);
67
    }
68
69
    /**
70
     * The collections the document belongs to.
71
     */
72
    public function collections()
73
    {
74
        return $this->belongsToMany('Colligator\Collection');
75
    }
76
77 View Code Duplication
    public function storeCover($url)
0 ignored issues
show
Duplication introduced by
This method 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...
78
    {
79
        $cover = $this->cover;
80
        if (is_null($cover)) {
81
            $cover = new Cover(['document_id' => $this->id]);
82
        }
83
        $cover->url = $url;
84
        $cover->cache();
85
        $cover->save();
86
87
        return $cover;
88
    }
89
90 View Code Duplication
    public function storeCoverFromBlob($blob)
0 ignored issues
show
Duplication introduced by
This method 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...
91
    {
92
        $cover = $this->cover;
93
        if (is_null($cover)) {
94
            $cover = new Cover(['document_id' => $this->id]);
95
        }
96
        $cover->url = null;
97
        $cover->cache($blob);
98
        $cover->save();
99
100
        return $cover;
101
    }
102
103
    public function setCannotFindCover()
104
    {
105
        if ($this->cannot_find_cover) {
106
            $this->cannot_find_cover = $this->cannot_find_cover + 1;
107
        } else {
108
            $this->cannot_find_cover = 1;
109
        }
110
    }
111
112
    public function isElectronic()
113
    {
114
        return $this->bibliographic['electronic'];
115
    }
116
}
117