Completed
Push — feature/improve-code ( e986a1...36787d )
by Avtandil
14:14
created

UserProfilePhotos::getTotalCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of the TelegramBot package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\TelegramBot\Entities;
12
13
use Longman\TelegramBot\Exception\TelegramException;
14
15
class UserProfilePhotos extends Entity
16
{
17
    /**
18
     * @var mixed|null
19
     */
20
    protected $total_count;
21
22
    /**
23
     * @var array
24
     */
25
    protected $photos;
26
27
    /**
28
     * UserProfilePhotos constructor.
29
     *
30
     * @param array $data
31
     * @throws \Longman\TelegramBot\Exception\TelegramException
32
     */
33 1
    public function __construct(array $data)
34
    {
35
36 1
        $this->total_count = isset($data['total_count']) ? $data['total_count'] : null;
37 1
        if ($this->total_count === null || !is_numeric($this->total_count)) {
38
            throw new TelegramException('total_count is empty!');
39
        }
40 1
        $this->photos = isset($data['photos']) ? $data['photos'] : null;
41 1
        if ($this->photos === null || !is_array($data['photos'])) {
42
            throw new TelegramException('photos is empty!');
43
        }
44
45 1
        $photos = [];
46 1
        foreach ($this->photos as $key => $photo) {
47 1
            if (is_array($photo)) {
48 1
                foreach ($photo as $photo_size) {
49 1
                    $photos[$key][] = new PhotoSize($photo_size);
50
                }
51
            } else {
52 1
                throw new TelegramException('photo is not an array!');
53
            }
54
        }
55
56 1
        $this->photos = $photos;
57 1
    }
58
59
    /**
60
     * Get total count
61
     *
62
     * @return mixed|null
63
     */
64
    public function getTotalCount()
65
    {
66
        return $this->total_count;
67
    }
68
69
    /**
70
     * Get photos
71
     *
72
     * @return array
73
     */
74 1
    public function getPhotos()
75
    {
76 1
        return $this->photos;
77
    }
78
}
79