Installer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getBinaries() 0 23 4
A getRootPath() 0 4 1
1
<?php
2
3
namespace Dumkaaa\BxOptimize\Install;
4
5
use Composer\Script\Event;
6
7
class Installer
8
{
9
    protected static $tools = [
10
        'gif'      => 'gifsicle',
11
        'png'      => 'optipng',
12
        'jpg'      => 'jpegtran',
13
        'pngquant' => 'pngquant',
14
    ];
15
16
    protected static $extByPlatforms = [
17
        'linux' => '-linux',
18
        'win' => '.exe',
19
    ];
20
21
    /**
22
     * Скачивает бинарники и кладёт их в папку bin/.
23
     *
24
     * @param Event $event
25
     */
26
    public static function getBinaries(Event $event)
27
    {
28
        $dir = self::getRootPath() . '/bin';
29
30
        if (!file_exists($dir)) {
31
            mkdir($dir);
32
        }
33
34
        $event->getIO()->write("<info>Setup binaries to $dir :</info>");
35
36
        foreach (self::$extByPlatforms as $ext) {
37
            foreach (self::$tools as $tool) {
38
                file_put_contents(
39
                    $dir . '/' . $tool . $ext,
40
                    fopen('https://github.com/nosilver4u/ewww-image-optimizer/raw/master/binaries/' . $tool . $ext, 'r')
41
                );
42
                chmod($dir . '/' . $tool . $ext, 0754);
43
                $event->getIO()->write($tool . $ext);
44
            }
45
        }
46
47
        $event->getIO()->write('<info>Setup binaries complete.</info>');
48
    }
49
50
    public static function getRootPath()
51
    {
52
        return dirname(dirname(__DIR__));
53
    }
54
}
55