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.
Completed
Push — master ( 64a210...2d6991 )
by Stan
02:42
created

PhotoSizeArray   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 16
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 83
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A getPhotoSizes() 0 4 1
A setPhotoSizes() 0 4 1
A initPhotoSizesFromData() 0 12 3
A getPhotoSizeWithMinFileSize() 0 4 1
A getPhotoSizeWithMaxFileSize() 0 4 1
B getPhotoSizeWithMinMaxFileSize() 0 20 7
1
<?php
2
3
namespace Teebot\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
}