Skip to content

Commit 68534a8

Browse files
authored
Merge pull request #20031 from terabytesoftw/rector-fixeds
Apply rector fixeds in directory tests.
2 parents a579102 + 5b152a6 commit 68534a8

File tree

303 files changed

+3087
-3646
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

303 files changed

+3087
-3646
lines changed

tests/TestCase.php

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public static function tearDownAfterClass(): void
3333
* @param mixed $default default value to use when param is not set.
3434
* @return mixed the value of the configuration param
3535
*/
36-
public static function getParam($name, $default = null)
36+
public static function getParam($name, mixed $default = null)
3737
{
3838
if (static::$params === null) {
3939
static::$params = require __DIR__ . '/data/config.php';
4040
}
4141

42-
return isset(static::$params[$name]) ? static::$params[$name] : $default;
42+
return static::$params[$name] ?? $default;
4343
}
4444

4545
/**
@@ -90,9 +90,9 @@ protected function mockWebApplication($config = [], $appClass = '\yii\web\Applic
9090

9191
protected function getVendorPath()
9292
{
93-
$vendor = dirname(dirname(__DIR__)) . '/vendor';
93+
$vendor = dirname(__DIR__, 2) . '/vendor';
9494
if (!is_dir($vendor)) {
95-
$vendor = dirname(dirname(dirname(dirname(__DIR__))));
95+
$vendor = dirname(__DIR__, 4);
9696
}
9797

9898
return $vendor;
@@ -141,11 +141,9 @@ protected function assertEqualsAnyWhitespace($expected, $actual, $message = ''){
141141
* Used on objects, it asserts that two variables reference
142142
* the same object.
143143
*
144-
* @param mixed $expected
145-
* @param mixed $actual
146144
* @param string $message
147145
*/
148-
protected function assertSameAnyWhitespace($expected, $actual, $message = ''){
146+
protected function assertSameAnyWhitespace(mixed $expected, mixed $actual, $message = ''){
149147
if (is_string($expected)) {
150148
$expected = $this->sanitizeWhitespaces($expected);
151149
}
@@ -159,14 +157,12 @@ protected function assertSameAnyWhitespace($expected, $actual, $message = ''){
159157
/**
160158
* Asserts that a haystack contains a needle ignoring line endings.
161159
*
162-
* @param mixed $needle
163-
* @param mixed $haystack
164160
* @param string $message
165161
*/
166-
protected function assertContainsWithoutLE($needle, $haystack, $message = '')
162+
protected function assertContainsWithoutLE(mixed $needle, mixed $haystack, $message = '')
167163
{
168-
$needle = str_replace("\r\n", "\n", $needle);
169-
$haystack = str_replace("\r\n", "\n", $haystack);
164+
$needle = str_replace("\r\n", "\n", (string) $needle);
165+
$haystack = str_replace("\r\n", "\n", (string) $haystack);
170166

171167
$this->assertStringContainsString($needle, $haystack, $message);
172168
}
@@ -179,7 +175,7 @@ protected function assertContainsWithoutLE($needle, $haystack, $message = '')
179175
* @return string
180176
*/
181177
protected function sanitizeWhitespaces($string){
182-
return preg_replace("/[\pZ\pC]/u", " ", $string);
178+
return preg_replace("/[\pZ\pC]/u", " ", (string) $string);
183179
}
184180

185181
/**
@@ -253,11 +249,9 @@ protected function getInaccessibleProperty($object, $propertyName, $revoke = tru
253249
/**
254250
* Asserts that value is one of expected values.
255251
*
256-
* @param mixed $actual
257-
* @param array $expected
258252
* @param string $message
259253
*/
260-
public function assertIsOneOf($actual, array $expected, $message = '')
254+
public function assertIsOneOf(mixed $actual, array $expected, $message = ''): void
261255
{
262256
self::assertThat($actual, new IsOneOfAssert($expected), $message);
263257
}
@@ -272,9 +266,9 @@ protected function switchDbConnection($db)
272266
if (isset($databases[$db])) {
273267
$database = $databases[$db];
274268
Yii::$app->db->close();
275-
Yii::$app->db->dsn = isset($database['dsn']) ? $database['dsn'] : null;
276-
Yii::$app->db->username = isset($database['username']) ? $database['username'] : null;
277-
Yii::$app->db->password = isset($database['password']) ? $database['password'] : null;
269+
Yii::$app->db->dsn = $database['dsn'] ?? null;
270+
Yii::$app->db->username = $database['username'] ?? null;
271+
Yii::$app->db->password = $database['password'] ?? null;
278272
}
279273
}
280274
}

tests/data/ar/Animal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public static function tableName()
2323
return 'animal';
2424
}
2525

