Completed
Push — master ( 7f07e9...1c1a0a )
by Vladimir
02:17
created

TinifyData::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
eloc 0
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the yii2-tinify package.
5
 *
6
 * (c) Vladimir Kuprienko <[email protected]>
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 vintage\tinify\helpers;
13
14
use Yii;
15
16
/**
17
 * Data helper.
18
 *
19
 * @author Vladimir Kuprienko <[email protected]>
20
 * @since 1.0
21
 */
22
class TinifyData
23
{
24
    const PARAM_KEY_API_TOKEN = 'tinify-api-token';
25
26
    /**
27
     * This class should not be instantiated.
28
     */
29
    private function __construct()
30
    {
31
    }
32
33
    /**
34
     * Returns API token from application params.
35
     *
36
     * @return null|string
37
     */
38
    public static function getApiToken()
39
    {
40
        if (!empty(Yii::$app->params[self::PARAM_KEY_API_TOKEN])) {
41
            return Yii::$app->params[self::PARAM_KEY_API_TOKEN];
42
        }
43
44
        return null;
45
    }
46
47
    /**
48
     * Returns allowed mime types.
49
     *
50
     * @return array
51
     */
52
    public static function getAllowedMimeTypes()
53
    {
54
        return ['image/jpeg', 'image/png'];
55
    }
56
57
    /**
58
     * Check whether compressing is allowed for current file.
59
     *
60
     * @param string $fileName
61
     *
62
     * @return bool
63
     *
64
     * @since 2.0
65
     */
66
    public static function allowCompression($fileName)
67
    {
68
        return in_array(mime_content_type($fileName), self::getAllowedMimeTypes());
69
    }
70
}
71