Browse Source

Fix CS (#14665)

* Run php-cs-fixer.

* Enable phpdoc_types rule.
tags/2.0.13
Robert Korulczyk 7 years ago committed by Carsten Brandt
parent
commit
b99e955627
  1. 2
      cs/src/YiiConfig.php
  2. 20
      framework/i18n/Formatter.php
  3. 6
      framework/web/Request.php
  4. 1
      tests/compatibility.php
  5. 13
      tests/framework/base/ApplicationTest.php
  6. 6
      tests/framework/base/BCObject.php
  7. 6
      tests/framework/behaviors/AttributesBehaviorTest.php
  8. 3
      tests/framework/db/ActiveRecordTest.php
  9. 3
      tests/framework/db/CommandTest.php
  10. 5
      tests/framework/db/GetTablesAliasTestTrait.php
  11. 5
      tests/framework/db/QueryTest.php
  12. 2
      tests/framework/filters/AjaxFilterTest.php
  13. 52
      tests/framework/helpers/ArrayHelperTest.php
  14. 16
      tests/framework/i18n/FormatterTest.php
  15. 2
      tests/framework/rbac/DbManagerTestCase.php
  16. 2
      tests/framework/rbac/ManagerTestCase.php
  17. 101
      tests/framework/web/RequestTest.php
  18. 14
      tests/framework/web/UrlManagerCreateUrlTest.php
  19. 6
      tests/framework/widgets/LinkPagerTest.php

2
cs/src/YiiConfig.php

@ -140,7 +140,7 @@ class YiiConfig extends Config
// 'phpdoc_summary' => true, // needs more attention (summary should be separated by blank line from description)
// 'phpdoc_to_comment' => true, // breaks phpdoc for define('CONSTANT', $value);
'phpdoc_trim' => true,
// 'phpdoc_types' => true, // conflicts with yii\base\Object typehits https://github.com/yiisoft/yii2/pull/12699
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'protected_to_private' => true,
'psr4' => true,

20
framework/i18n/Formatter.php

@ -1402,8 +1402,8 @@ class Formatter extends Component
/**
* Formats the value as a length in human readable form for example `12 meters`.
*
* @param double|int $value value to be formatted.
* @param double $baseUnit unit of value as the multiplier of the smallest unit.
* @param float|int $value value to be formatted.
* @param float $baseUnit unit of value as the multiplier of the smallest unit.
* @param string $unitSystem either [[UNIT_SYSTEM_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]]. When `null`, property [[systemOfUnits]] will be used.
* @param int $decimals the number of digits after the decimal point.
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
@ -1425,8 +1425,8 @@ class Formatter extends Component
*
* This is the short form of [[asLength]].
*
* @param double|int $value value to be formatted.
* @param double $baseUnit unit of value as the multiplier of the smallest unit
* @param float|int $value value to be formatted.
* @param float $baseUnit unit of value as the multiplier of the smallest unit
* @param string $unitSystem either [[UNIT_SYSTEM_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]]. When `null`, property [[systemOfUnits]] will be used.
* @param int $decimals the number of digits after the decimal point.
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
@ -1446,8 +1446,8 @@ class Formatter extends Component
/**
* Formats the value as a weight in human readable form for example `12 kilograms`.
*
* @param double|int $value value to be formatted.
* @param double $baseUnit unit of value as the multiplier of the smallest unit
* @param float|int $value value to be formatted.
* @param float $baseUnit unit of value as the multiplier of the smallest unit
* @param string $unitSystem either [[UNIT_SYSTEM_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]]. When `null`, property [[systemOfUnits]] will be used.
* @param int $decimals the number of digits after the decimal point.
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
@ -1468,8 +1468,8 @@ class Formatter extends Component
*
* This is the short form of [[asWeight]].
*
* @param double|int $value value to be formatted.
* @param double $baseUnit unit of value as the multiplier of the smallest unit
* @param float|int $value value to be formatted.
* @param float $baseUnit unit of value as the multiplier of the smallest unit
* @param string $unitSystem either [[UNIT_SYSTEM_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]]. When `null`, property [[systemOfUnits]] will be used.
* @param int $decimals the number of digits after the decimal point.
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].
@ -1488,8 +1488,8 @@ class Formatter extends Component
/**
* @param string $unitType one of [[UNIT_WEIGHT]], [[UNIT_LENGTH]]
* @param string $unitFormat one of [[FORMAT_WIDTH_SHORT]], [[FORMAT_WIDTH_LONG]]
* @param double|int $value to be formatted
* @param double $baseUnit unit of value as the multiplier of the smallest unit
* @param float|int $value to be formatted
* @param float $baseUnit unit of value as the multiplier of the smallest unit
* @param string $unitSystem either [[UNIT_SYSTEM_METRIC]] or [[UNIT_SYSTEM_IMPERIAL]]. When `null`, property [[systemOfUnits]] will be used.
* @param int $decimals the number of digits after the decimal point.
* @param array $options optional configuration for the number formatter. This parameter will be merged with [[numberFormatterOptions]].

6
framework/web/Request.php

@ -224,7 +224,7 @@ class Request extends \yii\base\Request
* @since 2.0.13
*/
public $ipHeaders = [
'X-Forwarded-For'
'X-Forwarded-For',
];
/**
* @var array list of headers to check for determining whether the connection is made via HTTPS.
@ -1255,11 +1255,11 @@ class Request extends \yii\base\Request
{
if (isset($_SERVER['CONTENT_TYPE'])) {
return $_SERVER['CONTENT_TYPE'];
} else {
}
//fix bug https://bugs.php.net/bug.php?id=66606
return $this->headers->get('Content-Type');
}
}
private $_languages;

1
tests/compatibility.php

@ -19,7 +19,6 @@ namespace PHPUnit\Framework\Constraint {
namespace PHPUnit\Framework {
if (!class_exists('PHPUnit\Framework\TestCase') && class_exists('PHPUnit_Framework_TestCase')) {
echo "Applying compatibility patch for PHPUnit 6...\n";
abstract class TestCase extends \PHPUnit_Framework_TestCase

13
tests/framework/base/ApplicationTest.php

@ -41,24 +41,23 @@ class ApplicationTest extends TestCase
$this->mockApplication([
'components' => [
'withoutBootstrapInterface' => [
'class' => Component::className()
'class' => Component::className(),
],
'withBootstrapInterface' => [
'class' => BootstrapComponentMock::className()
]
'class' => BootstrapComponentMock::className(),
],
],
'modules' => [
'moduleX' => [
'class' => Module::className()
]
'class' => Module::className(),
],
],
'bootstrap' => [
'withoutBootstrapInterface',
'withBootstrapInterface',
'moduleX',
function () {
}
},
],
]);
$this->assertSame('Bootstrap with yii\base\Component', Yii::getLogger()->messages[0][0]);

6
tests/framework/base/BCObject.php

@ -1,8 +1,12 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yiiunit\framework\base;
use yii\base\Object;
class BCObject extends \yii\base\Object

6
tests/framework/behaviors/AttributesBehaviorTest.php

@ -101,8 +101,7 @@ class AttributesBehaviorTest extends TestCase
$preserveNonEmptyValues,
$name,
$alias
)
{
) {
$model = new ActiveRecordWithAttributesBehavior();
$model->attributesBehavior->preserveNonEmptyValues = $preserveNonEmptyValues;
$model->name = $name;
@ -143,8 +142,7 @@ class AttributesBehaviorTest extends TestCase
$order,
$name,
$alias
)
{
) {
$model = new ActiveRecordWithAttributesBehavior();
$model->attributesBehavior->order = $order;
$model->name = $name;

3
tests/framework/db/ActiveRecordTest.php

@ -1526,8 +1526,7 @@ abstract class ActiveRecordTest extends DatabaseTestCase
*/
public function testAmbiguousColumnIndexBy()
{
switch ($this->driverName)
{
switch ($this->driverName) {
case 'pgsql':
case 'sqlite':
$selectExpression = "(customer.name || ' in ' || p.description) AS name";

3
tests/framework/db/CommandTest.php

@ -343,7 +343,7 @@ SQL;
// batch insert on "type" table
$db->createCommand()->batchInsert('type', $cols, $data)->execute();
$data = $db->createCommand("SELECT int_col, char_col, float_col, bool_col FROM {{type}} WHERE [[int_col]] IN (1,2,3) ORDER BY [[int_col]];")->queryAll();
$data = $db->createCommand('SELECT int_col, char_col, float_col, bool_col FROM {{type}} WHERE [[int_col]] IN (1,2,3) ORDER BY [[int_col]];')->queryAll();
$this->assertEquals(3, count($data));
$this->assertEquals(1, $data[0]['int_col']);
$this->assertEquals(2, $data[1]['int_col']);
@ -357,7 +357,6 @@ SQL;
$this->assertEquals('1', $data[0]['bool_col']);
$this->assertIsOneOf($data[1]['bool_col'], ['0', false]);
$this->assertIsOneOf($data[2]['bool_col'], ['0', false]);
} catch (\Exception $e) {
setlocale(LC_NUMERIC, $locale);
throw $e;

5
tests/framework/db/GetTablesAliasTestTrait.php

@ -1,4 +1,9 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yiiunit\framework\db;

5
tests/framework/db/QueryTest.php

@ -342,8 +342,7 @@ abstract class QueryTest extends DatabaseTestCase
*/
public function testAmbiguousColumnIndexBy()
{
switch ($this->driverName)
{
switch ($this->driverName) {
case 'pgsql':
case 'sqlite':
$selectExpression = "(customer.name || ' in ' || p.description) AS name";
@ -357,7 +356,7 @@ abstract class QueryTest extends DatabaseTestCase
}
$db = $this->getConnection();
$result = (new Query)->select([$selectExpression])->from('customer')
$result = (new Query())->select([$selectExpression])->from('customer')
->innerJoin('profile p', '{{customer}}.[[profile_id]] = {{p}}.[[id]]')
->indexBy('id')->column($db);
$this->assertEquals([

2
tests/framework/filters/AjaxFilterTest.php

@ -20,7 +20,7 @@ use yiiunit\TestCase;
class AjaxFilterTest extends TestCase
{
/**
* @param boolean $isAjax
* @param bool $isAjax
* @return Request
*/
protected function mockRequest($isAjax)

52
tests/framework/helpers/ArrayHelperTest.php

@ -32,7 +32,7 @@ class Post2 extends BaseObject
class Post3 extends BaseObject
{
public $id = 33;
/** @var Object */
/** @var BaseObject */
public $subObject;
public function init()
@ -493,7 +493,7 @@ class ArrayHelperTest extends TestCase
];
$b = [
'secondValue',
'thirdValue'
'thirdValue',
];
$result = ArrayHelper::merge($a, $b);
@ -870,7 +870,7 @@ class ArrayHelperTest extends TestCase
[
'key' => [
'val1',
'in' => 'val'
'in' => 'val',
],
],
],
@ -892,7 +892,7 @@ class ArrayHelperTest extends TestCase
[
'key1' => 'val1',
'key' => [
'in' => ['val']
'in' => ['val'],
],
],
],
@ -906,8 +906,8 @@ class ArrayHelperTest extends TestCase
'key1' => 'val1',
'key' => [
'in' => [
'arr' => 'val'
]
'arr' => 'val',
],
],
],
],
@ -920,15 +920,15 @@ class ArrayHelperTest extends TestCase
'key1' => 'val1',
'key' => [
'in' => [
'arr' => ['val']
]
'arr' => ['val'],
],
],
],
],
[
[
'key' => [
'in' => ['val1']
'in' => ['val1'],
],
],
'key.in.arr', 'val',
@ -936,8 +936,8 @@ class ArrayHelperTest extends TestCase
'key' => [
'in' => [
'val1',
'arr' => 'val'
]
'arr' => 'val',
],
],
],
],
@ -951,8 +951,8 @@ class ArrayHelperTest extends TestCase
'key' => [
'in' => [
'val1',
'arr' => ['val']
]
'arr' => ['val'],
],
],
],
],
@ -961,8 +961,8 @@ class ArrayHelperTest extends TestCase
'key' => [
'in' => [
'val1',
'key' => 'val'
]
'key' => 'val',
],
],
],
'key.in.0', ['arr' => 'val'],
@ -970,8 +970,8 @@ class ArrayHelperTest extends TestCase
'key' => [
'in' => [
['arr' => 'val'],
'key' => 'val'
]
'key' => 'val',
],
],
],
],
@ -980,14 +980,14 @@ class ArrayHelperTest extends TestCase
'key' => [
'in' => [
'val1',
'key' => 'val'
]
'key' => 'val',
],
],
],
'key.in', ['arr' => 'val'],
[
'key' => [
'in' => ['arr' => 'val']
'in' => ['arr' => 'val'],
],
],
],
@ -1000,8 +1000,8 @@ class ArrayHelperTest extends TestCase
'attr1',
'attr2',
'attr3',
]
]
],
],
],
],
'key.in.schema', 'array',
@ -1014,8 +1014,8 @@ class ArrayHelperTest extends TestCase
'attr1',
'attr2',
'attr3',
]
]
],
],
],
],
],
@ -1024,7 +1024,7 @@ class ArrayHelperTest extends TestCase
'key' => [
'in.array' => [
'key' => 'val',
]
],
],
],
['key', 'in.array', 'ok.schema'], 'array',
@ -1033,7 +1033,7 @@ class ArrayHelperTest extends TestCase
'in.array' => [
'key' => 'val',
'ok.schema' => 'array',
]
],
],
],
],

