Skip to content

Commit ac0eb0a

Browse files
committed
Enable Rector php 8.0 set
1 parent 475eb76 commit ac0eb0a

File tree

209 files changed

+308
-1029
lines changed

Some content is hidden

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

209 files changed

+308
-1029
lines changed

lib/ar-softdelete/src/SoftDeleteBehavior.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ private function detectRestoreAttributeValues()
532532
} elseif (!is_scalar($value) && is_callable($value)) {
533533
$restoreValue = null;
534534
} else {
535-
throw new InvalidConfigException('Unable to automatically determine restore attribute values, "' . get_class($this) . '::$restoreAttributeValues" should be explicitly set.');
535+
throw new InvalidConfigException('Unable to automatically determine restore attribute values, "' . static::class . '::$restoreAttributeValues" should be explicitly set.');
536536
}
537537
$restoreAttributeValues[$name] = $restoreValue;
538538
}

lib/ar-softdelete/src/SoftDeleteQueryBehavior.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function notDeleted()
183183
* @param mixed $deleted filter value.
184184
* @return \yii\db\ActiveQueryInterface|static
185185
*/
186-
public function filterDeleted($deleted)
186+
public function filterDeleted(mixed $deleted)
187187
{
188188
if ($deleted === '' || $deleted === null || $deleted === []) {
189189
return $this->notDeleted();
@@ -259,7 +259,7 @@ protected function defaultNotDeletedCondition()
259259
} elseif (!is_scalar($value) && is_callable($value)) {
260260
$restoreValue = null;
261261
} else {
262-
throw new InvalidConfigException('Unable to automatically determine not delete condition, "' . get_class($this) . '::$notDeletedCondition" should be explicitly set.');
262+
throw new InvalidConfigException('Unable to automatically determine not delete condition, "' . static::class . '::$notDeletedCondition" should be explicitly set.');
263263
}
264264

265265
$condition[$attribute] = $restoreValue;
@@ -297,12 +297,12 @@ protected function normalizeFilterCondition($condition)
297297
$alias = array_keys($fromTables)[0];
298298

299299
foreach ($condition as $attribute => $value) {
300-
if (is_numeric($attribute) || strpos($attribute, '.') !== false) {
300+
if (is_numeric($attribute) || str_contains($attribute, '.')) {
301301
continue;
302302
}
303303

304304
unset($condition[$attribute]);
305-
if (strpos($attribute, '[[') === false) {
305+
if (!str_contains($attribute, '[[')) {
306306
$attribute = '[[' . $attribute . ']]';
307307
}
308308
$attribute = $alias . '.' . $attribute;

lib/yii2/Yii.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function alias(string $path): string
5858

5959
$path = FileHelper::normalizePath($path);
6060
foreach (self::$_aliasPaths as $alias => $aliasPath) {
61-
if (strpos($path . DIRECTORY_SEPARATOR, $aliasPath . DIRECTORY_SEPARATOR) === 0) {
61+
if (str_starts_with($path . DIRECTORY_SEPARATOR, $aliasPath . DIRECTORY_SEPARATOR)) {
6262
return $alias . str_replace('\\', '/', substr($path, strlen($aliasPath)));
6363
}
6464
}

rector.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Rector\Config\RectorConfig;
66
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
77
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
8+
use Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector;
9+
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
810

911
return RectorConfig::configure()
1012
->withPaths([
@@ -24,5 +26,16 @@
2426
ClosureToArrowFunctionRector::class => [
2527
__DIR__ . '/src/base/ApplicationTrait.php',
2628
],
29+
30+
// used by finally and next if
31+
RemoveUnusedVariableInCatchRector::class => [
32+
__DIR__ . '/src/console/controllers/PluginController.php',
33+
__DIR__ . '/src/helpers/DateTimeHelper.php',
34+
],
35+
36+
// object check
37+
ChangeSwitchToMatchRector::class => [
38+
__DIR__ . '/src/elements/Entry.php',
39+
],
2740
])
28-
->withPhpSets(php74: true);
41+
->withPhpSets(php80: true);

src/Craft.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public static function parseEnv(?string $str = null): string|null|false
106106
* $status = Craft::parseBooleanEnv('$SYSTEM_STATUS') ?? false;
107107
* ```
108108
*
109-
* @param mixed $value
110109
* @return bool|null
111110
* @since 3.7.22
112111
* @deprecated in 3.7.29. [[App::parseBooleanEnv()]] should be used instead.

src/auth/sso/BaseExternalProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ protected function populateUser(User $user, array $data): User
334334
/**
335335
* Normalize a callback
336336
*
337-
* @param mixed $callback
338337
* @param string|null $defaultClass
339338
* @return callable|null
340339
* @throws \yii\base\InvalidConfigException

src/auth/sso/mapper/SetUserValueTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ trait SetUserValueTrait
2828
* Set a value on a user; determine if we're setting a field value or property
2929
*
3030
* @param User $user
31-
* @param mixed $value
3231
* @return void
3332
*/
3433
protected function setValue(User $user, mixed $value): void

src/auth/sso/mapper/UserMapInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ interface UserMapInterface
1818
{
1919
/**
2020
* @param User $user
21-
* @param mixed $data
2221
* @return User
2322
*/
2423
public function __invoke(User $user, mixed $data): User;

src/base/Element.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,7 +2526,7 @@ public function __toString(): string
25262526
public function __isset($name): bool
25272527
{
25282528
// Is this the "field:handle" syntax?
2529-
if (strncmp($name, 'field:', 6) === 0) {
2529+
if (str_starts_with($name, 'field:')) {
25302530
return $this->fieldByHandle(substr($name, 6)) !== null;
25312531
}
25322532

@@ -2544,7 +2544,7 @@ public function __get($name)
25442544
}
25452545

25462546
// Is this the "field:handle" syntax?
2547-
if (strncmp($name, 'field:', 6) === 0) {
2547+
if (str_starts_with($name, 'field:')) {
25482548
return $this->getFieldValue(substr($name, 6));
25492549
}
25502550

@@ -2562,7 +2562,7 @@ public function __get($name)
25622562
public function __set($name, $value)
25632563
{
25642564
// Is this the "field:handle" syntax?
2565-
if (strncmp($name, 'field:', 6) === 0) {
2565+
if (str_starts_with($name, 'field:')) {
25662566
$this->setFieldValue(substr($name, 6), $value);
25672567
return;
25682568
}
@@ -2584,7 +2584,7 @@ public function __set($name, $value)
25842584
*/
25852585
public function __call($name, $params)
25862586
{
2587-
if (strncmp($name, 'isFieldEmpty:', 13) === 0) {
2587+
if (str_starts_with($name, 'isFieldEmpty:')) {
25882588
return $this->isFieldEmpty(substr($name, 13));
25892589
}
25902590

@@ -2770,7 +2770,7 @@ public function getIterator(): Traversable
27702770
public function getAttributeLabel($attribute): string
27712771
{
27722772
// Is this the "field:handle" syntax?
2773-
if (strncmp($attribute, 'field:', 6) === 0) {
2773+
if (str_starts_with($attribute, 'field:')) {
27742774
$attribute = substr($attribute, 6);
27752775
}
27762776

@@ -2940,7 +2940,6 @@ public function afterValidate(): void
29402940
* Normalizes a field’s validation rule.
29412941
*
29422942
* @param string $attribute
2943-
* @param mixed $rule
29442943
* @param FieldInterface $field
29452944
* @param callable $isEmpty
29462945
* @return Validator
@@ -3036,7 +3035,7 @@ public function isFieldEmpty(string $handle): bool
30363035
*/
30373036
public function addError($attribute, $error = ''): void
30383037
{
3039-
if (strncmp($attribute, 'field:', 6) === 0) {
3038+
if (str_starts_with($attribute, 'field:')) {
30403039
$attribute = substr($attribute, 6);
30413040
}
30423041

@@ -6568,7 +6567,7 @@ protected function fieldLayoutFields(bool $visibleOnly = false): array
65686567
{
65696568
try {
65706569
$fieldLayout = $this->getFieldLayout();
6571-
} catch (InvalidConfigException $e) {
6570+
} catch (InvalidConfigException) {
65726571
return [];
65736572
}
65746573

@@ -6608,7 +6607,6 @@ public function getLanguage(): string
66086607
/**
66096608
* Returns an element right before/after this one, from a given set of criteria.
66106609
*
6611-
* @param mixed $criteria
66126610
* @param int $dir
66136611
* @return ElementInterface|null
66146612
*/

src/base/ElementInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,15 +1073,13 @@ public function getLocalized(): ElementQueryInterface|ElementCollection;
10731073
/**
10741074
* Returns the next element relative to this one, from a given set of criteria.
10751075
*
1076-
* @param mixed $criteria
10771076
* @return self|null
10781077
*/
10791078
public function getNext(mixed $criteria = false): ?self;
10801079

10811080
/**
10821081
* Returns the previous element relative to this one, from a given set of criteria.
10831082
*
1084-
* @param mixed $criteria
10851083
* @return self|null
10861084
*/
10871085
public function getPrev(mixed $criteria = false): ?self;

src/base/Field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
4444
* @since 3.0.0
4545
*/
46-
abstract class Field extends SavableComponent implements FieldInterface, Iconic, Actionable
46+
abstract class Field extends SavableComponent implements FieldInterface, Iconic, Actionable, \Stringable
4747
{
4848
use FieldTrait;
4949

src/base/MemoizableArray.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@
3434
*/
3535
class MemoizableArray implements IteratorAggregate, Countable
3636
{
37-
/**
38-
* @var array Array elements
39-
*/
40-
private array $_elements;
41-
4237
/**
4338
* @var callable|null Normalizer method
4439
*/
@@ -57,13 +52,12 @@ class MemoizableArray implements IteratorAggregate, Countable
5752
/**
5853
* Constructor
5954
*
60-
* @param array $elements The items to be memoized
55+
* @param array $_elements The items to be memoized
6156
* @param callable|null $normalizer A method that the items should be normalized with when first returned by
6257
* [[all()]] or [[firstWhere()]].
6358
*/
64-
public function __construct(array $elements, ?callable $normalizer = null)
59+
public function __construct(private array $_elements, ?callable $normalizer = null)
6560
{
66-
$this->_elements = $elements;
6761
$this->_normalizer = $normalizer;
6862
}
6963

@@ -179,7 +173,6 @@ public function firstWhere(string $key, mixed $value = true, bool $strict = fals
179173
*
180174
* @param string $method
181175
* @param string $key
182-
* @param mixed $value
183176
* @param bool $strict
184177
* @return string
185178
*/

src/base/NestedElementTrait.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,16 +371,11 @@ public function addInvalidNestedElementIds(array $ids): void
371371
*/
372372
public function setEagerLoadedElements(string $handle, array $elements, EagerLoadPlan $plan): void
373373
{
374-
switch ($plan->handle) {
375-
case 'owner':
376-
$this->setOwner(reset($elements) ?: null);
377-
break;
378-
case 'primaryOwner':
379-
$this->setPrimaryOwner(reset($elements) ?: null);
380-
break;
381-
default:
382-
parent::setEagerLoadedElements($handle, $elements, $plan);
383-
}
374+
match ($plan->handle) {
375+
'owner' => $this->setOwner(reset($elements) ?: null),
376+
'primaryOwner' => $this->setPrimaryOwner(reset($elements) ?: null),
377+
default => parent::setEagerLoadedElements($handle, $elements, $plan),
378+
};
384379
}
385380

386381
/**

src/base/PreviewableFieldInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public function getPreviewHtml(mixed $value, ElementInterface $element): string;
3131
* Return the HTML that should be shown for the field in the card preview.
3232
* It can be used outside an element context, e.g. in a card view designer.
3333
*
34-
* @param mixed $value
3534
* @param ElementInterface|null $element
3635
* @return string
3736
* @since 5.5.0

src/base/conditions/BaseCondition.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ protected function validateConditionRule(ConditionRuleInterface $rule): bool
237237
return false;
238238
}
239239

240-
$ruleClass = get_class($rule);
240+
$ruleClass = $rule::class;
241241

242242
foreach ($this->getSelectableConditionRules() as $selectableRule) {
243-
if ($ruleClass === get_class($selectableRule)) {
243+
if ($ruleClass === $selectableRule::class) {
244244
return true;
245245
}
246246
}
@@ -298,7 +298,7 @@ public function getBuilderInnerHtml(bool $autofocusAddButton = false): string
298298
],
299299
]);
300300

301-
$html .= Html::hiddenInput('class', get_class($this));
301+
$html .= Html::hiddenInput('class', static::class);
302302
$html .= Html::hiddenInput('config', Json::encode($this->getBuilderConfig()));
303303

304304
foreach ($this->getConditionRules() as $rule) {
@@ -311,7 +311,7 @@ public function getBuilderInnerHtml(bool $autofocusAddButton = false): string
311311
'class' => 'visually-hidden',
312312
]) .
313313
Html::hiddenInput('uid', $rule->uid) .
314-
Html::hiddenInput('class', get_class($rule));
314+
Html::hiddenInput('class', $rule::class);
315315

316316
if ($this->sortable) {
317317
$ruleHtml .= Html::tag('div',
@@ -611,7 +611,7 @@ public function getBuilderConfig(): array
611611
public function getConfig(): array
612612
{
613613
return array_merge($this->config(), [
614-
'class' => get_class($this),
614+
'class' => static::class,
615615
'conditionRules' => $this->_conditionRules
616616
->map(function(ConditionRuleInterface $rule) {
617617
try {

src/base/conditions/BaseConditionRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function getGroupLabel(): ?string
121121
public function getConfig(): array
122122
{
123123
$config = [
124-
'class' => get_class($this),
124+
'class' => static::class,
125125
'uid' => $this->uid,
126126
];
127127

src/base/conditions/BaseDateRangeConditionRule.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ public function getStartDate(): ?string
8686
return $this->_startDate;
8787
}
8888

89-
/**
90-
* @param mixed $value
91-
*/
9289
public function setStartDate(mixed $value): void
9390
{
9491
$this->_startDate = ($value ? DateTimeHelper::toIso8601($value) : null);
@@ -102,9 +99,6 @@ public function getEndDate(): ?string
10299
return $this->_endDate;
103100
}
104101

105-
/**
106-
* @param mixed $value
107-
*/
108102
public function setEndDate(mixed $value): void
109103
{
110104
$this->_endDate = ($value ? DateTimeHelper::toIso8601($value) : null);

src/base/conditions/BaseTextConditionRule.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ protected function paramValue(): ?string
141141
/**
142142
* Returns whether the condition rule matches the given value.
143143
*
144-
* @param mixed $value
145144
* @return bool
146145
*/
147146
protected function matchValue(mixed $value): bool

src/behaviors/FieldLayoutBehavior.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function getFieldLayoutId(): int
8484
}
8585

8686
if (!isset($id) || !is_numeric($id)) {
87-
throw new InvalidConfigException('Unable to determine the field layout ID for ' . get_class($this->owner) . '.');
87+
throw new InvalidConfigException('Unable to determine the field layout ID for ' . $this->owner::class . '.');
8888
}
8989

9090
return $this->_fieldLayoutId = (int)$id;

src/cache/ElementQueryTagDependency.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,14 @@
1818
*/
1919
class ElementQueryTagDependency extends TagDependency
2020
{
21-
/**
22-
* @var ElementQuery|null
23-
*/
24-
public ?ElementQuery $elementQuery = null;
25-
2621
/**
2722
* Constructor
2823
*
2924
* @param ElementQuery $elementQuery
3025
* @param array $config
3126
*/
32-
public function __construct(ElementQuery $elementQuery, array $config = [])
27+
public function __construct(public ?ElementQuery $elementQuery, array $config = [])
3328
{
34-
$this->elementQuery = $elementQuery;
3529
parent::__construct($config);
3630
}
3731

0 commit comments

Comments
 (0)