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

UserProfilePhotos   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 88.24%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 64
rs 10
ccs 15
cts 17
cp 0.8824

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTotalCount() 0 4 1
D __construct() 0 25 10
A getPhotos() 0 4 1
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