Skip to content

Commit b224a3e

Browse files
author
igor-chepurnoi
committed
fix code style
1 parent 32cdfa6 commit b224a3e

File tree

9 files changed

+83
-44
lines changed

9 files changed

+83
-44
lines changed

.php_cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
$finder = Symfony\CS\Finder::create()
4+
->exclude('vendor')
5+
->in([__DIR__]);
6+
7+
$config = Symfony\CS\Config::create()
8+
->fixers([
9+
'-phpdoc_params',
10+
'-phpdoc_short_description',
11+
'-phpdoc_inline_tag',
12+
'-pre_increment',
13+
'-heredoc_to_nowdoc',
14+
'-spaces_cast',
15+
'-include',
16+
'-phpdoc_no_package',
17+
'concat_with_spaces',
18+
'ordered_use',
19+
'short_array_syntax',
20+
])
21+
->finder($finder);
22+
23+
return $config;

.travis.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ php:
55
- 5.5
66
- 5.6
77
- 7.0
8-
- hhvm
9-
10-
# run build against hhvm but allow them to fail
11-
# http://docs.travis-ci.com/user/build-configuration/#Rows-That-are-Allowed-To-Fail
12-
matrix:
13-
fast_finish: true
14-
allow_failures:
15-
- php: hhvm
168

179
# faster builds on new travis setup not using sudo
1810
sudo: false
@@ -21,6 +13,7 @@ sudo: false
2113
cache:
2214
directories:
2315
- $HOME/.composer/cache
16+
- vendor
2417

2518
install:
2619
- travis_retry composer self-update && composer --version
@@ -29,4 +22,5 @@ install:
2922
- travis_retry composer install --prefer-dist --no-interaction
3023

