Skip to content

Commit fcde80e

Browse files
committed
Fix coding style errors
1 parent abd5826 commit fcde80e

File tree

7 files changed

+93
-53
lines changed

7 files changed

+93
-53
lines changed

.php_cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__)
5+
->exclude([
6+
'vendor',
7+
])
8+
;
9+
10+
return PhpCsFixer\Config::create()
11+
->setRules([
12+
'@Symfony' => true,
13+
'yoda_style' => false,
14+
'array_syntax' => ['syntax' => 'short'],
15+
'concat_space' => ['spacing' => 'one'],
16+
'phpdoc_align' => false,
17+
'phpdoc_annotation_without_dot' => false,
18+
'phpdoc_summary' => false,
19+
'phpdoc_inline_tag' => false,
20+
'heredoc_to_nowdoc' => false,
21+
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
22+
])
23+
->setFinder($finder)
24+
;

Component.php

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
/**
88
* Component.
9-
*
9+
*
1010
* Examples:
11-
*
11+
*
1212
* Minimal code:
13-
*
13+
*
1414
* ~~~
1515
* 'language' => 'en',
1616
* 'bootstrap' => ['languagepicker'],
@@ -21,9 +21,9 @@
2121
* ]
2222
* ],
2323
* ~~~
24-
*
24+
*
2525
* Complete example:
26-
*
26+
*
2727
* ~~~
2828
* 'language' => 'en-US',
2929
* 'bootstrap' => ['languagepicker'],
@@ -44,21 +44,21 @@
4444
* ]
4545
* ]
4646
* ~~~
47-
*
47+
*
4848
*
4949
* @author Lajos Molnar <[email protected]>
50+
*
5051
* @since 1.0
5152
*/
5253
class Component extends \yii\base\Component
5354
{
54-
5555
/**
5656
* @var function - function to execute after changing the language of the site.
5757
*/
5858
public $callback;
5959

6060
/**
61-
* @var integer expiration date of the cookie storing the language of the site.
61+
* @var int expiration date of the cookie storing the language of the site.
6262
*/
6363
public $expireDays = 30;
6464

@@ -76,28 +76,28 @@ class Component extends \yii\base\Component
7676
/**
7777
* @var array List of available languages
7878
* Formats supported in the pre-defined skins:
79-
*
79+
*
8080
* ~~~
8181
* ['en', 'de', 'es']
8282
* ['en' => 'English', 'de' => 'Deutsch', 'fr' => 'Français']
8383
* ['en-US', 'de-DE', 'fr-FR']
8484
* ['en-US' => 'English', 'de-DE' => 'Deutsch', 'fr-FR' => 'Français']
8585
* ~~~
86-
*
8786
*/
8887
public $languages;
8988

9089
/**
9190
* @inheritdoc
91+
*
9292
* @param array $config
93+
*
9394
* @throws \yii\base\InvalidConfigException
9495
*/
95-
public function __construct($config = array())
96+
public function __construct($config = [])
9697
{
97-
9898
if (empty($config['languages'])) {
9999
throw new \yii\base\InvalidConfigException('Missing languages');
100-
} else if (is_callable($config['languages'])) {
100+
} elseif (is_callable($config['languages'])) {
101101
$config['languages'] = call_user_func($config['languages']);
102102
}
103103

@@ -109,7 +109,6 @@ public function __construct($config = array())
109109
*/
110110
public function init()
111111
{
112-
113112
$this->initLanguage();
114113

115114
parent::init();
@@ -123,12 +122,13 @@ public function initLanguage()
123122
if (isset($_GET['language-picker-language'])) {
124123
if ($this->_isValidLanguage($_GET['language-picker-language'])) {
125124
return $this->saveLanguage($_GET['language-picker-language']);
126-
} else if (!Yii::$app->request->isAjax) {
125+
} elseif (!Yii::$app->request->isAjax) {
127126
return $this->_redirect();
128127
}
129-
} else if (Yii::$app->request->cookies->has($this->cookieName)) {
128+
} elseif (Yii::$app->request->cookies->has($this->cookieName)) {
130129
if ($this->_isValidLanguage(Yii::$app->request->cookies->getValue($this->cookieName))) {
131130
Yii::$app->language = Yii::$app->request->cookies->getValue($this->cookieName);
131+
132132
return;
133133
} else {
134134
Yii::$app->response->cookies->remove($this->cookieName);
@@ -140,12 +140,13 @@ public function initLanguage()
140140

141141
/**
142142
* Saving language into cookie and database.
143+
*
143144
* @param string $language - The language to save.
145+
*
144146
* @return static
145147
*/
146148
public function saveLanguage($language)
147149
{
148-
149150
Yii::$app->language = $language;
150151
$this->saveLanguageIntoCookie($language);
151152

@@ -170,6 +171,7 @@ public function detectLanguage()
170171
if ($this->_isValidLanguage($language)) {
171172
Yii::$app->language = $language;
172173
$this->saveLanguageIntoCookie($language);
174+
173175
return;
174176
}
175177
}
@@ -180,6 +182,7 @@ public function detectLanguage()
180182
if (preg_match('/^' . $pattern . '/', $value) || preg_match('/^' . $pattern . '/', $key)) {
181183
Yii::$app->language = $this->_isValidLanguage($key) ? $key : $value;
182184
$this->saveLanguageIntoCookie(Yii::$app->language);
185+
183186
return;
184187
}
185188
}
@@ -188,6 +191,7 @@ public function detectLanguage()
188191

189192
/**
190193
* Save language into cookie.
194+
*
191195
* @param string $language
192196
*/
193197
public function saveLanguageIntoCookie($language)
@@ -196,30 +200,33 @@ public function saveLanguageIntoCookie($language)
196200
'name' => $this->cookieName,
197201
'domain' => $this->cookieDomain,
198202
'value' => $language,
199-
'expire' => time() + 86400 * $this->expireDays
203+
'expire' => time() + 86400 * $this->expireDays,
200204
]);
201205

202206
Yii::$app->response->cookies->add($cookie);
203207
}
204208

205209
/**
206210
* Redirects the browser to the referer URL.
211+
*
207212
* @return static
208213
*/
209214
private function _redirect()
210215
{
211216
$redirect = Yii::$app->request->absoluteUrl == Yii::$app->request->referrer ? '/' : Yii::$app->request->referrer;
217+
212218
return Yii::$app->response->redirect($redirect);
213219
}
214220

215221
/**
216222
* Determines whether the language received as a parameter can be processed.
223+
*
217224
* @param string $language
218-
* @return boolean
225+
*
226+
* @return bool
219227
*/
220228
private function _isValidLanguage($language)
221229
{
222230
return is_string($language) && (isset($this->languages[$language]) || in_array($language, $this->languages));
223231
}
224-
225-
}
232+
}

