BaseUpload   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 80.95%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 4
dl 0
loc 54
ccs 17
cts 21
cp 0.8095
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 11 2
A initI18N() 0 12 2
1
<?php
2
/**
3
 * @link https://github.com/2amigos/yii2-file-upload-widget
4
 * @copyright Copyright (c) 2013-2017 2amigOS! Consulting Group LLC
5
 * @license http://opensource.org/licenses/BSD-3-Clause
6
 */
7
8
namespace dosamigos\fileupload;
9
10
use Yii;
11
use yii\base\InvalidConfigException;
12
use yii\helpers\Url;
13
use yii\widgets\InputWidget;
14
15
/**
16
 * Base class for both uploaders.
17
 *
18
 * @author Antonio Ramirez <[email protected]>
19
 */
20
class BaseUpload extends InputWidget
21
{
22
    /**
23
     * @var string|array upload route
24
     */
25
    public $url;
26
    /**
27
     * @var array the plugin options. For more information see the jQuery File Upload options documentation.
28
     * @see https://github.com/blueimp/jQuery-File-Upload/wiki/Options
29
     */
30
    public $clientOptions = [];
31
    /**
32
     * @var array the event handlers for the jQuery File Upload plugin.
33
     * Please refer to the jQuery File Upload plugin web page for possible options.
34
     * @see https://github.com/blueimp/jQuery-File-Upload/wiki/Options#callback-options
35
     */
36
    public $clientEvents = [];
37
    /**
38
     * @var array for the internalization configuration
39
     */
40
    public $i18n = [];
41
42
    /**
43
     * @inheritdoc
44
     * @throws \yii\base\InvalidConfigException
45
     */
46 4
    public function init()
47
    {
48 4
        parent::init();
49 4
        $this->initI18N();
50
51 4
        if(empty($this->url)) {
52 2
            throw new InvalidConfigException('"url" cannot be empty.');
53
        }
54
55 2
        $this->clientOptions['url'] = Url::to($this->url);
56 2
    }
57
58
    /**
59
     * Initialize internalization
60
     */
61 4
    public function initI18N()
62
    {
63 4
        Yii::setAlias('@fileupload', dirname(__FILE__));
64 4
        if (empty($this->i18n)) {
65 4
            $this->i18n = [
66 4
                'sourceLanguage' => 'en',
67 4
                'basePath' => '@fileupload/messages',
68 4
                'class' => 'yii\i18n\PhpMessageSource',
69
            ];
70 4
        }
71 4
        Yii::$app->i18n->translations['fileupload'] = $this->i18n;
72 4
    }
73
}
74