Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
14 / 14
CRAP
100.00% covered (success)
100.00%
1 / 1
pvcExifImage
100.00% covered (success)
100.00%
22 / 22
100.00% covered (success)
100.00%
14 / 14
19
100.00% covered (success)
100.00%
1 / 1
 setImageid
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getImageid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setWho
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 isValidProperName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addNameToWho
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 whoContains
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 removeNameFromWho
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 getWho
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setEvent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getEvent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setWhen
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getWhen
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setWhere
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getWhere
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * @author: Doug Wilbourne (dougwilbourne@gmail.com)
5 */
6
7declare (strict_types=1);
8
9
10namespace pvc\exif;
11
12
13use DateTime;
14use pvc\exif\err\_ExceptionFactory;
15use pvc\exif\err\InvalidImageIdException;
16use pvc\exif\err\InvalidProperNameException;
17
18/**
19 * Class pvcExifImage
20 */
21class pvcExifImage
22{
23    /**
24     * @var int<0, max> $imageid.  Unique id for this image.  This id is allocated by a relational database and is
25     * used as the primary key for accessing information about the image in a relational database environment.  For
26     * example, if Doug and Patricia and David comprise a family, that relationship can be modeled in a relational
27     * (sorry for the pun)  database. Those relationships cannot possibly be stored in individual image files, so we
28     * need a link between each image and the database that tracks images.
29     */
30    protected int $imageid;
31
32    /**
33     * @var string[] $who.  each entry in the array is the name of a person.  This info is used to be able to search
34     * through a collection of files containing exif info and pull out those where a specific person appears.
35     */
36    protected array $who = [];
37
38    /**
39     * @var string $event.  A description of the event that was occurring when the image was captured.  For example,
40     * a birthday party, a vacation, etc.  I almost named this attribute "what", especially because "event" in
41     * computer programming often refers to some sort of software event, but in the end I decided that event was the
42     * clearest descriptor.
43     */
44    protected string $event;
45
46    /**
47     * @var DateTime $when. Date and time that the image was captured.
48     */
49    protected DateTime $when;
50
51    /**
52     * @var string $where.  Text description of where the image was captured.
53     */
54    protected string $where;
55
56    /**
57     * @function setImageid
58     * @param int<0, max> $imageid
59     */
60    public function setImageid(int $imageid): void
61    {
62        if ($imageid < 0) {
63            throw _ExceptionFactory::createException(InvalidImageIdException::class, [$imageid]);
64        }
65        $this->imageid = $imageid;
66    }
67
68    /**
69     * @function getImageid
70     * @return int
71     */
72    public function getImageid(): int
73    {
74        return $this->imageid;
75    }
76
77    /**
78     * @function setWho
79     * @param string[] $who
80     */
81    public function setWho(array $who): void
82    {
83        foreach ($who as $properName) {
84            if (!$this->isValidProperName($properName)) {
85                throw _ExceptionFactory::createException(InvalidProperNameException::class, [$properName]);
86            }
87        }
88        $this->who = $who;
89    }
90
91    private function isValidProperName(mixed $name) : bool
92    {
93        return is_string($name);
94    }
95
96    /**
97     * @function addNameToWho
98     * @param mixed $name
99     */
100    public function addNameToWho(mixed $name) : void
101    {
102        /**
103         * typehinting is removed from the signature and instead this uses the validity test.  If there are
104         * additional validation rules put in place later the code here will not require modification
105         */
106        if (!$this->isValidProperName($name)) {
107            throw _ExceptionFactory::createException(InvalidProperNameException::class, [$name]);
108        }
109        $this->who[] = $name;
110    }
111
112    /**
113     * whoContains
114     * @param string $name
115     * @return bool
116     */
117    public function whoContains(string $name) : bool
118    {
119        return in_array($name, $this->who);
120    }
121
122    /**
123     * function removeNameFromWho.  If array_search returns a key, then unset that key
124     * @param string $name
125     */
126    public function removeNameFromWho(string $name) : void
127    {
128        if (false !== ($key = array_search($name, $this->who))) {
129            unset($this->who[$key]);
130        }
131    }
132
133    /**
134     * @function getWho
135     * @return string[]
136     */
137    public function getWho(): array
138    {
139        return $this->who;
140    }
141
142    /**
143     * @function setEvent
144     * @param string $event
145     */
146    public function setEvent(string $event): void
147    {
148        $this->event = $event;
149    }
150
151    /**
152     * @function getEvent
153     * @return string
154     */
155    public function getEvent(): string
156    {
157        return $this->event;
158    }
159
160    /**
161     * @function setWhen
162     * @param DateTime $when
163     */
164    public function setWhen(DateTime $when): void
165    {
166        $this->when = $when;
167    }
168
169    /**
170     * @function getWhen
171     * @return DateTime
172     */
173    public function getWhen(): DateTime
174    {
175        return $this->when;
176    }
177
178    /**
179     * @function setWhere
180     * @param string $where
181     */
182    public function setWhere(string $where): void
183    {
184        $this->where = $where;
185    }
186
187    /**
188     * @function getWhere
189     * @return string
190     */
191    public function getWhere(): string
192    {
193        return $this->where;
194    }
195
196
197}