3124
script:
32-
- phpunit --verbose $PHPUNIT_FLAGS
25+
- vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --dry-run --diff
26+
- phpunit --verbose $PHPUNIT_FLAGS

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
"name": "yii2mod/yii2-enum",
33
"description": "Yii2 Enumerable helpers",
44
"type": "yii2-extension",
5-
"keywords": ["yii2", "extension"],
5+
"keywords": [
6+
"yii2",
7+
"yii2 enum",
8+
"enumerable helper"
9+
],
610
"license": "MIT",
711
"authors": [
812
{
@@ -13,6 +17,9 @@
1317
"require": {
1418
"yiisoft/yii2": "*"
1519
},
20+
"require-dev": {
21+
"friendsofphp/php-cs-fixer": "~1.7"
22+
},
1623
"autoload": {
1724
"psr-4": {
1825
"yii2mod\\enum\\": ""

helpers/BaseEnum.php

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
/**
1111
* Class BaseEnum
12+
*
1213
* @author Dmitry Semenov <disemx@gmail.com>
14+
*
1315
* @package yii2mod\enum\helpers
1416
*/
1517
abstract class BaseEnum
@@ -48,14 +50,14 @@ abstract class BaseEnum
4850
/**
4951
* Sets the value that will be managed by this type instance.
5052
*
51-
* @param mixed $value The value to be managed.
53+
* @param mixed $value The value to be managed
5254
*
53-
* @throws BadRequestHttpException If the value is not valid.
55+
* @throws BadRequestHttpException If the value is not valid
5456
*/
5557
public function __construct($value)
5658
{
5759
if (!self::isValidValue($value)) {
58-
throw new BadRequestHttpException;
60+
throw new BadRequestHttpException();
5961
}
6062

6163
$this->value = $value;
@@ -64,10 +66,10 @@ public function __construct($value)
6466
/**
6567
* Creates a new type instance for a called name.
6668
*
67-
* @param string $name The name of the value.
68-
* @param array $arguments An ignored list of arguments.
69+
* @param string $name The name of the value
70+
* @param array $arguments An ignored list of arguments
6971
*
70-
* @return $this The new type instance.
72+
* @return $this The new type instance
7173
*/
7274
public static function __callStatic($name, array $arguments = [])
7375
{
@@ -77,57 +79,62 @@ public static function __callStatic($name, array $arguments = [])
7779
/**
7880
* Creates a new type instance using the name of a value.
7981
*
80-
* @param string $name The name of a value.
82+
* @param string $name The name of a value
8183
*
8284
* @throws \yii\web\BadRequestHttpException
83-
* @return $this The new type instance.
8485
*
86+
* @return $this The new type instance
8587
*/
8688
public static function createByName($name)
8789
{
8890
$constants = self::getConstantsByName();
8991

9092
if (!array_key_exists($name, $constants)) {
91-
throw new BadRequestHttpException;
93+
throw new BadRequestHttpException();
9294
}
9395

9496
return new static($constants[$name]);
9597
}
9698

9799
/**
98100
* get constant key by value(label)
101+
*
99102
* @param $value
103+
*
100104
* @return mixed
101105
*/
102106
public static function getValueByName($value)
103107
{
104108
$list = self::listData();
109+
105110
return array_search($value, $list);
106111
}
107112

108113
/**
109114
* Creates a new type instance using the value.
110115
*
111-
* @param mixed $value The value.
116+
* @param mixed $value The value
112117
*
113118
* @throws \yii\web\BadRequestHttpException
114-
* @return $this The new type instance.
115119
*
120+
* @return $this The new type instance
116121
*/
117122
public static function createByValue($value)
118123
{
119124
$constants = self::getConstantsByValue();
120125

121126
if (!array_key_exists($value, $constants)) {
122-
throw new BadRequestHttpException;
127+
throw new BadRequestHttpException();
123128
}
124129

125130
return new static($value);
126131
}
127132

128133
/**
129134
* Get list data
135+
*
130136
* @static
137+
*
131138
* @return mixed
132139
*/
133140
public static function listData()
@@ -140,12 +147,15 @@ public static function listData()
140147
$result = ArrayHelper::getColumn(self::$list[$class], function ($value) {
141148
return Yii::t(self::$messageCategory, $value);
142149
});
150+
143151
return $result;
144152
}
145153

146-
/**
154+
/**
147155
* Get label by value
156+
*
148157
* @var string value
158+
*
149159
* @return string label
150160
*/
151161
public static function getLabel($value)
@@ -154,13 +164,14 @@ public static function getLabel($value)
154164
if (isset($list[$value])) {
155165
return Yii::t(static::$messageCategory, $list[$value]);
156166
}
167+
157168
return null;
158169
}
159170

160171
/**
161172
* Returns the list of constants (by name) for this type.
162173
*
163-
* @return array The list of constants by name.
174+
* @return array The list of constants by name
164175
*/
165176
public static function getConstantsByName()
166177
{
@@ -187,7 +198,7 @@ public static function getConstantsByName()
187198
/**
188199
* Returns the list of constants (by value) for this type.
189200
*
190-
* @return array The list of constants by value.
201+
* @return array The list of constants by value
191202
*/
192203
public static function getConstantsByValue()
193204
{
@@ -202,10 +213,10 @@ public static function getConstantsByValue()
202213
if (array_key_exists($value, self::$byValue[$class])) {
203214
if (!is_array(self::$byValue[$class][$value])) {
204215
self::$byValue[$class][$value] = [
205-
self::$byValue[$class][$value]
216+
self::$byValue[$class][$value],
206217
];
207218
}
208-
self::$byValue[$class][$value][] = $name;;
219+
self::$byValue[$class][$value][] = $name;
209220
} else {
210221
self::$byValue[$class][$value] = $name;
211222
}
@@ -218,7 +229,7 @@ public static function getConstantsByValue()
218229
/**
219230
* Returns the name of the value.
220231
*
221-
* @return array|string The name, or names, of the value.
232+
* @return array|string The name, or names, of the value
222233
*/
223234
public function getName()
224235
{
@@ -230,7 +241,7 @@ public function getName()
230241
/**
231242
* Unwraps the type and returns the raw value.
232243
*
233-
* @return mixed The raw value managed by the type instance.
244+
* @return mixed The raw value managed by the type instance
234245
*/
235246
public function getValue()
236247
{
@@ -240,10 +251,10 @@ public function getValue()
240251
/**
241252
* Checks if a name is valid for this type.
242253
*
243-
* @param string $name The name of the value.
254+
* @param string $name The name of the value
244255
*
245-
* @return boolean If the name is valid for this type, `true` is returned.
246-
* Otherwise, the name is not valid and `false` is returned.
256+
* @return bool If the name is valid for this type, `true` is returned.
257+
* Otherwise, the name is not valid and `false` is returned
247258
*/
248259
public static function isValidName($name)
249260
{
@@ -255,10 +266,10 @@ public static function isValidName($name)
255266
/**
256267
* Checks if a value is valid for this type.
257268
*
258-
* @param string $value The value.
269+
* @param string $value The value
259270
*
260-
* @return boolean If the value is valid for this type, `true` is returned.
261-
* Otherwise, the value is not valid and `false` is returned.
271+
* @return bool If the value is valid for this type, `true` is returned.
272+
* Otherwise, the value is not valid and `false` is returned
262273
*/
263274
public static function isValidValue($value)
264275
{

helpers/BooleanEnum.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
/**
66
* Class BooleanEnum
7+
*
78
* @package yii2mod\enum\helpers
89
*/
910
class BooleanEnum extends BaseEnum
@@ -13,6 +14,6 @@ class BooleanEnum extends BaseEnum
1314

1415
public static $list = [
1516
self::YES => 'Yes',
16-
self::NO => 'No'
17+
self::NO => 'No',
1718
];
1819
}

tests/EnumTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/**
88
* Class EnumTest
9+
*
910
* @package yii2mod\enum\tests
1011
*/
1112
class EnumTest extends TestCase
@@ -26,4 +27,4 @@ public function testValidation()
2627
$this->assertTrue(BooleanEnum::isValidValue(1));
2728
$this->assertFalse(BooleanEnum::isValidValue('YES'));
2829
}
29-
}
30+
}

tests/TestCase.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace yii2mod\enum\tests;
44

5-
use yii\helpers\ArrayHelper;
65
use Yii;
6+
use yii\helpers\ArrayHelper;
77

88
/**
99
* This is the base class for all yii framework unit tests.
@@ -24,6 +24,7 @@ protected function tearDown()
2424
/**
2525
* Populates Yii::$app with a new application
2626
* The application will be destroyed on tearDown() automatically.
27+
*
2728
* @param array $config The application configuration, if needed
2829
* @param string $appClass name of the application class to create
2930
*/
@@ -39,11 +40,11 @@ protected function mockApplication($config = [], $appClass = '\yii\console\Appli
3940
'*' => [
4041
'class' => 'yii\i18n\PhpMessageSource',
4142
'basePath' => '@app/messages', // if advanced application, set @frontend/messages
42-
'sourceLanguage' => 'en'
43+
'sourceLanguage' => 'en',
4344
],
4445
],
4546
],
46-
]
47+
],
4748
], $config));
4849
}
4950

@@ -62,4 +63,4 @@ protected function destroyApplication()
6263
{
6364
Yii::$app = null;
6465
}
65-
}
66+
}

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
1111

1212
require_once(__DIR__ . '/../vendor/autoload.php');
13-
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
13+
require_once(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');

tests/data/BooleanEnum.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/**
88
* Class BooleanEnum
9+
*
910
* @package yii2mod\enum\tests\data
1011
*/
1112
class BooleanEnum extends BaseEnum
@@ -22,6 +23,6 @@ class BooleanEnum extends BaseEnum
2223

2324
public static $list = [
2425
self::YES => 'Yes',
25-
self::NO => 'No'
26+
self::NO => 'No',
2627
];
27-
}
28+
}

0 commit comments

Comments
 (0)