bundles/LanguageLargeIconsAsset.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
/**
88
* LanguageLargeIcons asset bundle
9+
*
910
* @author Lajos Molnár <[email protected]>
11+
*
1012
* @since 1.0
1113
*/
12-
class LanguageLargeIconsAsset extends AssetBundle {
13-
14+
class LanguageLargeIconsAsset extends AssetBundle
15+
{
1416
/**
1517
* @inheritdoc
1618
*/
@@ -23,5 +25,4 @@ class LanguageLargeIconsAsset extends AssetBundle {
2325
'stylesheets/language-picker.min.css',
2426
'stylesheets/flags-large.min.css',
2527
];
26-
2728
}

bundles/LanguagePluginAsset.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
/**
88
* LanguagePlugin asset bundle
9+
*
910
* @author Lajos Molnár <[email protected]>
11+
*
1012
* @since 1.0
1113
*/
12-
class LanguagePluginAsset extends AssetBundle {
13-
14+
class LanguagePluginAsset extends AssetBundle
15+
{
1416
/**
1517
* @inheritdoc
1618
*/
@@ -29,5 +31,4 @@ class LanguagePluginAsset extends AssetBundle {
2931
public $depends = [
3032
'yii\web\JqueryAsset',
3133
];
32-
3334
}

bundles/LanguageSmallIconsAsset.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
/**
88
* LanguageSmallIcons asset bundle
9+
*
910
* @author Lajos Molnár <[email protected]>
11+
*
1012
* @since 1.0
1113
*/
12-
class LanguageSmallIconsAsset extends AssetBundle {
13-
14+
class LanguageSmallIconsAsset extends AssetBundle
15+
{
1416
/**
1517
* @inheritdoc
1618
*/
@@ -23,5 +25,4 @@ class LanguageSmallIconsAsset extends AssetBundle {
2325
'stylesheets/language-picker.min.css',
2426
'stylesheets/flags-small.min.css',
2527
];
26-
2728
}

composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@
1717
},
1818
"require": {
1919
"yiisoft/yii2": "~2.0.0"
20+
},
21+
"require-dev": {
22+
"friendsofphp/php-cs-fixer": "^2.11"
23+
},
24+
"scripts": {
25+
"cs-fix": "php-cs-fixer fix --config=.php_cs",
26+
"cs-check": "php-cs-fixer fix --config=.php_cs --dry-run --diff"
2027
}
2128
}

0 commit comments

Comments
 (0)