Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
12 / 12
CRAP
100.00% covered (success)
100.00%
1 / 1
MediaInfo
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
12 / 12
22
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
4
 getType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setId
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getLabels
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDescriptions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getStatements
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isEmpty
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
3
 equals
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
5
 copy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __clone
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 clear
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Wikibase\MediaInfo\DataModel;
4
5use InvalidArgumentException;
6use Wikibase\DataModel\Entity\ClearableEntity;
7use Wikibase\DataModel\Entity\EntityId;
8use Wikibase\DataModel\Entity\StatementListProvidingEntity;
9use Wikibase\DataModel\Statement\StatementList;
10use Wikibase\DataModel\Term\DescriptionsProvider;
11use Wikibase\DataModel\Term\LabelsProvider;
12use Wikibase\DataModel\Term\TermList;
13
14/**
15 * Entity describing a media file that consists of an id, labels, descriptions and statements.
16 *
17 * @since 0.1
18 *
19 * @license GPL-2.0-or-later
20 * @author Bene* < benestar.wikimedia@gmail.com >
21 */
22class MediaInfo
23    implements StatementListProvidingEntity, LabelsProvider, DescriptionsProvider, ClearableEntity
24{
25
26    public const ENTITY_TYPE = 'mediainfo';
27
28    /**
29     * @var MediaInfoId|null
30     */
31    private $id;
32
33    /**
34     * @var TermList
35     */
36    private $labels;
37
38    /**
39     * @var TermList
40     */
41    private $descriptions;
42
43    /**
44     * @var StatementList
45     */
46    private $statements;
47
48    /**
49     * @param MediaInfoId|null $id
50     * @param TermList|null $labels
51     * @param TermList|null $descriptions
52     * @param StatementList|null $statements
53     */
54    public function __construct(
55        MediaInfoId $id = null,
56        TermList $labels = null,
57        TermList $descriptions = null,
58        StatementList $statements = null
59    ) {
60        $this->id = $id;
61        $this->labels = $labels ?: new TermList();
62        $this->descriptions = $descriptions ?: new TermList();
63        $this->statements = $statements ?: new StatementList();
64    }
65
66    /**
67     * @return string
68     */
69    public function getType() {
70        return self::ENTITY_TYPE;
71    }
72
73    /**
74     * @return MediaInfoId|null
75     */
76    public function getId() {
77        return $this->id;
78    }
79
80    /**
81     * @param EntityId $id
82     *
83     * @throws InvalidArgumentException
84     */
85    public function setId( $id ) {
86        if ( !( $id instanceof MediaInfoId ) ) {
87            throw new InvalidArgumentException( '$id must be an instance of MediaInfoId' );
88        }
89
90        $this->id = $id;
91    }
92
93    /**
94     * @return TermList
95     */
96    public function getLabels() {
97        return $this->labels;
98    }
99
100    /**
101     * @return TermList
102     */
103    public function getDescriptions() {
104        return $this->descriptions;
105    }
106
107    /**
108     * @return StatementList
109     */
110    public function getStatements() {
111        return $this->statements;
112    }
113
114    /**
115     * @return bool
116     */
117    public function isEmpty() {
118        return $this->labels->isEmpty()
119            && $this->descriptions->isEmpty()
120            && $this->statements->isEmpty();
121    }
122
123    /**
124     * @see EntityDocument::equals
125     *
126     * @param mixed $target
127     *
128     * @return bool
129     */
130    public function equals( $target ) {
131        if ( $this === $target ) {
132            return true;
133        }
134
135        return $target instanceof self
136            && $this->labels->equals( $target->labels )
137            && $this->descriptions->equals( $target->descriptions )
138            && $this->statements->equals( $target->statements );
139    }
140
141    /**
142     * @see EntityDocument::copy
143     *
144     * @return MediaInfo
145     */
146    public function copy() {
147        return clone $this;
148    }
149
150    /**
151     * @see http://php.net/manual/en/language.oop5.cloning.php
152     */
153    public function __clone() {
154        $this->labels = clone $this->labels;
155        $this->descriptions = clone $this->descriptions;
156        $this->statements = clone $this->statements;
157    }
158
159    /**
160     * @inheritDoc
161     */
162    public function clear() {
163        $this->labels = new TermList();
164        $this->descriptions = new TermList();
165        $this->statements = new StatementList();
166    }
167
168}