16
tests/framework/i18n/FormatterTest.php

@ -230,15 +230,15 @@ class FormatterTest extends TestCase
public function lengthDataProvider()
{
return [
[-3, "-3 meters", '-3 m'],
[-3, '-3 meters', '-3 m'],
['NaN', '0 millimeters', '0 mm'],
[0, "0 millimeters", '0 mm'],
[0.005, "5 millimeters", '5 mm'],
[0.053, "5.3 centimeters", '5.3 cm'],
[0.1, "10 centimeters", '10 cm'],
[1.123, "1.123 meters", '1.123 m'],
[1893.12, "1.893 kilometers", '1.893 km'],
[4561549, "4561.549 kilometers", '4561.549 km'],
[0, '0 millimeters', '0 mm'],
[0.005, '5 millimeters', '5 mm'],
[0.053, '5.3 centimeters', '5.3 cm'],
[0.1, '10 centimeters', '10 cm'],
[1.123, '1.123 meters', '1.123 m'],
[1893.12, '1.893 kilometers', '1.893 km'],
[4561549, '4561.549 kilometers', '4561.549 km'],
];
}

2
tests/framework/rbac/DbManagerTestCase.php

@ -161,7 +161,7 @@ abstract class DbManagerTestCase extends ManagerTestCase
return [
[0, 0, true],
[0, new UserID(0), true],
['', '', false]
['', '', false],
];
}