26-
public function init()
26+
public function init(): void
2727
{
2828
parent::init();
29-
$this->type = \get_called_class();
29+
$this->type = static::class;
3030
}
3131

3232
public function getDoes()

tests/data/ar/Cat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Cat extends Animal
1919
* @param self $record
2020
* @param array $row
2121
*/
22-
public static function populateRecord($record, $row)
22+
public static function populateRecord($record, $row): void
2323
{
2424
parent::populateRecord($record, $row);
2525

@@ -31,7 +31,7 @@ public static function populateRecord($record, $row)
3131
* @throw DivisionByZeroError
3232
* @return float|int
3333
*/
34-
public function getException()
34+
public function getException(): never
3535
{
3636
throw new \Exception('no');
3737
}

tests/data/ar/Customer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
*/
2424
class Customer extends ActiveRecord
2525
{
26-
const STATUS_ACTIVE = 1;
27-
const STATUS_INACTIVE = 2;
26+
final public const STATUS_ACTIVE = 1;
27+
final public const STATUS_INACTIVE = 2;
2828

2929
public $status2;
3030

@@ -81,7 +81,7 @@ public function getOrderItems()
8181
/* @var $rel ActiveQuery */
8282
$rel = $this->hasMany(Item::class, ['id' => 'item_id']);
8383

84-
return $rel->viaTable('order_item', ['order_id' => 'id'], function ($q) {
84+
return $rel->viaTable('order_item', ['order_id' => 'id'], function ($q): void {
8585
/* @var $q ActiveQuery */
8686
$q->viaTable('order', ['customer_id' => 'id']);
8787
})->orderBy('id');
@@ -99,7 +99,7 @@ public function getItems()
9999
->via('orderItems2');
100100
}
101101

102-
public function afterSave($insert, $changedAttributes)
102+
public function afterSave($insert, $changedAttributes): void
103103
{
104104
ActiveRecordTest::$afterSaveInsert = $insert;
105105
ActiveRecordTest::$afterSaveNewRecord = $this->isNewRecord;
@@ -112,6 +112,6 @@ public function afterSave($insert, $changedAttributes)
112112
*/
113113
public static function find()
114114
{
115-
return new CustomerQuery(\get_called_class());
115+
return new CustomerQuery(static::class);
116116
}
117117
}

tests/data/ar/CustomerQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CustomerQuery extends ActiveQuery
1616
{
1717
public static $joinWithProfile = false;
1818

19-
public function init()
19+
public function init(): void
2020
{
2121
if (static::$joinWithProfile) {
2222
$this->innerJoinWith('profile');

tests/data/ar/CustomerWithAlias.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
class CustomerWithAlias extends ActiveRecord
1717
{
18-
const STATUS_ACTIVE = 1;
19-
const STATUS_INACTIVE = 2;
18+
final public const STATUS_ACTIVE = 1;
19+
final public const STATUS_INACTIVE = 2;
2020

2121
public $status2;
2222

@@ -33,7 +33,7 @@ public static function tableName()
3333
*/
3434
public static function find()
3535
{
36-
$activeQuery = new CustomerQuery(get_called_class());
36+
$activeQuery = new CustomerQuery(static::class);
3737
$activeQuery->alias('csr');
3838
return $activeQuery;
3939
}

tests/data/ar/Dog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Dog extends Animal
1919
* @param self $record
2020
* @param array $row
2121
*/
22-
public static function populateRecord($record, $row)
22+
public static function populateRecord($record, $row): void
2323
{
2424
parent::populateRecord($record, $row);
2525

tests/data/ar/NoAutoLabels.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function attributeLabels()
2020
];
2121
}
2222

23-
public function generateAttributeLabel($name)
23+
public function generateAttributeLabel($name): never
2424
{
2525
throw new \yii\base\InvalidArgumentException('Label not defined!');
2626
}

tests/data/ar/Order.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ public function getOrderItems2()
6868
public function getOrderItems3()
6969
{
7070
return $this->hasMany(OrderItem::class, ['order_id' => 'id'])
71-
->indexBy(function ($row) {
72-
return $row['order_id'] . '_' . $row['item_id'];
73-
});
71+
->indexBy(fn($row) => $row['order_id'] . '_' . $row['item_id']);
7472
}
7573

7674
public function getOrderItemsWithNullFK()
@@ -81,23 +79,23 @@ public function getOrderItemsWithNullFK()
8179
public function getItems()
8280
{
8381
return $this->hasMany(Item::class, ['id' => 'item_id'])
84-
->via('orderItems', function ($q) {
82+
->via('orderItems', function ($q): void {
8583
// additional query configuration
8684
})->orderBy('item.id');
8785
}
8886

8987
public function getExpensiveItemsUsingViaWithCallable()
9088
{
9189
return $this->hasMany(Item::class, ['id' => 'item_id'])
92-
->via('orderItems', function (ActiveQuery $q) {
90+
->via('orderItems', function (ActiveQuery $q): void {
9391
$q->where(['>=', 'subtotal', 10]);
9492
});
9593
}
9694

9795
public function getCheapItemsUsingViaWithCallable()
9896
{
9997
return $this->hasMany(Item::class, ['id' => 'item_id'])
100-
->via('orderItems', function (ActiveQuery $q) {
98+
->via('orderItems', function (ActiveQuery $q): void {
10199
$q->where(['<', 'subtotal', 10]);
102100
});
103101
}
@@ -117,15 +115,15 @@ public function getItemsWithNullFK()
117115
public function getItemsInOrder1()
118116
{
119117
return $this->hasMany(Item::class, ['id' => 'item_id'])
120-
->via('orderItems', function ($q) {
118+
->via('orderItems', function ($q): void {
121119
$q->orderBy(['subtotal' => SORT_ASC]);
122120
})->orderBy('name');
123121
}
124122

125123
public function getItemsInOrder2()
126124
{
127125
return $this->hasMany(Item::class, ['id' => 'item_id'])
128-
->via('orderItems', function ($q) {
126+
->via('orderItems', function ($q): void {
129127
$q->orderBy(['subtotal' => SORT_DESC]);
130128
})->orderBy('name');
131129
}

tests/data/base/ArrayAccessObject.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ArrayAccessObject extends TraversableObject implements \ArrayAccess
3030
* @since 2.0.14.1
3131
*/
3232
#[\ReturnTypeWillChange]
33-
public function offsetExists($offset)
33+
public function offsetExists(mixed $offset)
3434
{
3535
return isset($this->data[$offset]);
3636
}
@@ -46,7 +46,7 @@ public function offsetExists($offset)
4646
* @since 2.0.14.1
4747
*/
4848
#[\ReturnTypeWillChange]
49-
public function offsetGet($offset)
49+
public function offsetGet(mixed $offset)
5050
{
5151
return $this->data[$offset];
5252
}
@@ -65,7 +65,7 @@ public function offsetGet($offset)
6565
* @since 2.0.14.1
6666
*/
6767
#[\ReturnTypeWillChange]
68-
public function offsetSet($offset, $value)
68+
public function offsetSet(mixed $offset, mixed $value): void
6969
{
7070
$this->data[$offset] = $value;
7171
}
@@ -81,7 +81,7 @@ public function offsetSet($offset, $value)
8181
* @since 2.0.14.1
8282
*/
8383
#[\ReturnTypeWillChange]
84-
public function offsetUnset($offset)
84+
public function offsetUnset(mixed $offset): void
8585
{
8686
unset($this->data[$offset]);
8787
}

0 commit comments

Comments
 (0)