PhotoResponse::setPhoto()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the pexels-library package.
5
 *
6
 * (c) 2019 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Pexels\Response;
13
14
use WBW\Library\Pexels\Model\Photo;
15
16
/**
17
 * Photo response.
18
 *
19
 * @author webeweb <https://github.com/webeweb>
20
 * @package WBW\Library\Pexels\Response
21
 */
22
class PhotoResponse extends AbstractMediaResponse {
23
24
    /**
25
     * Get the photo.
26
     *
27
     * @return Photo|null Returns the photo.
28
     */
29
    public function getPhoto(): ?Photo {
30
31
        /** @var Photo[] $medias */
32
        $medias = $this->getMedias();
33
34
        return 1 === count($medias) ? $medias[0] : null;
35
    }
36
37
    /**
38
     * Set the photo.
39
     *
40
     * @param Photo $photo The photo.
41
     * @return PhotoResponse Returns this photo response.
42
     */
43
    public function setPhoto(Photo $photo): PhotoResponse {
44
        return $this->setMedias([$photo]);
45
    }
46
}
47