2
tests/framework/rbac/ManagerTestCase.php

@ -458,7 +458,7 @@ abstract class ManagerTestCase extends TestCase
{
return [
[Item::TYPE_ROLE],
[Item::TYPE_PERMISSION]
[Item::TYPE_PERMISSION],
];
}

101
tests/framework/web/RequestTest.php

@ -307,7 +307,8 @@ class RequestTest extends TestCase
$this->assertEquals(null, $request->getServerPort());
}
public function isSecureServerDataProvider() {
public function isSecureServerDataProvider()
{
return [
[['HTTPS' => 1], true],
[['HTTPS' => 'on'], true],
@ -318,38 +319,38 @@ class RequestTest extends TestCase
[['HTTP_X_FORWARDED_PROTO' => 'http'], false],
[[
'HTTP_X_FORWARDED_PROTO' => 'https',
'REMOTE_HOST' => 'test.com'
'REMOTE_HOST' => 'test.com',
], true],
[[
'HTTP_X_FORWARDED_PROTO' => 'https',
'REMOTE_HOST' => 'othertest.com'
'REMOTE_HOST' => 'othertest.com',
], false],
[[
'HTTP_X_FORWARDED_PROTO' => 'https',
'REMOTE_ADDR' => '192.168.0.1'
'REMOTE_ADDR' => '192.168.0.1',
], true],
[[
'HTTP_X_FORWARDED_PROTO' => 'https',
'REMOTE_ADDR' => '192.169.0.1'
'REMOTE_ADDR' => '192.169.0.1',
], false],
[['HTTP_FRONT_END_HTTPS' => 'on'], false],
[['HTTP_FRONT_END_HTTPS' => 'off'], false],
[[
'HTTP_FRONT_END_HTTPS' => 'on',
'REMOTE_HOST' => 'test.com'
'REMOTE_HOST' => 'test.com',
], true],
[[
'HTTP_FRONT_END_HTTPS' => 'on',
'REMOTE_HOST' => 'othertest.com'
'REMOTE_HOST' => 'othertest.com',
], false],
[[
'HTTP_FRONT_END_HTTPS' => 'on',
'REMOTE_ADDR' => '192.168.0.1'
'REMOTE_ADDR' => '192.168.0.1',
], true],
[[
'HTTP_FRONT_END_HTTPS' => 'on',
'REMOTE_ADDR' => '192.169.0.1'
], false]
'REMOTE_ADDR' => '192.169.0.1',
], false],
];
}
@ -362,8 +363,8 @@ class RequestTest extends TestCase
$request = new Request([
'trustedHosts' => [
'/^test.com$/',
'/^192\.168/'
]
'/^192\.168/',
],
]);
$_SERVER = $server;
@ -371,41 +372,43 @@ class RequestTest extends TestCase
$_SERVER = $original;
}
public function getUserIPDataProvider() {
public function getUserIPDataProvider()
{
return [
[
[
'HTTP_X_FORWARDED_PROTO' => 'https',
'HTTP_X_FORWARDED_FOR' => '123.123.123.123',
'REMOTE_ADDR' => '192.168.0.1'
'REMOTE_ADDR' => '192.168.0.1',
],
'123.123.123.123',
],
'123.123.123.123'
], [
[
[
'HTTP_X_FORWARDED_PROTO' => 'https',
'HTTP_X_FORWARDED_FOR' => '123.123.123.123',
'REMOTE_ADDR' => '192.169.1.1'
'REMOTE_ADDR' => '192.169.1.1',
],
'192.169.1.1',
],
'192.169.1.1'
], [
[
[
'HTTP_X_FORWARDED_PROTO' => 'https',
'HTTP_X_FORWARDED_FOR' => '123.123.123.123',
'REMOTE_HOST' => 'trusted.com',
'REMOTE_ADDR' => '192.169.1.1'
'REMOTE_ADDR' => '192.169.1.1',
],
'123.123.123.123'
], [
'123.123.123.123',
],
[
[
'HTTP_X_FORWARDED_PROTO' => 'https',
'HTTP_X_FORWARDED_FOR' => '192.169.1.1',
'REMOTE_HOST' => 'untrusted.com',
'REMOTE_ADDR' => '192.169.1.1'
'REMOTE_ADDR' => '192.169.1.1',
],
'192.169.1.1',
],
'192.169.1.1'
]
];
}
@ -419,30 +422,30 @@ class RequestTest extends TestCase
$request = new Request([
'trustedHosts' => [
'/^192\.168/',
'/^trusted.com$/'
'/^trusted.com$/',
],
]);
$this->assertEquals($expected, $request->getUserIP());
$_SERVER = $original;
}
public function getMethodDataProvider() {
public function getMethodDataProvider()
{
return [
[
[
'REQUEST_METHOD' => 'DEFAULT',
'HTTP_X-HTTP-METHOD-OVERRIDE' => 'OVERRIDE'
'HTTP_X-HTTP-METHOD-OVERRIDE' => 'OVERRIDE',
],
'OVERRIDE'
], [
'OVERRIDE',
],
[
[
'REQUEST_METHOD' => 'DEFAULT',
],
'DEFAULT'
]
'DEFAULT',
],
];
}
@ -459,19 +462,20 @@ class RequestTest extends TestCase
$_SERVER = $original;
}
public function getIsAjaxDataProvider() {
public function getIsAjaxDataProvider()
{
return [
[
[
],
false
], [
false,
],
[
[
'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest',
],
true
]
true,
],
];
}
@ -488,20 +492,21 @@ class RequestTest extends TestCase
$_SERVER = $original;
}
public function getIsPjaxDataProvider() {
public function getIsPjaxDataProvider()
{
return [
[
[
],
false
], [
false,
],
[
[
'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest',
'HTTP_X_PJAX' => 'any value',
],
true
]
true,
],
];
}

