Completed
Push — master ( ca1db9...a19c54 )
by Andrii
02:44
created

DoController   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getIconsList() 0 15 3
B genCss() 0 28 5
A actionGenCss() 0 4 1
A actionWriteCss() 0 4 1
B actionWritePreviews() 0 21 5
1
<?php
2
3
/*
4
 * 50+ icons for payment systems and methods
5
 *
6
 * @link      https://github.com/hiqdev/payment-icons
7
 * @package   payment-icons
8
 * @license   MIT
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\paymenticons\console;
13
14
use hidev\helpers\FileHelper;
15
use Yii;
16
17
class DoController extends \yii\console\Controller
18
{
19
    /**
20
     * Returns list of icons.
21
     * @return array
22
     */
23
    public function getIconsList()
24
    {
25
        $dir = Yii::getAlias('@hiqdev/paymenticons/assets/png/xs');
26
        $files = scandir($dir);
27
        $list = [];
28
        foreach ($files as $file) {
29
            if ($file[0] === '.') {
30
                continue;
31
            }
32
            $name = pathinfo($file)['filename'];
33
            $list[$name] = $name;
34
        }
35
36
        return $list;
37
    }
38
39
    /**
40
     * Generates CSS file.
41
     * @return string
42
     */
43
    public function genCss()
44
    {
45
        $sizes = [
46
            'xs' => 'height: 38px; width: 60px;',
47
            'sm' => 'height: 75px; width: 120px;',
48
            'md' => 'height: 240px; width: 150px;',
49
            'lg' => 'height: 480px; width: 300px;',
50
        ];
51
52
        $res = '.pi { display: inline-block;height: 38px;width: 60px; }' . PHP_EOL;
53
54
        foreach (array_keys($sizes) as $size) {
55
            $res .= ".pi.pi-$size { $sizes[$size] }" . PHP_EOL;
56
        }
57
58
        foreach (array_keys($sizes) as $size) {
59
            foreach ($this->getIconsList() as $name) {
60
                if ($size === 'xs') {
61
                    $res .= ".pi.pi-$size.pi-$name, .pi.pi-$name { background: url('../png/$size/$name.png') no-repeat right; }" . PHP_EOL;
62
                } else {
63
                    $res .= ".pi.pi-$size.pi-$name { background: url('../png/$size/$name.png') no-repeat right; }" . PHP_EOL;
64
                }
65
            }
66
            $res .= PHP_EOL;
67
        }
68
69
        return $res;
70
    }
71
72
    public function actionGenCss()
73
    {
74
        echo $this->genCss();
75
    }
76
77
    public function actionWriteCss()
78
    {
79
        FileHelper::write('@hiqdev/paymenticons/assets/css/payment-icons.css', $this->genCss());
80
    }
81
82
    public function actionWritePreviews()
83
    {
84
        $sizes = ['xs', 'sm', 'md', 'lg'];
85
86
        foreach ($sizes as $size) {
87
            $str = '';
88
            foreach ($this->getIconsList() as $name) {
89
                $str .= "![$name](https://raw.githubusercontent.com/hiqdev/payment-icons/master/src/assets/png/$size/$name.png)\n";
90
            }
91
            FileHelper::write('@hiqdev/paymenticons/../docs/Preview' . strtoupper($size) . '.md', $str);
92
            if ($size === 'xs') {
93
                $ps = [];
94
                foreach ($sizes as $s) {
95
                    $us = strtoupper($s);
96
                    $ps[] = "[$us](docs/Preview$us.md)";
97
                }
98
                $str .= "\n" . implode(' | ', $ps);
99
                FileHelper::write('@hiqdev/paymenticons/../docs/readme/Preview.md', $str);
100
            }
101
        }
102
    }
103
}
104