GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

PhotoSizeArray::getPhotoSizeWithMinMaxFileSize()   B
last analyzed

Complexity

Conditions 7
Paths 10

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 10
nc 10
nop 1
dl 0
loc 19
rs 8.2222
c 0
b 0
f 0
1
<?php
2
3
namespace Teebot\Api\Entity;
4
5
class PhotoSizeArray extends AbstractEntity
6
{
7
    const ENTITY_TYPE   = 'Photo';
8
9
    const MAX_FILE_SIZE = 'max_file_size';
10
11
    const MIN_FILE_SIZE = 'min_file_size';
12
13
    protected $photoSizes;
14
15
    public function __construct(array $data)
16
    {
17
        if (empty($data)) {
18
            return;
19
        }
20
21
        $photoSizes = $this->initPhotoSizesFromData($data);
22
23
        $this->setPhotoSizes($photoSizes);
24
25
        parent::__construct($data);
26
    }
27
28
    /**
29
     * @return mixed
30
     */
31
    public function getPhotoSizes()
32
    {
33
        return $this->photoSizes;
34
    }
35
36
    /**
37
     * @param mixed $photoSizes
38
     */
39
    public function setPhotoSizes($photoSizes)
40
    {
41
        $this->photoSizes = $photoSizes;
42
    }
43
44
    protected function initPhotoSizesFromData($data)
45
    {
46
        $photoSizes = [];
47
48
        foreach ($data as $photoSizeData) {
49
            if (!empty($photoSizeData)) {
50
                $photoSizes[] = new PhotoSize($photoSizeData);
51
            }
52
        }
53
54
        return $photoSizes;
55
    }
56
57
    public function getPhotoSizeWithMinFileSize()
58
    {
59
        return $this->getPhotoSizeWithMinMaxFileSize(static::MIN_FILE_SIZE);
60
    }
61
62
    public function getPhotoSizeWithMaxFileSize()
63
    {
64
        return $this->getPhotoSizeWithMinMaxFileSize(static::MAX_FILE_SIZE);
65
    }
66
67
    protected function getPhotoSizeWithMinMaxFileSize($minMax)
68
    {
69
        $minMaxPhotoSize = null;
70
71
        foreach ($this->photoSizes as $photoSize) {
72
            if (!$photoSize instanceof PhotoSize) {
73
                continue;
74
            }
75
76
            $size      = $photoSize->getFileSize();
77
            $maxSize   = $minMaxPhotoSize instanceof PhotoSize ? $minMaxPhotoSize->getFileSize() : 0;
78
            $condition = $minMax == static::MAX_FILE_SIZE ? $size > $maxSize : $size < $maxSize;
79
80
            if (!$minMaxPhotoSize || $condition) {
81
                $minMaxPhotoSize = $photoSize;
82
            }
83
        }
84
85
        return $minMaxPhotoSize;
86
    }
87
}