PictureParser::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Image Size Finder
5
 *
6
 * (c) Nexuslink Services
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 ImageSizeFinder;
13
14
use Symfony\Component\Yaml\Yaml;
15
use ImageSizeFinder\src\Services\ImageUtility;
16
17
class PictureParser {
18
19
    private $pathToYml;
20
21
    public function __construct($pathToYml = '') {
22
23
        if (!empty($pathToYml)) {
24
            $this->pathToYml = $pathToYml;
25
        } else {
26
            $this->pathToYml = __DIR__."/../Resources/config/config.yml";
27
        }
28
    }
29
30
    /**
31
     * @param array $images
32
     * 
33
     * @return array
34
     */
35
    public function fetchSize($images) {
36
        
37
        if (empty($images))
38
        {
39
            return [];
40
        }
41
        
42
        $configArray = Yaml::parse(file_get_contents($this->pathToYml));
43
        $minSize = $configArray['image_size']['minimum'];
44
        $maxSize = $configArray['image_size']['maximum'];
45
        
46
        $imageList = array();
47
        
48
        foreach ($images as $key => $image) {
49
            $imageList[$key]['url'] = $image;
50
            $imageList[$key]['size'] = ImageUtility::getSize($image);
51
            
52
            list($width, $height) = getimagesize($image);
53
            $imageList[$key]['height'] = $height;
54
            $imageList[$key]['width']  = $width;
55
            
56
            $imageList[$key]['valid'] = true;
57
            
58
            if ($imageList[$key]['size'] < $minSize || $imageList[$key]['size'] > $maxSize)
59
            {
60
                $imageList[$key]['valid'] = false;
61
            }
62
        }
63
        
64
        return $imageList;
65
    }
66
    
67
}
68