14
tests/framework/web/UrlManagerCreateUrlTest.php

@ -767,24 +767,24 @@ class UrlManagerCreateUrlTest extends TestCase
{
$this->mockWebApplication([
'components' => [
'cache' => ArrayCache::className()
]
'cache' => ArrayCache::className(),
],
]);
$urlManager = $this->getUrlManager([
'cache' => 'cache',
'rules' => [
'/' => 'site/index'
]
'/' => 'site/index',
],
]);
$cachedUrlManager = $this->getUrlManager([
'cache' => 'cache',
'ruleConfig' => [
'class' => CachedUrlRule::className()
'class' => CachedUrlRule::className(),
],
'rules' => [
'/' => 'site/index'
]
'/' => 'site/index',
],
]);
$this->assertNotEquals($urlManager->rules, $cachedUrlManager->rules);

6
tests/framework/widgets/LinkPagerTest.php

@ -118,7 +118,7 @@ class LinkPagerTest extends \yiiunit\TestCase
'pagination' => $this->getPagination(5),
'options' => [
'tag' => 'div',
]
],
]);
$this->assertTrue(StringHelper::startsWith($output, '<div>'));
@ -131,8 +131,8 @@ class LinkPagerTest extends \yiiunit\TestCase
'pagination' => $this->getPagination(1),
'linkContainerOptions' => [
'tag' => 'div',
'class' => 'my-class'
]
'class' => 'my-class',
],
]);
$this->assertContains(

Loading…
Cancel
Save