Passed
Push — master ( 94e56d...7c5cc2 )
by Tõnis
02:46 queued 27s
created
src/models/BaseLanguageSetting.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 class BaseLanguageSetting extends MyActiveRecord implements  SettingInterface {
22 22
 
23 23
     /** @var string $typeColumn the column containing setting type id */
24
-    protected static $typeColumn  = "key";
24
+    protected static $typeColumn = "key";
25 25
     /** @var string  */
26 26
     public $keyColumn = "key";
27 27
 
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
     public function init()
37 37
     {
38 38
         parent::init();
39
-        if($this->insert()){
40
-            if(!$this->parent){
39
+        if ($this->insert()) {
40
+            if (!$this->parent) {
41 41
                 throw new InvalidConfigException('Parent Model must be defined while initiating languages-settings');
42 42
             }
43
-            if(!$this->parent instanceof WithLanguageInterface){
43
+            if (!$this->parent instanceof WithLanguageInterface) {
44 44
                 throw new InvalidConfigException('Parent Model must implement ModelWithLanguages');
45 45
             }
46 46
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
             [['language_id', 'value'], 'required'],
58 58
             [['value'], 'string'],
59 59
             [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::class, 'targetAttribute' => ['language_id' => 'language_id']],
60
-        ],  parent::rules());
60
+        ], parent::rules());
61 61
     }
62 62
 
63 63
     /**
@@ -66,37 +66,37 @@  discard block
 block discarded – undo
66 66
      * @param string $key
67 67
      * @return bool|static|array
68 68
      */
69
-    public static function getSetting($parent, $language, $key){
69
+    public static function getSetting($parent, $language, $key) {
70 70
 
71 71
         /** @var TypeInterface $typeClass */
72 72
         $typeClass = static::$typeClass;
73 73
         /** @var TypeInterface $type */
74 74
         $type = $typeClass::getByKey($key);
75 75
 
76
-        if(!empty($type)){
76
+        if (!empty($type)) {
77 77
             /** @var BaseLanguageSetting $model */
78 78
             $query = static::find();
79
-            if(!empty($parent)){
79
+            if (!empty($parent)) {
80 80
                 $query->andWhere([$parent->primaryKeySingle() =>$parent->primaryKey]);
81 81
             }
82
-            $model =$query->andWhere(['language_id'=>$language->primaryKey])
82
+            $model = $query->andWhere(['language_id'=>$language->primaryKey])
83 83
                 ->andWhere([$type->primaryKeySingle()=>$type->{$type->primaryKeySingle()}])
84 84
                 ->one();
85 85
 
86
-            if(empty($model)){
86
+            if (empty($model)) {
87 87
                 /** @var BaseLanguageSetting $model */
88 88
                 $model = \Yii::createObject(['class'=>static::class]);
89 89
                 $model->language_id = $language->primaryKey;
90
-                if(!empty($parent)){
90
+                if (!empty($parent)) {
91 91
                     $model->{$parent->primaryKeySingle()} = $parent->primaryKey;
92 92
                 }
93
-                $model->{$type->primaryKeySingle()}=$type->{$type->primaryKeySingle()};
93
+                $model->{$type->primaryKeySingle()} = $type->{$type->primaryKeySingle()};
94 94
 
95 95
             }
96 96
             return $model;
97 97
         }
98 98
 
99
-        throw new InvalidConfigException('Undefined type key: ' . $key);
99
+        throw new InvalidConfigException('Undefined type key: '.$key);
100 100
 
101 101
     }
102 102
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
      * @param $key string
137 137
      * @return static
138 138
      */
139
-    public function findOneByKey($key){
139
+    public function findOneByKey($key) {
140 140
         /** @var static $model */
141 141
         $model = static::find()
142 142
             ->andWhere([static::$typeColumn => $key])
Please login to merge, or discard this patch.
src/models/LanguageSearch.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
     public function rules()
20 20
     {
21 21
         return [
22
-            [['language_id','language', 'name', 'native_name'], 'safe'],
22
+            [['language_id', 'language', 'name', 'native_name'], 'safe'],
23 23
         ];
24 24
     }
25 25
 
Please login to merge, or discard this patch.
src/models/Language.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
      * @param string $language As in language\Language->language
63 63
      * @return string The county / flag code that matches the county code. If no match is found then the initial country code is returned
64 64
      */
65
-    public static function getFlagCode($language){
65
+    public static function getFlagCode($language) {
66 66
         $map = [
67 67
             'en-US'=>'GB',
68 68
             'et'=>'EE',
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
             'pl'=>'PL',
75 75
         ];
76 76
         
77
-        if(isset($map[$language])){
77
+        if (isset($map[$language])) {
78 78
             return $map[$language];
79 79
         }
80 80
         return strtoupper($language);
@@ -84,18 +84,18 @@  discard block
 block discarded – undo
84 84
      * @param string $languageCode language code
85 85
      * @return array|null|Language
86 86
      */
87
-    public static function getByCode($languageCode){
88
-        if($languageCode === 'en'){
87
+    public static function getByCode($languageCode) {
88
+        if ($languageCode === 'en') {
89 89
             $languageCode = 'en-US';
90 90
         }
91 91
         /* @var Language $language */
92
-        $language =Language::find()->andWhere(['language'=>$languageCode])->one(); ;
92
+        $language = Language::find()->andWhere(['language'=>$languageCode])->one(); ;
93 93
         return $language;
94 94
     }
95 95
 
96
-    public static function getByCodes($languageCodes){
96
+    public static function getByCodes($languageCodes) {
97 97
         return Language::find()
98
-            ->andWhere(['in','language',$languageCodes])
98
+            ->andWhere(['in', 'language', $languageCodes])
99 99
             ->all();
100 100
     }
101 101
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
      */
105 105
     public function getFlag()
106 106
     {
107
-        return Icon::show(strtolower(Language::getFlagCode($this->language)),['framework' =>  Icon::FI]);
107
+        return Icon::show(strtolower(Language::getFlagCode($this->language)), ['framework' =>  Icon::FI]);
108 108
     }
109 109
 
110 110
 
Please login to merge, or discard this patch.
src/models/BaseLanguageSettings.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -48,12 +48,12 @@
 block discarded – undo
48 48
     }
49 49
 
50 50
     /** {@inheritdoc} */
51
-    public function save($runValidation = true, $attributeNames = NULL){
52
-        if(!empty($this->settings)){
51
+    public function save($runValidation = true, $attributeNames = NULL) {
52
+        if (!empty($this->settings)) {
53 53
             foreach ($this->settings as $key => $setting) {
54 54
                 // delete empty
55
-                if($setting->value === null || $setting->value === ''){
56
-                    if(!$setting->isNewRecord){
55
+                if ($setting->value === null || $setting->value === '') {
56
+                    if (!$setting->isNewRecord) {
57 57
                         $setting->delete();
58 58
                     }
59 59
                 } else {
Please login to merge, or discard this patch.
src/models/LanguageTranslation.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
     public function rules()
33 33
     {
34 34
         return array_merge([
35
-            [['language_id', 'model_class', 'model_id', 'value','model_field_name'], 'required'],
35
+            [['language_id', 'model_class', 'model_id', 'value', 'model_field_name'], 'required'],
36 36
             [['language_id', 'model_id'], 'integer'],
37 37
             [['value'], 'string'],
38 38
             [['model_class'], 'string', 'max' => 255],
39 39
             [['model_field_name'], 'string', 'max' => 128],
40 40
             [['language_id'], 'exist', 'skipOnError' => true, 'targetClass' => Language::class, 'targetAttribute' => ['language_id' => 'language_id']]
41
-        ],  parent::rules());
41
+        ], parent::rules());
42 42
     }
43 43
 
44 44
     /**
@@ -64,12 +64,12 @@  discard block
 block discarded – undo
64 64
      * @return LanguageTranslation[]
65 65
      * @deprecated
66 66
      */
67
-    public static function findTranslations($class, $id, $column){
67
+    public static function findTranslations($class, $id, $column) {
68 68
         /** @var LanguageTranslation $model */
69 69
         $query = self::find()->andWhere([
70 70
             'model_class'=>$class,
71 71
             'model_id'=>$id,
72
-            'model_field_name'=>$column,])
72
+            'model_field_name'=>$column, ])
73 73
             ->indexBy('language_id');
74 74
 
75 75
         return $query->all();
Please login to merge, or discard this patch.
src/models/LanguageSettingsPack.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -30,11 +30,11 @@  discard block
 block discarded – undo
30 30
     {
31 31
         parent::init();
32 32
 
33
-        if(!$this->parent){
33
+        if (!$this->parent) {
34 34
             throw new yii\base\InvalidConfigException('Parent Model must be defined while initiating languages-settings');
35 35
         }
36 36
 
37
-        if(!$this->parent instanceof WithLanguagesInterface){
37
+        if (!$this->parent instanceof WithLanguagesInterface) {
38 38
             throw new yii\base\InvalidConfigException('Parent Model must implement WithLanguagesInterface');
39 39
         }
40 40
         $this->setLanguageSettings();
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
     }
43 43
 
44 44
     protected function setLanguageSettings() {
45
-        if(!empty($this->parent->languages)){
46
-            foreach ($this->parent->languages as $language){
45
+        if (!empty($this->parent->languages)) {
46
+            foreach ($this->parent->languages as $language) {
47 47
                 /* @var BaseLanguageSettings $languageSettings */
48 48
                 $languageSettings = Yii::createObject([
49 49
                     'class' => $this->languageSettingsClass,
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
         }
56 56
     }
57 57
 
58
-    public function save($runValidation = true,$attributeNames=null){
59
-        if(!empty($this->languageSettings)){
58
+    public function save($runValidation = true, $attributeNames = null) {
59
+        if (!empty($this->languageSettings)) {
60 60
             // language by language
61
-            foreach ($this->languageSettings as $key => $languageSetting){
62
-                $languageSetting->save($runValidation,$attributeNames);
61
+            foreach ($this->languageSettings as $key => $languageSetting) {
62
+                $languageSetting->save($runValidation, $attributeNames);
63 63
                 $this->addErrors($languageSetting->errors);
64 64
                 $this->languageSettings[$key] = $languageSetting;
65 65
             }
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
      * @param string $key
76 76
      * @return bool|string
77 77
      */
78
-    public function getSettingByLanguageAndKey($language, $key){
78
+    public function getSettingByLanguageAndKey($language, $key) {
79 79
         $setting = $this->getSettingByKeyAndLanguage($language, $key);
80
-        if(!$setting){
80
+        if (!$setting) {
81 81
             $setting = $this->getSettingByKeyInAnyLanguage($key);
82 82
         }
83 83
         return $setting;
@@ -90,10 +90,10 @@  discard block
 block discarded – undo
90 90
      * @param string $key
91 91
      * @return bool|string
92 92
      */
93
-    public function getSettingByKeyAndLanguage($language, $key){
94
-        if(isset($this->languageSettings[$language->primaryKey])){
93
+    public function getSettingByKeyAndLanguage($language, $key) {
94
+        if (isset($this->languageSettings[$language->primaryKey])) {
95 95
             $languageSettings = $this->languageSettings[$language->primaryKey];
96
-            if($languageSettings->{$key} && $languageSettings->{$key} != ''){
96
+            if ($languageSettings->{$key} && $languageSettings->{$key} != '') {
97 97
                 return $languageSettings->{$key};
98 98
             }
99 99
         }
@@ -107,10 +107,10 @@  discard block
 block discarded – undo
107 107
      * @param string $key
108 108
      * @return bool|string
109 109
      */
110
-    public function getSettingByKeyInAnyLanguage($key){
111
-        if(!empty($this->languageSettings)){
112
-            foreach ($this->languageSettings as $language_id => $languageSettings){
113
-                if($languageSettings->{$key} && $languageSettings->{$key} != ''){
110
+    public function getSettingByKeyInAnyLanguage($key) {
111
+        if (!empty($this->languageSettings)) {
112
+            foreach ($this->languageSettings as $language_id => $languageSettings) {
113
+                if ($languageSettings->{$key} && $languageSettings->{$key} != '') {
114 114
                     return $languageSettings->{$key};
115 115
                 }
116 116
             }
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
     {
126 126
         $scope = yii\helpers\StringHelper::basename($this->languageSettingsClass);
127 127
         if (isset($data[$scope])) {
128
-            foreach ($data[$scope] as $language_id => $attributes){
128
+            foreach ($data[$scope] as $language_id => $attributes) {
129 129
                 $language = Language::findOne((int) $language_id);
130 130
                 /** @var BaseLanguageSettings $model */
131
-                if(isset($this->languageSettings[$language_id])){
131
+                if (isset($this->languageSettings[$language_id])) {
132 132
                     $model = $this->languageSettings[$language_id];
133 133
                 } else {
134 134
                     $model = Yii::createObject([
Please login to merge, or discard this patch.
src/models/ModelWithLanguageSettings.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -36,12 +36,12 @@  discard block
 block discarded – undo
36 36
         parent::load($data, $formName = null);
37 37
         $scope = \yii\helpers\StringHelper::basename($this->languageSettingsPack->languageSettingsClass);
38 38
         if (isset($data[$scope])) {
39
-            foreach ($data[$scope] as $language_id => $attributes){
39
+            foreach ($data[$scope] as $language_id => $attributes) {
40 40
                 $language = Language::findOne((int) $language_id);
41 41
                 /** @var BaseLanguageSettings $model */
42
-                if(isset($this->languageSettingsPack->languageSettings[$language_id])){
42
+                if (isset($this->languageSettingsPack->languageSettings[$language_id])) {
43 43
                     $model = $this->languageSettingsPack->languageSettings[$language_id];
44
-                }else{
44
+                } else {
45 45
                     $model = Yii::createObject([
46 46
                         'class' => $this->languageSettingsPack->languageSettingsClass,
47 47
                         'language'=>$language,
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
 
64 64
     /** {@inheritdoc} */
65
-    public function save(){
65
+    public function save() {
66 66
         parent::save();
67 67
         $this->languageSettingsPack->save();
68 68
         $this->addErrors($this->languageSettingsPack->errors);
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
                 /** @var BaseLanguageSettings $model */
42 42
                 if(isset($this->languageSettingsPack->languageSettings[$language_id])){
43 43
                     $model = $this->languageSettingsPack->languageSettings[$language_id];
44
-                }else{
44
+                } else{
45 45
                     $model = Yii::createObject([
46 46
                         'class' => $this->languageSettingsPack->languageSettingsClass,
47 47
                         'language'=>$language,
Please login to merge, or discard this patch.
src/views/language/update.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
 
6 6
 $this->title = Yii::t('app', 'Update {modelClass}: ', [
7 7
     'modelClass' => 'Language',
8
-]) . ' ' . $model->name;
8
+]).' '.$model->name;
9 9
 $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Languages'), 'url' => ['index']];
10 10
 $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'language_id' => $model->primaryKey]];
11 11
 $this->params['breadcrumbs'][] = Yii::t('app', 'Update');
Please login to merge, or discard this patch.
src/migrations/m160223_102646_add_language.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -8,18 +8,18 @@
 block discarded – undo
8 8
 
9 9
     public function safeUp()
10 10
     {
11
-        $this->createTable($this->tableName,[
11
+        $this->createTable($this->tableName, [
12 12
             'language_id' => $this->primaryKey()->comment('ID'),
13 13
             'language' => $this->string(16)->notNull()->comment('language code'),
14 14
             'name' => $this->string(255)->notNull()->comment('Language name'),
15 15
 
16 16
         ]);
17
-        $this->insert($this->tableName,['language_id'=>1, 'language'=>'en-US','name'=>'English']);
18
-        $this->insert($this->tableName,['language_id'=>2, 'language'=>'et','name'=>'Estonian']);
19
-        $this->insert($this->tableName,['language_id'=>3, 'language'=>'ru','name'=>'Russian']);
20
-        $this->insert($this->tableName,['language_id'=>4, 'language'=>'fi','name'=>'Finnish']);
21
-        $this->insert($this->tableName,['language_id'=>5, 'language'=>'lv','name'=>'Latvian']);
22
-        $this->insert($this->tableName,['language_id'=>6, 'language'=>'lt','name'=>'Lithuanian']);
17
+        $this->insert($this->tableName, ['language_id'=>1, 'language'=>'en-US', 'name'=>'English']);
18
+        $this->insert($this->tableName, ['language_id'=>2, 'language'=>'et', 'name'=>'Estonian']);
19
+        $this->insert($this->tableName, ['language_id'=>3, 'language'=>'ru', 'name'=>'Russian']);
20
+        $this->insert($this->tableName, ['language_id'=>4, 'language'=>'fi', 'name'=>'Finnish']);
21
+        $this->insert($this->tableName, ['language_id'=>5, 'language'=>'lv', 'name'=>'Latvian']);
22
+        $this->insert($this->tableName, ['language_id'=>6, 'language'=>'lt', 'name'=>'Lithuanian']);
23 23
 
24 24
     }
25 25
 
Please login to merge, or discard this patch.