PictureParser   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
B fetchSize() 0 31 5
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