diff --git a/lib/ar-softdelete/src/SoftDeleteBehavior.php b/lib/ar-softdelete/src/SoftDeleteBehavior.php index c842ddeb024..d654962b2dc 100644 --- a/lib/ar-softdelete/src/SoftDeleteBehavior.php +++ b/lib/ar-softdelete/src/SoftDeleteBehavior.php @@ -532,7 +532,7 @@ private function detectRestoreAttributeValues() } elseif (!is_scalar($value) && is_callable($value)) { $restoreValue = null; } else { - throw new InvalidConfigException('Unable to automatically determine restore attribute values, "' . get_class($this) . '::$restoreAttributeValues" should be explicitly set.'); + throw new InvalidConfigException('Unable to automatically determine restore attribute values, "' . static::class . '::$restoreAttributeValues" should be explicitly set.'); } $restoreAttributeValues[$name] = $restoreValue; } diff --git a/lib/ar-softdelete/src/SoftDeleteQueryBehavior.php b/lib/ar-softdelete/src/SoftDeleteQueryBehavior.php index f95660c1665..9c570acd88d 100644 --- a/lib/ar-softdelete/src/SoftDeleteQueryBehavior.php +++ b/lib/ar-softdelete/src/SoftDeleteQueryBehavior.php @@ -259,7 +259,7 @@ protected function defaultNotDeletedCondition() } elseif (!is_scalar($value) && is_callable($value)) { $restoreValue = null; } else { - throw new InvalidConfigException('Unable to automatically determine not delete condition, "' . get_class($this) . '::$notDeletedCondition" should be explicitly set.'); + throw new InvalidConfigException('Unable to automatically determine not delete condition, "' . static::class . '::$notDeletedCondition" should be explicitly set.'); } $condition[$attribute] = $restoreValue; @@ -297,12 +297,12 @@ protected function normalizeFilterCondition($condition) $alias = array_keys($fromTables)[0]; foreach ($condition as $attribute => $value) { - if (is_numeric($attribute) || strpos($attribute, '.') !== false) { + if (is_numeric($attribute) || str_contains($attribute, '.')) { continue; } unset($condition[$attribute]); - if (strpos($attribute, '[[') === false) { + if (!str_contains($attribute, '[[')) { $attribute = '[[' . $attribute . ']]'; } $attribute = $alias . '.' . $attribute; diff --git a/lib/yii2/Yii.php b/lib/yii2/Yii.php index 7d1d41a9565..40eb0c94638 100644 --- a/lib/yii2/Yii.php +++ b/lib/yii2/Yii.php @@ -58,7 +58,7 @@ public static function alias(string $path): string $path = FileHelper::normalizePath($path); foreach (self::$_aliasPaths as $alias => $aliasPath) { - if (strpos($path . DIRECTORY_SEPARATOR, $aliasPath . DIRECTORY_SEPARATOR) === 0) { + if (str_starts_with($path . DIRECTORY_SEPARATOR, $aliasPath . DIRECTORY_SEPARATOR)) { return $alias . str_replace('\\', '/', substr($path, strlen($aliasPath))); } } diff --git a/rector.php b/rector.php index c86ed8ecc46..accb03734ff 100644 --- a/rector.php +++ b/rector.php @@ -5,6 +5,10 @@ use Rector\Config\RectorConfig; use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; +use Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector; +use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; +use Rector\Php80\Rector\FunctionLike\MixedTypeRector; +use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector; return RectorConfig::configure() ->withPaths([ @@ -24,5 +28,34 @@ ClosureToArrowFunctionRector::class => [ __DIR__ . '/src/base/ApplicationTrait.php', ], + + // used by finally and next if + RemoveUnusedVariableInCatchRector::class => [ + __DIR__ . '/src/console/controllers/PluginController.php', + __DIR__ . '/src/helpers/DateTimeHelper.php', + ], + + + ChangeSwitchToMatchRector::class => [ + // object check + __DIR__ . '/src/elements/Entry.php', + + // by preference usage, no assign or returns used, just void call + __DIR__ . '/src/base/NestedElementTrait.php', + __DIR__ . '/src/elements/db/NestedElementQueryTrait.php', + __DIR__ . '/src/console/controllers/ProjectConfigController.php', + __DIR__ . '/src/elements/db/ElementQuery.php', + __DIR__ . '/src/elements/db/EntryQuery.php', + __DIR__ . '/src/i18n/Locale.php', + ], + + MixedTypeRector::class, + + ClassPropertyAssignToConstructorPromotionRector::class => [ + __DIR__ . '/src/cache/ElementQueryTagDependency.php', + ], ]) - ->withPhpSets(php74: true); + ->withPhpSets(php80: true) + ->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [ + ClassPropertyAssignToConstructorPromotionRector::RENAME_PROPERTY => false, + ]); diff --git a/src/base/Element.php b/src/base/Element.php index 1427b628cb5..438709603df 100644 --- a/src/base/Element.php +++ b/src/base/Element.php @@ -2526,7 +2526,7 @@ public function __toString(): string public function __isset($name): bool { // Is this the "field:handle" syntax? - if (strncmp($name, 'field:', 6) === 0) { + if (str_starts_with($name, 'field:')) { return $this->fieldByHandle(substr($name, 6)) !== null; } @@ -2544,7 +2544,7 @@ public function __get($name) } // Is this the "field:handle" syntax? - if (strncmp($name, 'field:', 6) === 0) { + if (str_starts_with($name, 'field:')) { return $this->getFieldValue(substr($name, 6)); } @@ -2562,7 +2562,7 @@ public function __get($name) public function __set($name, $value) { // Is this the "field:handle" syntax? - if (strncmp($name, 'field:', 6) === 0) { + if (str_starts_with($name, 'field:')) { $this->setFieldValue(substr($name, 6), $value); return; } @@ -2584,7 +2584,7 @@ public function __set($name, $value) */ public function __call($name, $params) { - if (strncmp($name, 'isFieldEmpty:', 13) === 0) { + if (str_starts_with($name, 'isFieldEmpty:')) { return $this->isFieldEmpty(substr($name, 13)); } @@ -2770,7 +2770,7 @@ public function getIterator(): Traversable public function getAttributeLabel($attribute): string { // Is this the "field:handle" syntax? - if (strncmp($attribute, 'field:', 6) === 0) { + if (str_starts_with($attribute, 'field:')) { $attribute = substr($attribute, 6); } @@ -3036,7 +3036,7 @@ public function isFieldEmpty(string $handle): bool */ public function addError($attribute, $error = ''): void { - if (strncmp($attribute, 'field:', 6) === 0) { + if (str_starts_with($attribute, 'field:')) { $attribute = substr($attribute, 6); } @@ -6588,7 +6588,7 @@ protected function fieldLayoutFields(bool $visibleOnly = false): array { try { $fieldLayout = $this->getFieldLayout(); - } catch (InvalidConfigException $e) { + } catch (InvalidConfigException) { return []; } diff --git a/src/base/Field.php b/src/base/Field.php index b9bd4d0d25d..cf04eaa81cf 100644 --- a/src/base/Field.php +++ b/src/base/Field.php @@ -30,6 +30,7 @@ use DateTime; use Exception; use GraphQL\Type\Definition\Type; +use Stringable; use yii\base\Arrayable; use yii\base\ErrorHandler; use yii\base\InvalidArgumentException; @@ -43,7 +44,7 @@ * @author Pixel & Tonic, Inc. * @since 3.0.0 */ -abstract class Field extends SavableComponent implements FieldInterface, Iconic, Actionable +abstract class Field extends SavableComponent implements FieldInterface, Iconic, Actionable, Stringable { use FieldTrait; diff --git a/src/base/conditions/BaseCondition.php b/src/base/conditions/BaseCondition.php index 4fcab106d55..0f2dd6ac6d4 100644 --- a/src/base/conditions/BaseCondition.php +++ b/src/base/conditions/BaseCondition.php @@ -237,10 +237,10 @@ protected function validateConditionRule(ConditionRuleInterface $rule): bool return false; } - $ruleClass = get_class($rule); + $ruleClass = $rule::class; foreach ($this->getSelectableConditionRules() as $selectableRule) { - if ($ruleClass === get_class($selectableRule)) { + if ($ruleClass === $selectableRule::class) { return true; } } @@ -298,7 +298,7 @@ public function getBuilderInnerHtml(bool $autofocusAddButton = false): string ], ]); - $html .= Html::hiddenInput('class', get_class($this)); + $html .= Html::hiddenInput('class', static::class); $html .= Html::hiddenInput('config', Json::encode($this->getBuilderConfig())); foreach ($this->getConditionRules() as $rule) { @@ -311,7 +311,7 @@ public function getBuilderInnerHtml(bool $autofocusAddButton = false): string 'class' => 'visually-hidden', ]) . Html::hiddenInput('uid', $rule->uid) . - Html::hiddenInput('class', get_class($rule)); + Html::hiddenInput('class', $rule::class); if ($this->sortable) { $ruleHtml .= Html::tag('div', @@ -611,7 +611,7 @@ public function getBuilderConfig(): array public function getConfig(): array { return array_merge($this->config(), [ - 'class' => get_class($this), + 'class' => static::class, 'conditionRules' => $this->_conditionRules ->map(function(ConditionRuleInterface $rule) { try { diff --git a/src/base/conditions/BaseConditionRule.php b/src/base/conditions/BaseConditionRule.php index 90d1e12c06a..2285327b4eb 100644 --- a/src/base/conditions/BaseConditionRule.php +++ b/src/base/conditions/BaseConditionRule.php @@ -121,7 +121,7 @@ public function getGroupLabel(): ?string public function getConfig(): array { $config = [ - 'class' => get_class($this), + 'class' => static::class, 'uid' => $this->uid, ]; diff --git a/src/behaviors/FieldLayoutBehavior.php b/src/behaviors/FieldLayoutBehavior.php index 5d4416176b5..169d3e567c4 100644 --- a/src/behaviors/FieldLayoutBehavior.php +++ b/src/behaviors/FieldLayoutBehavior.php @@ -84,7 +84,7 @@ public function getFieldLayoutId(): int } if (!isset($id) || !is_numeric($id)) { - throw new InvalidConfigException('Unable to determine the field layout ID for ' . get_class($this->owner) . '.'); + throw new InvalidConfigException('Unable to determine the field layout ID for ' . $this->owner::class . '.'); } return $this->_fieldLayoutId = (int)$id; diff --git a/src/console/controllers/MigrateController.php b/src/console/controllers/MigrateController.php index 77cf17bb727..cadb4c3d532 100644 --- a/src/console/controllers/MigrateController.php +++ b/src/console/controllers/MigrateController.php @@ -226,7 +226,7 @@ public function beforeAction($action): bool if (!$this->traitBeforeAction($action)) { return false; } - } catch (InvalidConfigException $e) { + } catch (InvalidConfigException) { // migrations folder not created, but we don't mind. } @@ -586,7 +586,7 @@ public function actionFresh(): int */ protected function truncateDatabase(): void { - throw new NotSupportedException('This command is not implemented in ' . get_class($this)); + throw new NotSupportedException('This command is not implemented in ' . static::class); } /** diff --git a/src/console/controllers/ProjectConfigController.php b/src/console/controllers/ProjectConfigController.php index d0f49ad983f..8ae9c1d4ad3 100644 --- a/src/console/controllers/ProjectConfigController.php +++ b/src/console/controllers/ProjectConfigController.php @@ -167,7 +167,7 @@ public function actionSet(string $path, string $value): int { try { $parsedValue = Yaml::parse($value); - } catch (ParseException $e) { + } catch (ParseException) { $this->stderr('Input value must be valid YAML.' . PHP_EOL, Console::FG_RED); return ExitCode::USAGE; } diff --git a/src/controllers/AppController.php b/src/controllers/AppController.php index 4c5e65e0ef4..7c4b01be49c 100644 --- a/src/controllers/AppController.php +++ b/src/controllers/AppController.php @@ -852,7 +852,7 @@ public function actionRenderComponents(): Response 'icon' => $component instanceof Iconic ? $component->getIcon() : null, 'attributes' => [ 'data' => [ - 'type' => get_class($component), + 'type' => $component::class, 'id' => $component->getId(), ], ], diff --git a/src/controllers/BaseUpdaterController.php b/src/controllers/BaseUpdaterController.php index 7648db8ae62..56f016f3e42 100644 --- a/src/controllers/BaseUpdaterController.php +++ b/src/controllers/BaseUpdaterController.php @@ -508,7 +508,7 @@ protected function runMigrations(array $handles, ?string $restoreAction = null): $previous = $e->getPrevious(); $migration = $e->migration; $output = $e->output; - $error = get_class($migration) . ' migration failed' . ($previous ? ': ' . $previous->getMessage() : '.'); + $error = $migration::class . ' migration failed' . ($previous ? ': ' . $previous->getMessage() : '.'); $e = $previous ?? $e; } else { $migration = $output = null; @@ -546,12 +546,12 @@ protected function runMigrations(array $handles, ?string $restoreAction = null): 'subject' => $ownerName . ' update failure', ]; - $eName = $e instanceof Exception ? $e->getName() : get_class($e); + $eName = $e instanceof Exception ? $e->getName() : $e::class; return $this->send([ 'error' => Craft::t('app', 'One of {name}’s migrations failed.', ['name' => $ownerName]), 'errorDetails' => $eName . ': ' . $e->getMessage() . - ($migration ? "\n\nMigration: " . get_class($migration) : '') . + ($migration ? "\n\nMigration: " . $migration::class : '') . ($output ? "\n\nOutput:\n\n" . $output : ''), 'options' => $options, ]); @@ -599,9 +599,9 @@ protected function installPlugin(string $handle, ?string $edition = null): array Craft::error('Plugin installation failed: ' . $e->getMessage(), __METHOD__); - $eName = $e instanceof YiiException ? $e->getName() : get_class($e); + $eName = $e instanceof YiiException ? $e->getName() : $e::class; $errorDetails = $eName . ': ' . $e->getMessage() . - ($migration ? "\n\nMigration: " . get_class($migration) : '') . + ($migration ? "\n\nMigration: " . $migration::class : '') . ($output ? "\n\nOutput:\n\n" . $output : ''); } @@ -644,7 +644,7 @@ private function _composerErrorDetails(Throwable $e, string $output): string } if (empty($details)) { - $details[] = 'Exception of class ' . get_class($e) . ' was thrown.'; + $details[] = 'Exception of class ' . $e::class . ' was thrown.'; } return implode("\n\n", $details); diff --git a/src/controllers/DashboardController.php b/src/controllers/DashboardController.php index 55ef2cde8db..d5518a6b735 100644 --- a/src/controllers/DashboardController.php +++ b/src/controllers/DashboardController.php @@ -75,7 +75,7 @@ public function actionIndex(): Response $settingsHtml = $view->namespaceInputs(fn() => (string)$widget->getSettingsHtml(), '__NAMESPACE__'); $settingsJs = (string)$view->clearJsBuffer(false); - $class = get_class($widget); + $class = $widget::class; $widgetTypeInfo[$class] = [ 'iconSvg' => $this->_getWidgetIconSvg($widget), 'name' => $widget::displayName(), @@ -201,7 +201,7 @@ public function actionSaveWidgetSettings(): Response 'dateCreated' => $widget->dateCreated, 'dateUpdated' => $widget->dateUpdated, 'colspan' => $widget->colspan, - 'type' => get_class($widget), + 'type' => $widget::class, 'settings' => $settings, ]); @@ -480,7 +480,7 @@ private function _getWidgetInfo(WidgetInterface $widget): array|false return [ 'id' => $widget->id, - 'type' => get_class($widget), + 'type' => $widget::class, 'colspan' => $colspan, 'title' => $widget->getTitle(), 'subtitle' => $widget->getSubtitle(), diff --git a/src/controllers/ElementIndexesController.php b/src/controllers/ElementIndexesController.php index 9a589f4f62f..ee0f8d70140 100644 --- a/src/controllers/ElementIndexesController.php +++ b/src/controllers/ElementIndexesController.php @@ -229,7 +229,7 @@ public function actionPerformAction(): ?Response if (!empty($this->actions)) { /** @var ElementAction $availableAction */ foreach ($this->actions as $availableAction) { - if ($actionClass === get_class($availableAction)) { + if ($actionClass === $availableAction::class) { $action = clone $availableAction; break; } @@ -362,7 +362,7 @@ public function actionExport(): Response $export = $export(); } if (!is_iterable($export)) { - throw new InvalidValueException(get_class($exporter) . '::export() must return an array or generator function since isFormattable() returns true.'); + throw new InvalidValueException($exporter::class . '::export() must return an array or generator function since isFormattable() returns true.'); } $this->response->data = $export; @@ -410,7 +410,7 @@ private function _exporter(): ElementExporterInterface $exporterClass = $this->request->getBodyParam('type', Raw::class); if (!empty($this->exporters)) { foreach ($this->exporters as $exporter) { - if ($exporterClass === get_class($exporter)) { + if ($exporterClass === $exporter::class) { return $exporter; } } @@ -979,7 +979,7 @@ protected function exporterData(): ?array foreach ($this->exporters as $exporter) { $exporterData[] = [ - 'type' => get_class($exporter), + 'type' => $exporter::class, 'name' => $exporter::displayName(), 'formattable' => $exporter::isFormattable(), ]; diff --git a/src/controllers/ElementsController.php b/src/controllers/ElementsController.php index 43a5862b634..95edc091f98 100644 --- a/src/controllers/ElementsController.php +++ b/src/controllers/ElementsController.php @@ -427,7 +427,7 @@ public function actionEdit(?ElementInterface $element, ?int $elementId = null): 'canonicalId' => $canonical->id, 'draftId' => $element->draftId, 'draftName' => $isDraft ? $element->draftName : null, - 'elementType' => get_class($element), + 'elementType' => $element::class, 'enablePreview' => $enablePreview, 'enabledForSite' => $element->enabled && $enabledForSite, 'hashedCpEditUrl' => $security->hashData('{cpEditUrl}'), diff --git a/src/controllers/FieldsController.php b/src/controllers/FieldsController.php index 973dc68a064..3c531bdad73 100644 --- a/src/controllers/FieldsController.php +++ b/src/controllers/FieldsController.php @@ -113,7 +113,7 @@ public function actionEditField(?int $fieldId = null, ?FieldInterface $field = n $allFieldTypes = $fieldsService->getAllFieldTypes(); foreach ($allFieldTypes as $class) { - if ($class === get_class($field) || $class::isSelectable()) { + if ($class === $field::class || $class::isSelectable()) { $supportedTranslationMethods[$class] = $class::supportedTranslationMethods(); } } @@ -135,7 +135,7 @@ public function actionEditField(?int $fieldId = null, ?FieldInterface $field = n $multiInstanceTypesOnly = (bool)$this->request->getParam('multiInstanceTypesOnly'); foreach ($allFieldTypes as $class) { - $isCurrent = $class === ($field instanceof MissingField ? $field->expectedType : get_class($field)); + $isCurrent = $class === ($field instanceof MissingField ? $field->expectedType : $field::class); $foundCurrent = $foundCurrent || $isCurrent; if ( @@ -530,7 +530,7 @@ public function actionApplyLayoutElementSettings(): Response $selectorHtml = Cp::layoutElementSelectorHtml($element); return $this->asJson([ - 'config' => ['type' => get_class($element)] + $element->toArray(), + 'config' => ['type' => $element::class] + $element->toArray(), 'selectorHtml' => $selectorHtml, ]); } diff --git a/src/controllers/QueueController.php b/src/controllers/QueueController.php index ae7711fd8f5..6662c7d6d25 100644 --- a/src/controllers/QueueController.php +++ b/src/controllers/QueueController.php @@ -63,7 +63,7 @@ public function init(): void $queue = Craft::$app->getQueue(); if (!$queue instanceof QueueInterface) { - throw new ServerErrorHttpException(sprintf('The queue class %s doesn’t support web-based runners.', get_class($queue))); + throw new ServerErrorHttpException(sprintf('The queue class %s doesn’t support web-based runners.', $queue::class)); } $this->queue = $queue; } diff --git a/src/controllers/SystemSettingsController.php b/src/controllers/SystemSettingsController.php index 9291dbbc3f5..0c30d951adf 100644 --- a/src/controllers/SystemSettingsController.php +++ b/src/controllers/SystemSettingsController.php @@ -135,8 +135,8 @@ public function actionEditEmailSettings(?MailSettings $settings = null, ?Transpo $allTransportAdapterTypes = MailerHelper::allMailerTransportTypes(); // Make sure the selected adapter class is in there - if (!in_array(get_class($adapter), $allTransportAdapterTypes, true)) { - $allTransportAdapterTypes[] = get_class($adapter); + if (!in_array($adapter::class, $allTransportAdapterTypes, true)) { + $allTransportAdapterTypes[] = $adapter::class; } $allTransportAdapters = []; @@ -144,7 +144,7 @@ public function actionEditEmailSettings(?MailSettings $settings = null, ?Transpo foreach ($allTransportAdapterTypes as $transportAdapterType) { /** @var class-string $transportAdapterType */ - if ($transportAdapterType === get_class($adapter) || $transportAdapterType::isSelectable()) { + if ($transportAdapterType === $adapter::class || $transportAdapterType::isSelectable()) { $allTransportAdapters[] = MailerHelper::createTransportAdapter($transportAdapterType); $transportTypeOptions[] = [ 'value' => $transportAdapterType, diff --git a/src/db/CoalesceColumnsExpression.php b/src/db/CoalesceColumnsExpression.php index 78066a29b11..31585f1da3c 100644 --- a/src/db/CoalesceColumnsExpression.php +++ b/src/db/CoalesceColumnsExpression.php @@ -17,20 +17,14 @@ */ class CoalesceColumnsExpression extends BaseObject implements ExpressionInterface { - /** - * @var string[] The columns that should be coalesced. - */ - public array $columns; - /** * Constructor * * @param string[] $columns The columns that should be coalesced. * @param array $config */ - public function __construct(array $columns = [], array $config = []) + public function __construct(public array $columns = [], array $config = []) { - $this->columns = $columns; parent::__construct($config); } diff --git a/src/db/FixedOrderExpression.php b/src/db/FixedOrderExpression.php index 5dacda8852d..7e3c0b187db 100644 --- a/src/db/FixedOrderExpression.php +++ b/src/db/FixedOrderExpression.php @@ -17,21 +17,6 @@ */ class FixedOrderExpression extends Expression { - /** - * @var string The column name that contains the values - */ - public string $column; - - /** - * @var array The column values, in the order in which the rows should be returned in - */ - public array $values; - - /** - * @var Connection The DB connection - */ - public Connection $db; - /** * Constructor * @@ -41,13 +26,9 @@ class FixedOrderExpression extends Expression * @param array $params Parameters * @param array $config Name-value pairs that will be used to initialize the object properties. */ - public function __construct(string $column, array $values, Connection $db, array $params = [], array $config = []) + public function __construct(public string $column, public array $values, public Connection $db, array $params = [], array $config = []) { - $this->column = $column; - $this->values = $values; - $this->db = $db; - - $expression = $db->getQueryBuilder()->fixedOrder($column, $values); + $expression = $this->db->getQueryBuilder()->fixedOrder($this->column, $this->values); parent::__construct($expression, $params, $config); } } diff --git a/src/db/MigrationManager.php b/src/db/MigrationManager.php index c6e9338aedb..a7567a88d33 100644 --- a/src/db/MigrationManager.php +++ b/src/db/MigrationManager.php @@ -436,7 +436,7 @@ private function _normalizeMigration(\yii\db\Migration|string|MigrationInterface $migrationName = $migration; $migration = $this->createMigration($migration); } else { - $classParts = explode('\\', get_class($migration)); + $classParts = explode('\\', $migration::class); $migrationName = array_pop($classParts); } diff --git a/src/db/Paginator.php b/src/db/Paginator.php index 0d0d695e964..f83bb453f4c 100644 --- a/src/db/Paginator.php +++ b/src/db/Paginator.php @@ -58,11 +58,6 @@ class Paginator extends BaseObject */ public int $pageSize = 100; - /** - * @var QueryInterface The query being paginated - */ - protected QueryInterface $query; - /** * @var int The total query count */ @@ -89,10 +84,8 @@ class Paginator extends BaseObject * @param QueryInterface $query The query that should be paginated * @param array $config */ - public function __construct(QueryInterface $query, array $config = []) + public function __construct(protected QueryInterface $query, array $config = []) { - $this->query = $query; - // Set the current page after everything else $currentPage = ArrayHelper::remove($config, 'currentPage'); diff --git a/src/debug/LogTarget.php b/src/debug/LogTarget.php index d851f7c1c24..a17369b49c8 100644 --- a/src/debug/LogTarget.php +++ b/src/debug/LogTarget.php @@ -169,7 +169,7 @@ private function _updateIndexFile(string $indexFile, array $summary): void { try { $manifest = unserialize($this->module->fs->read($indexFile)); - } catch (FsException $e) { + } catch (FsException) { $manifest = []; } diff --git a/src/elements/Address.php b/src/elements/Address.php index 51480cbbea7..14164d1e1e7 100644 --- a/src/elements/Address.php +++ b/src/elements/Address.php @@ -119,12 +119,10 @@ protected static function defineTableAttributes(): array */ protected function attributeHtml(string $attribute): string { - switch ($attribute) { - case 'country': - return $this->getCountry()->getName(); - default: - return parent::attributeHtml($attribute); - } + return match ($attribute) { + 'country' => $this->getCountry()->getName(), + default => parent::attributeHtml($attribute), + }; } /** diff --git a/src/elements/Asset.php b/src/elements/Asset.php index 86820df2ad1..4451d0d566c 100644 --- a/src/elements/Asset.php +++ b/src/elements/Asset.php @@ -831,7 +831,7 @@ public static function indexElementCount(ElementQueryInterface $elementQuery, ?s if (self::_includeFoldersInIndexElements($elementQuery, $sourceKey, $queryFolder)) { try { $count += self::_createFolderQueryForIndex($elementQuery, $queryFolder)->count(); - } catch (QueryAbortedException $e) { + } catch (QueryAbortedException) { return 0; } } @@ -1232,7 +1232,7 @@ public function __isset($name): bool { return ( parent::__isset($name) || - strncmp($name, 'transform:', 10) === 0 || + str_starts_with($name, 'transform:') || Craft::$app->getImageTransforms()->getTransformByHandle($name) ); } @@ -1251,7 +1251,7 @@ public function __isset($name): bool */ public function __get($name) { - if (strncmp($name, 'transform:', 10) === 0) { + if (str_starts_with($name, 'transform:')) { return $this->copyWithTransform(substr($name, 10)); } @@ -2772,15 +2772,13 @@ public function getInlineAttributeInputHtml(string $attribute): string */ protected function inlineAttributeInputHtml(string $attribute): string { - switch ($attribute) { - case 'alt': - return Cp::textareaHtml([ - 'name' => 'alt', - 'value' => $this->alt, - ]); - default: - return parent::inlineAttributeInputHtml($attribute); - } + return match ($attribute) { + 'alt' => Cp::textareaHtml([ + 'name' => 'alt', + 'value' => $this->alt, + ]), + default => parent::inlineAttributeInputHtml($attribute), + }; } /** @@ -2806,34 +2804,26 @@ public function getPreviewHtml(): string ($userSession->getId() == $this->uploaderId || $userSession->checkPermission("editPeerImages:$volume->uid")) ); - switch ($this->kind) { - case Asset::KIND_VIDEO: - $previewInner = - Html::tag('video', Html::tag('source', '', [ - 'type' => $this->getMimeType(), - 'src' => $this->url, - ]), [ - 'class' => 'preview-thumb', - 'controls' => true, - 'preload' => 'metadata', - ]); - break; - case Asset::KIND_AUDIO: - $previewInner = - Html::tag('audio', Html::tag('source', '', [ - 'src' => $this->url, - 'type' => $this->getMimeType(), - ]), [ - 'controls' => true, - 'preload' => 'metadata', - ]); - break; - default: - $previewInner = - Html::tag('div', $this->getPreviewThumbImg(350, 190), [ - 'class' => 'preview-thumb', - ]); - } + $previewInner = match ($this->kind) { + Asset::KIND_VIDEO => Html::tag('video', Html::tag('source', '', [ + 'type' => $this->getMimeType(), + 'src' => $this->url, + ]), [ + 'class' => 'preview-thumb', + 'controls' => true, + 'preload' => 'metadata', + ]), + Asset::KIND_AUDIO => Html::tag('audio', Html::tag('source', '', [ + 'src' => $this->url, + 'type' => $this->getMimeType(), + ]), [ + 'controls' => true, + 'preload' => 'metadata', + ]), + default => Html::tag('div', $this->getPreviewThumbImg(350, 190), [ + 'class' => 'preview-thumb', + ]), + }; $previewThumbHtml = Html::beginTag('div', [ diff --git a/src/elements/Category.php b/src/elements/Category.php index 60802c66332..8268e44c9af 100644 --- a/src/elements/Category.php +++ b/src/elements/Category.php @@ -770,15 +770,13 @@ public function getGroup(): CategoryGroup */ protected function inlineAttributeInputHtml(string $attribute): string { - switch ($attribute) { - case 'slug': - return Cp::textHtml([ - 'name' => 'slug', - 'value' => $this->slug, - ]); - default: - return parent::inlineAttributeInputHtml($attribute); - } + return match ($attribute) { + 'slug' => Cp::textHtml([ + 'name' => 'slug', + 'value' => $this->slug, + ]), + default => parent::inlineAttributeInputHtml($attribute), + }; } /** diff --git a/src/elements/Entry.php b/src/elements/Entry.php index a1e4c9e0e18..0956d459264 100644 --- a/src/elements/Entry.php +++ b/src/elements/Entry.php @@ -2400,7 +2400,7 @@ public function showStatusField(): bool { try { $showStatusField = $this->getType()->showStatusField; - } catch (InvalidConfigException $e) { + } catch (InvalidConfigException) { $showStatusField = true; } diff --git a/src/elements/GlobalSet.php b/src/elements/GlobalSet.php index e7090afd93f..21215018aca 100644 --- a/src/elements/GlobalSet.php +++ b/src/elements/GlobalSet.php @@ -298,7 +298,7 @@ public function beforeDelete(): bool try { $fieldLayout = $this->getFieldLayout(); - } catch (InvalidConfigException $e) { + } catch (InvalidConfigException) { $fieldLayout = null; } diff --git a/src/elements/NestedElementManager.php b/src/elements/NestedElementManager.php index 8de674792d5..8d7db3fd37b 100644 --- a/src/elements/NestedElementManager.php +++ b/src/elements/NestedElementManager.php @@ -337,7 +337,7 @@ public function getSupportedSiteIds(ElementInterface $owner): array if (!isset($propagationKey)) { $include = true; } else { - $siteOwner = $elementsService->getElementById($owner->id, get_class($owner), $siteId); + $siteOwner = $elementsService->getElementById($owner->id, $owner::class, $siteId); $include = $siteOwner && $propagationKey === $view->renderObjectTemplate($this->propagationKeyFormat, $siteOwner); } break; diff --git a/src/elements/actions/ChangeSortOrder.php b/src/elements/actions/ChangeSortOrder.php index 42f370f5b78..17c53d2e118 100644 --- a/src/elements/actions/ChangeSortOrder.php +++ b/src/elements/actions/ChangeSortOrder.php @@ -110,7 +110,7 @@ public function getTriggerHtml(): ?string [ static::class, [ - 'ownerElementType' => get_class($this->owner), + 'ownerElementType' => $this->owner::class, 'ownerId' => $this->owner->id, 'ownerSiteId' => $this->owner->siteId, 'attribute' => $this->attribute, diff --git a/src/elements/db/ElementQuery.php b/src/elements/db/ElementQuery.php index b753208e8d4..1003178ecab 100644 --- a/src/elements/db/ElementQuery.php +++ b/src/elements/db/ElementQuery.php @@ -110,14 +110,6 @@ class ElementQuery extends Query implements ElementQueryInterface */ public const EVENT_AFTER_POPULATE_ELEMENTS = 'afterPopulateElements'; - // Base config attributes - // ------------------------------------------------------------------------- - - /** - * @var class-string The name of the [[ElementInterface]] class. - */ - public string $elementType; - /** * @var Query|null The query object created by [[prepare()]] * @see prepare() @@ -597,10 +589,8 @@ class ElementQuery extends Query implements ElementQueryInterface * @param class-string $elementType The element type class associated with this query * @param array $config Configurations to be applied to the newly created query object */ - public function __construct(string $elementType, array $config = []) + public function __construct(public string $elementType, array $config = []) { - $this->elementType = $elementType; - // Use ** as a placeholder for "all the default columns" $config['select'] ??= ['**' => '**']; @@ -629,7 +619,7 @@ public function __set($name, $value) /** * @inheritdoc */ - public function __toString() + public function __toString(): string { return self::class; } diff --git a/src/errors/ElementException.php b/src/errors/ElementException.php index 3ba8bcaef51..fc764f42912 100644 --- a/src/errors/ElementException.php +++ b/src/errors/ElementException.php @@ -18,11 +18,6 @@ */ class ElementException extends Exception { - /** - * @var ElementInterface The element - */ - public ElementInterface $element; - /** * Constructor. * @@ -30,9 +25,8 @@ class ElementException extends Exception * @param string|null $message The error message * @param int $code The error code */ - public function __construct(ElementInterface $element, ?string $message = null, int $code = 0) + public function __construct(public ElementInterface $element, ?string $message = null, int $code = 0) { - $this->element = $element; parent::__construct($message, $code); } } diff --git a/src/errors/FieldNotFoundException.php b/src/errors/FieldNotFoundException.php index 11a6e39267b..7c396a740eb 100644 --- a/src/errors/FieldNotFoundException.php +++ b/src/errors/FieldNotFoundException.php @@ -18,11 +18,6 @@ */ class FieldNotFoundException extends Exception { - /** - * @var string The field’s UUID - */ - public string $fieldUid; - /** * Constructor * @@ -31,9 +26,8 @@ class FieldNotFoundException extends Exception * @param int $code * @param Throwable|null $previous */ - public function __construct(string $fieldUid, string $message = '', int $code = 0, ?Throwable $previous = null) + public function __construct(public string $fieldUid, string $message = '', int $code = 0, ?Throwable $previous = null) { - $this->fieldUid = $fieldUid; parent::__construct($message, $code, $previous); } diff --git a/src/errors/InvalidHtmlTagException.php b/src/errors/InvalidHtmlTagException.php index 89e4f96c6ff..376419d450f 100644 --- a/src/errors/InvalidHtmlTagException.php +++ b/src/errors/InvalidHtmlTagException.php @@ -17,26 +17,6 @@ */ class InvalidHtmlTagException extends InvalidArgumentException { - /** - * @var string|null The tag type - */ - public ?string $type = null; - - /** - * @var array|null The tag attributes - */ - public ?array $attributes = null; - - /** - * @var int|null The tag’s starting position - */ - public ?int $start = null; - - /** - * @var int|null The tag’s inner HTML starting position - */ - public ?int $htmlStart = null; - /** * Constructor. * @@ -46,13 +26,8 @@ class InvalidHtmlTagException extends InvalidArgumentException * @param int|null $start The tag’s starting position * @param int|null $htmlStart The tag’s inner HTML starting position */ - public function __construct(string $message, ?string $type = null, ?array $attributes = null, ?int $start = null, ?int $htmlStart = null) + public function __construct(string $message, public ?string $type = null, public ?array $attributes = null, public ?int $start = null, public ?int $htmlStart = null) { - $this->type = $type; - $this->attributes = $attributes; - $this->start = $start; - $this->htmlStart = $htmlStart; - parent::__construct($message); } diff --git a/src/errors/InvalidLicenseKeyException.php b/src/errors/InvalidLicenseKeyException.php index 4af21267ba5..a537befd14c 100644 --- a/src/errors/InvalidLicenseKeyException.php +++ b/src/errors/InvalidLicenseKeyException.php @@ -17,11 +17,6 @@ */ class InvalidLicenseKeyException extends Exception { - /** - * @var string The license key - */ - public string $licenseKey; - /** * Constructor. * @@ -29,12 +24,10 @@ class InvalidLicenseKeyException extends Exception * @param string|null $message The error message * @param int $code The error code */ - public function __construct(string $licenseKey, ?string $message = null, int $code = 0) + public function __construct(public string $licenseKey, ?string $message = null, int $code = 0) { - $this->licenseKey = $licenseKey; - if ($message === null) { - $message = "The license key “{$licenseKey}” is invalid."; + $message = "The license key “{$this->licenseKey}” is invalid."; } parent::__construct($message, $code); diff --git a/src/errors/InvalidPluginException.php b/src/errors/InvalidPluginException.php index d4b0cc4af14..bf4575b6654 100644 --- a/src/errors/InvalidPluginException.php +++ b/src/errors/InvalidPluginException.php @@ -17,11 +17,6 @@ */ class InvalidPluginException extends Exception { - /** - * @var string The invalid plugin handle - */ - public string $handle; - /** * Constructor. * @@ -29,12 +24,10 @@ class InvalidPluginException extends Exception * @param string|null $message The error message * @param int $code The error code */ - public function __construct(string $handle, ?string $message = null, int $code = 0) + public function __construct(public string $handle, ?string $message = null, int $code = 0) { - $this->handle = $handle; - if ($message === null) { - $message = "No plugin exists with the handle \"$handle\"."; + $message = "No plugin exists with the handle \"{$this->handle}\"."; } parent::__construct($message, $code); diff --git a/src/errors/InvalidSubpathException.php b/src/errors/InvalidSubpathException.php index da74102c8cb..585ca4cb781 100644 --- a/src/errors/InvalidSubpathException.php +++ b/src/errors/InvalidSubpathException.php @@ -18,11 +18,6 @@ */ class InvalidSubpathException extends Exception { - /** - * @var string The invalid subpath - */ - public string $subpath; - /** * Constructor. * @@ -31,12 +26,10 @@ class InvalidSubpathException extends Exception * @param int $code The error code * @param Throwable|null $previous The previous exception */ - public function __construct(string $subpath, ?string $message = null, int $code = 0, ?Throwable $previous = null) + public function __construct(public string $subpath, ?string $message = null, int $code = 0, ?Throwable $previous = null) { - $this->subpath = $subpath; - if ($message === null) { - $message = "Could not resolve the subpath “{$subpath}”."; + $message = "Could not resolve the subpath “{$this->subpath}”."; } parent::__construct($message, $code, $previous); diff --git a/src/errors/InvalidTypeException.php b/src/errors/InvalidTypeException.php index ff21687aa50..0b45a355644 100644 --- a/src/errors/InvalidTypeException.php +++ b/src/errors/InvalidTypeException.php @@ -17,16 +17,6 @@ */ class InvalidTypeException extends Exception { - /** - * @var class-string The invalid class name - */ - public string $class; - - /** - * @var class-string The base class or interface that [[$class]] was supposed to be - */ - public string $requiredType; - /** * Constructor. * @@ -35,13 +25,10 @@ class InvalidTypeException extends Exception * @param string|null $message The error message * @param int $code The error code */ - public function __construct(string $class, string $requiredType, ?string $message = null, int $code = 0) + public function __construct(public string $class, public string $requiredType, ?string $message = null, int $code = 0) { - $this->class = $class; - $this->requiredType = $requiredType; - if ($message === null) { - $message = "$class doesn’t exist or doesn’t extend/implement $requiredType"; + $message = "{$this->class} doesn’t exist or doesn’t extend/implement {$this->requiredType}"; } parent::__construct($message, $code); diff --git a/src/errors/MigrateException.php b/src/errors/MigrateException.php index a752a386463..54db704ccde 100644 --- a/src/errors/MigrateException.php +++ b/src/errors/MigrateException.php @@ -18,16 +18,6 @@ */ class MigrateException extends Exception { - /** - * @var string The name of the thing being updated - */ - public string $ownerName; - - /** - * @var string The handle of the thing being updated - */ - public string $ownerHandle; - /** * Constructor. * @@ -37,13 +27,10 @@ class MigrateException extends Exception * @param int $code The error code * @param Throwable|null $previous The previous exception */ - public function __construct(string $ownerName, string $ownerHandle, ?string $message = null, int $code = 0, Throwable $previous = null) + public function __construct(public string $ownerName, public string $ownerHandle, ?string $message = null, int $code = 0, Throwable $previous = null) { - $this->ownerName = $ownerName; - $this->ownerHandle = $ownerHandle; - if ($message === null) { - $message = 'An error occurred while migrating ' . $ownerName . '.'; + $message = 'An error occurred while migrating ' . $this->ownerName . '.'; } parent::__construct($message, $code, $previous); diff --git a/src/errors/MigrationException.php b/src/errors/MigrationException.php index a246adaec2a..3dad4da30d2 100644 --- a/src/errors/MigrationException.php +++ b/src/errors/MigrationException.php @@ -19,16 +19,6 @@ */ class MigrationException extends UserException { - /** - * @var Migration The migration being executed - */ - public Migration $migration; - - /** - * @var string|null The migration output - */ - public ?string $output = null; - /** * Constructor. * @@ -38,13 +28,10 @@ class MigrationException extends UserException * @param int $code The error code * @param Throwable|null $previous The previous exception */ - public function __construct(Migration $migration, ?string $output = null, ?string $message = null, int $code = 0, ?Throwable $previous = null) + public function __construct(public Migration $migration, public ?string $output = null, ?string $message = null, int $code = 0, ?Throwable $previous = null) { - $this->migration = $migration; - $this->output = $output; - if ($message === null) { - $message = 'An error occurred while executing the "' . get_class($migration) . ' migration' . ($previous ? ': ' . $previous->getMessage() : '.'); + $message = 'An error occurred while executing the "' . $this->migration::class . ' migration' . ($previous ? ': ' . $previous->getMessage() : '.'); } parent::__construct($message, $code, $previous); diff --git a/src/errors/MissingAssetException.php b/src/errors/MissingAssetException.php index 67a2ac03cda..61bd6d24ec6 100644 --- a/src/errors/MissingAssetException.php +++ b/src/errors/MissingAssetException.php @@ -21,26 +21,6 @@ */ class MissingAssetException extends Exception { - /** - * @var AssetIndexData - */ - public AssetIndexData $indexEntry; - - /** - * @var Volume - */ - public Volume $volume; - - /** - * @var VolumeFolder - */ - public VolumeFolder $folder; - - /** - * @var string - */ - public string $filename; - /** * Constructor * @@ -52,12 +32,8 @@ class MissingAssetException extends Exception * @param int $code * @param Throwable|null $previous */ - public function __construct(AssetIndexData $indexEntry, Volume $volume, VolumeFolder $folder, string $filename, string $message = '', int $code = 0, ?Throwable $previous = null) + public function __construct(public AssetIndexData $indexEntry, public Volume $volume, public VolumeFolder $folder, public string $filename, string $message = '', int $code = 0, ?Throwable $previous = null) { - $this->indexEntry = $indexEntry; - $this->volume = $volume; - $this->folder = $folder; - $this->filename = $filename; parent::__construct($message, $code, $previous); } diff --git a/src/errors/MissingVolumeFolderException.php b/src/errors/MissingVolumeFolderException.php index 8581d99e970..4e98a321c49 100644 --- a/src/errors/MissingVolumeFolderException.php +++ b/src/errors/MissingVolumeFolderException.php @@ -20,21 +20,6 @@ */ class MissingVolumeFolderException extends Exception { - /** - * @var AssetIndexData - */ - public AssetIndexData $indexEntry; - - /** - * @var Volume - */ - public Volume $volume; - - /** - * @var string - */ - public string $folderName; - /** * Constructor * @@ -45,11 +30,8 @@ class MissingVolumeFolderException extends Exception * @param int $code * @param Throwable|null $previous */ - public function __construct(AssetIndexData $indexEntry, Volume $volume, string $folderName, string $message = '', int $code = 0, ?Throwable $previous = null) + public function __construct(public AssetIndexData $indexEntry, public Volume $volume, public string $folderName, string $message = '', int $code = 0, ?Throwable $previous = null) { - $this->indexEntry = $indexEntry; - $this->volume = $volume; - $this->folderName = $folderName; parent::__construct($message, $code, $previous); } diff --git a/src/errors/ShellCommandException.php b/src/errors/ShellCommandException.php index 4391d5e4d99..d7acd84f13a 100644 --- a/src/errors/ShellCommandException.php +++ b/src/errors/ShellCommandException.php @@ -18,21 +18,6 @@ */ final class ShellCommandException extends Exception { - /** - * @var string The command that was executed - */ - public string $command; - - /** - * @var int The command’s exit code - */ - public int $exitCode; - - /** - * @var string|null The command’s error output - */ - public ?string $error = null; - /** * Creates a ShellCommandException from a [[Command]] object * @@ -59,14 +44,10 @@ public static function createFromCommand(Command $command): self|false * @param string|null $message The error message * @param int $code The error code */ - public function __construct(string $command, int $exitCode, ?string $error = null, ?string $message = null, int $code = 0) + public function __construct(public string $command, public int $exitCode, public ?string $error = null, ?string $message = null, int $code = 0) { - $this->command = $command; - $this->exitCode = $exitCode; - $this->error = $error; - if ($message === null) { - $message = "The shell command \"$command\" failed with exit code $exitCode" . ($error ? ": $error" : '.'); + $message = "The shell command \"{$this->command}\" failed with exit code {$this->exitCode}" . ($this->error ? ": {$this->error}" : '.'); } parent::__construct($message, $code); diff --git a/src/errors/SsoFailedException.php b/src/errors/SsoFailedException.php index 878459f0b1a..f08c1ede4f1 100644 --- a/src/errors/SsoFailedException.php +++ b/src/errors/SsoFailedException.php @@ -18,16 +18,6 @@ */ class SsoFailedException extends Exception { - /** - * @var ProviderInterface - */ - public ProviderInterface $provider; - - /** - * @var User|null - */ - public ?User $identity; - /** * Constructor * @@ -37,10 +27,8 @@ class SsoFailedException extends Exception * @param int $code * @param Throwable|null $previous */ - public function __construct(ProviderInterface $provider, ?User $identity = null, string $message = '', int $code = 0, ?Throwable $previous = null) + public function __construct(public ProviderInterface $provider, public ?User $identity = null, string $message = '', int $code = 0, ?Throwable $previous = null) { - $this->provider = $provider; - $this->identity = $identity; parent::__construct($message, $code, $previous); } diff --git a/src/errors/UnsupportedSiteException.php b/src/errors/UnsupportedSiteException.php index 575b03ca94e..7e6a0732328 100644 --- a/src/errors/UnsupportedSiteException.php +++ b/src/errors/UnsupportedSiteException.php @@ -17,11 +17,6 @@ */ class UnsupportedSiteException extends ElementException { - /** - * @var int The site ID that the element doesn’t support. - */ - public int $siteId; - /** * Constructor. * @@ -30,12 +25,10 @@ class UnsupportedSiteException extends ElementException * @param string|null $message The error message * @param int $code The error code */ - public function __construct(ElementInterface $element, int $siteId, ?string $message = null, int $code = 0) + public function __construct(ElementInterface $element, public int $siteId, ?string $message = null, int $code = 0) { - $this->siteId = $siteId; - if ($message === null) { - $message = "The element “{$element}” doesn’t support site $siteId."; + $message = "The element “{$element}” doesn’t support site {$this->siteId}."; } parent::__construct($element, $message, $code); diff --git a/src/errors/UploadFailedException.php b/src/errors/UploadFailedException.php index ff7beedde62..208999547a9 100644 --- a/src/errors/UploadFailedException.php +++ b/src/errors/UploadFailedException.php @@ -18,11 +18,6 @@ */ class UploadFailedException extends FileException { - /** - * @var int Error code - */ - public int $errorCode; - /** * Constructor * @@ -30,12 +25,10 @@ class UploadFailedException extends FileException * @param string|null $message * @param Throwable|null $previous */ - public function __construct(int $errorCode = 0, ?string $message = null, Throwable $previous = null) + public function __construct(public int $errorCode = 0, ?string $message = null, Throwable $previous = null) { - $this->errorCode = $errorCode; - if ($message === null) { - $message = match ($errorCode) { + $message = match ($this->errorCode) { UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE => Craft::t('app', 'The uploaded file exceeds the maximum allowed size.'), UPLOAD_ERR_PARTIAL, UPLOAD_ERR_NO_FILE => Craft::t('app', 'The file failed to upload to the server properly.'), UPLOAD_ERR_NO_TMP_DIR => Craft::t('app', 'Could not write to the temporary upload folder.'), diff --git a/src/errors/UserLockedException.php b/src/errors/UserLockedException.php index e6b6288dcba..df1bef3c64e 100644 --- a/src/errors/UserLockedException.php +++ b/src/errors/UserLockedException.php @@ -19,11 +19,6 @@ */ class UserLockedException extends Exception { - /** - * @var User The user that's locked. - */ - public User $user; - /** * Constructor * @@ -32,9 +27,8 @@ class UserLockedException extends Exception * @param int $code * @param Throwable|null $previous */ - public function __construct(User $user, string $message = '', int $code = 0, ?Throwable $previous = null) + public function __construct(public User $user, string $message = '', int $code = 0, ?Throwable $previous = null) { - $this->user = $user; parent::__construct($message, $code, $previous); } diff --git a/src/events/AuthorizationCheckEvent.php b/src/events/AuthorizationCheckEvent.php index bfc690bb036..3d522514b78 100644 --- a/src/events/AuthorizationCheckEvent.php +++ b/src/events/AuthorizationCheckEvent.php @@ -25,9 +25,8 @@ class AuthorizationCheckEvent extends Event * @param User $user * @param array $config */ - public function __construct(User $user, array $config = []) + public function __construct(public User $user, array $config = []) { - $this->user = $user; parent::__construct($config); } @@ -40,11 +39,6 @@ public function __construct(User $user, array $config = []) */ public ?ElementInterface $element = null; - /** - * @var User The user to be authorized. - */ - public User $user; - /** * @var bool|null Whether the user is authorized. */ diff --git a/src/events/CreateElementCheckEvent.php b/src/events/CreateElementCheckEvent.php index 756186ad16f..3c61dfa7d0f 100644 --- a/src/events/CreateElementCheckEvent.php +++ b/src/events/CreateElementCheckEvent.php @@ -24,14 +24,8 @@ class CreateElementCheckEvent extends AuthorizationCheckEvent * @param array $attributes * @param array $config */ - public function __construct(User $user, array $attributes, array $config = []) + public function __construct(User $user, public array $attributes, array $config = []) { - $this->attributes = $attributes; parent::__construct($user, $config); } - - /** - * @var array The attributes the new element would be created with. - */ - public array $attributes; } diff --git a/src/events/FsEvent.php b/src/events/FsEvent.php index f6b214b05a5..63f9d77d3fa 100644 --- a/src/events/FsEvent.php +++ b/src/events/FsEvent.php @@ -24,14 +24,8 @@ class FsEvent extends Event * @param FsInterface $fs * @param array $config */ - public function __construct(FsInterface $fs, array $config = []) + public function __construct(public FsInterface $fs, array $config = []) { - $this->fs = $fs; parent::__construct($config); } - - /** - * @var FsInterface The filesystem - */ - public FsInterface $fs; } diff --git a/src/fieldlayoutelements/CustomField.php b/src/fieldlayoutelements/CustomField.php index b521cb6eeaf..fc7b155e7ad 100644 --- a/src/fieldlayoutelements/CustomField.php +++ b/src/fieldlayoutelements/CustomField.php @@ -254,7 +254,7 @@ protected function containerAttributes(?ElementInterface $element = null, bool $ return ArrayHelper::merge(parent::containerAttributes($element, $static), [ 'id' => "{$this->_field->handle}-field", 'data' => [ - 'type' => get_class($field), + 'type' => $field::class, ], ]); } diff --git a/src/fieldlayoutelements/Html.php b/src/fieldlayoutelements/Html.php index 9128d461c22..3cfc022db56 100644 --- a/src/fieldlayoutelements/Html.php +++ b/src/fieldlayoutelements/Html.php @@ -20,14 +20,11 @@ */ class Html extends FieldLayoutElement { - private string $html; - /** * Constructor */ - public function __construct(string $html, array $config = []) + public function __construct(private string $html, array $config = []) { - $this->html = $html; parent::__construct($config); } diff --git a/src/fields/Number.php b/src/fields/Number.php index 13a29870ac2..e01812ce60d 100644 --- a/src/fields/Number.php +++ b/src/fields/Number.php @@ -274,7 +274,7 @@ protected function inputHtml(mixed $value, ?ElementInterface $element, bool $inl try { $formatNumber = !$this->step && !$formatter->willBeMisrepresented($value); - } catch (InvalidArgumentException $e) { + } catch (InvalidArgumentException) { $formatNumber = false; } diff --git a/src/fields/data/ColorData.php b/src/fields/data/ColorData.php index e625daaa0ca..95d5280030c 100644 --- a/src/fields/data/ColorData.php +++ b/src/fields/data/ColorData.php @@ -8,6 +8,7 @@ namespace craft\fields\data; use craft\base\Serializable; +use Stringable; use yii\base\BaseObject; /** @@ -26,7 +27,7 @@ * @author Top Shelf Craft * @since 3.0.0 */ -class ColorData extends BaseObject implements Serializable +class ColorData extends BaseObject implements Serializable, Stringable { /** * @var string The color’s hex value diff --git a/src/fields/data/LinkData.php b/src/fields/data/LinkData.php index 7ba229cd267..758badfe93d 100644 --- a/src/fields/data/LinkData.php +++ b/src/fields/data/LinkData.php @@ -14,6 +14,7 @@ use craft\fields\linktypes\BaseLinkType; use craft\helpers\Html; use craft\helpers\Template; +use Stringable; use Twig\Markup; use yii\base\BaseObject; @@ -30,7 +31,7 @@ * @author Pixel & Tonic, Inc. * @since 5.3.0 */ -class LinkData extends BaseObject implements Serializable +class LinkData extends BaseObject implements Serializable, Stringable { /** * @var string|null The link’s URL suffix value. diff --git a/src/fields/data/OptionData.php b/src/fields/data/OptionData.php index a9ae7ad1872..3663b96d0be 100644 --- a/src/fields/data/OptionData.php +++ b/src/fields/data/OptionData.php @@ -8,6 +8,7 @@ namespace craft\fields\data; use craft\base\Serializable; +use Stringable; /** * Class OptionData @@ -15,29 +16,8 @@ * @author Pixel & Tonic, Inc. * @since 3.0.0 */ -class OptionData implements Serializable +class OptionData implements Serializable, Stringable { - /** - * @var string|null - */ - public ?string $label = null; - - /** - * @var string|null - */ - public ?string $value = null; - - /** - * @var bool - */ - public bool $selected; - - /** - * @var bool - * @since 3.5.10 - */ - public bool $valid; - /** * Constructor * @@ -46,12 +26,15 @@ class OptionData implements Serializable * @param bool $selected * @param bool $valid */ - public function __construct(?string $label, ?string $value, bool $selected, bool $valid = true) - { - $this->label = $label; - $this->value = $value; - $this->selected = $selected; - $this->valid = $valid; + public function __construct( + public ?string $label, + public ?string $value, + public bool $selected, + /** + * @since 3.5.10 + */ + public bool $valid = true, + ) { } /** diff --git a/src/fields/linktypes/Url.php b/src/fields/linktypes/Url.php index d87e4d4bf20..891e5823c8b 100644 --- a/src/fields/linktypes/Url.php +++ b/src/fields/linktypes/Url.php @@ -80,7 +80,7 @@ public function validateValue(string $value, ?string &$error = null): bool // Leveraging Uri package to convert domains to punycode $value = Uri::new($value); return parent::validateValue($value, $error); - } catch (\Exception $e) { + } catch (\Exception) { return false; } } diff --git a/src/helpers/App.php b/src/helpers/App.php index 2880adb394c..37382631340 100644 --- a/src/helpers/App.php +++ b/src/helpers/App.php @@ -1432,7 +1432,7 @@ public static function licensingIssues(bool $withUnresolvables = true, bool $fet // If the license key path starts with the root project path, trim the project path off $rootPath = Craft::getAlias('@root'); - if (strpos($keyPath, $rootPath . '/') === 0) { + if (str_starts_with($keyPath, $rootPath . '/')) { $keyPath = substr($keyPath, strlen($rootPath) + 1); } diff --git a/src/helpers/Cp.php b/src/helpers/Cp.php index 5865fe3bce4..19e1b85cb52 100644 --- a/src/helpers/Cp.php +++ b/src/helpers/Cp.php @@ -241,7 +241,7 @@ public static function alerts(?string $path = null, bool $fetch = false): array while (true) { try { $tagInfo = Html::parseTag($alert['content'], $offset); - } catch (InvalidHtmlTagException $e) { + } catch (InvalidHtmlTagException) { break; } @@ -370,7 +370,7 @@ public static function chipHtml(Chippable $component, array $config = []): strin '--custom-sel-bg-color' => $color?->cssVar(900), ]), 'data' => array_filter([ - 'type' => get_class($component), + 'type' => $component::class, 'id' => $component->getId(), 'settings' => $config['autoReload'] ? [ 'selectable' => $config['selectable'], @@ -924,7 +924,7 @@ private static function baseElementAttributes(ElementInterface $element, array $ ($config['context'] === 'field' && $element->hasErrors()) ? 'error' : null, ]), 'data' => array_filter([ - 'type' => get_class($element), + 'type' => $element::class, 'id' => $element->isProvisionalDraft ? $element->getCanonicalId() : $element->id, 'draft-id' => $element->isProvisionalDraft ? null : $element->draftId, 'revision-id' => $element->revisionId, @@ -2966,7 +2966,7 @@ public static function layoutElementSelectorHtml( ]), 'data' => [ 'uid' => !$forLibrary ? $element->uid : false, - 'config' => $forLibrary ? ['type' => get_class($element)] + $element->toArray() : false, + 'config' => $forLibrary ? ['type' => $element::class] + $element->toArray() : false, 'ui-label' => $forLibrary && $element instanceof CustomField ? $element->getField()->getUiLabel() : false, 'is-multi-instance' => $element->isMultiInstance(), 'has-custom-width' => $element->hasCustomWidth(), diff --git a/src/helpers/ElementHelper.php b/src/helpers/ElementHelper.php index de05cdae13a..86e8611b3dd 100644 --- a/src/helpers/ElementHelper.php +++ b/src/helpers/ElementHelper.php @@ -319,7 +319,7 @@ public static function supportedSitesForElement(ElementInterface $element, bool ]; } else { if (!isset($site['siteId'])) { - throw new Exception('Missing "siteId" key in ' . get_class($element) . '::getSupportedSites()'); + throw new Exception('Missing "siteId" key in ' . $element::class . '::getSupportedSites()'); } $site['siteId'] = (int)$site['siteId']; } diff --git a/src/helpers/FileHelper.php b/src/helpers/FileHelper.php index 85f1dacc070..d51432a6279 100644 --- a/src/helpers/FileHelper.php +++ b/src/helpers/FileHelper.php @@ -274,7 +274,7 @@ public static function sanitizeFilename(string $filename, array $options = []): // Always use the primary site language, so file paths/names are normalized // to ASCII consistently regardless of who is logged in. $language = Craft::$app->getSites()->getPrimarySite()->language; - } catch (SiteNotFoundException $e) { + } catch (SiteNotFoundException) { $language = Craft::$app->language; } @@ -579,7 +579,7 @@ public static function clearDirectory(string $dir, array $options = []): void static::removeDirectory($path, $options); } catch (UnexpectedValueException $e) { // Ignore if the folder has already been removed. - if (strpos($e->getMessage(), 'No such file or directory') === false) { + if (!str_contains($e->getMessage(), 'No such file or directory')) { Craft::warning("Tried to remove " . $path . ", but it doesn't exist."); throw $e; } diff --git a/src/helpers/MailerHelper.php b/src/helpers/MailerHelper.php index 0d9cab898a0..bcc96d881b5 100644 --- a/src/helpers/MailerHelper.php +++ b/src/helpers/MailerHelper.php @@ -144,7 +144,7 @@ public static function normalizeEmails(mixed $emails): array */ public static function settingsReport(Mailer $mailer, ?TransportAdapterInterface $transportAdapter = null): string { - $transportType = $transportAdapter ? get_class($transportAdapter) : App::mailSettings()->transportType; + $transportType = $transportAdapter ? $transportAdapter::class : App::mailSettings()->transportType; $settings = [ Craft::t('app', 'From') => self::_emailList($mailer->from), Craft::t('app', 'Reply To') => self::_emailList($mailer->replyTo), diff --git a/src/helpers/StringHelper.php b/src/helpers/StringHelper.php index f1207339cce..7bc3454553c 100644 --- a/src/helpers/StringHelper.php +++ b/src/helpers/StringHelper.php @@ -413,11 +413,11 @@ public static function dasherize(string $str): string */ public static function decdec(string $str): string { - if (strncmp($str, 'base64:', 7) === 0) { + if (str_starts_with($str, 'base64:')) { $str = base64_decode(substr($str, 7)); } - if (strncmp($str, 'crypt:', 6) === 0) { + if (str_starts_with($str, 'crypt:')) { $str = Craft::$app->getSecurity()->decryptByKey(substr($str, 6)); } diff --git a/src/helpers/Template.php b/src/helpers/Template.php index 8f3151d9e8f..301856643bc 100644 --- a/src/helpers/Template.php +++ b/src/helpers/Template.php @@ -139,7 +139,7 @@ public static function attribute( // Convert any \Twig\Markup arguments back to strings (unless the class *extends* \Twig\Markup) foreach ($arguments as $key => $value) { - if (is_object($value) && get_class($value) === Markup::class) { + if (is_object($value) && $value::class === Markup::class) { $arguments[$key] = (string)$value; } } diff --git a/src/i18n/Formatter.php b/src/i18n/Formatter.php index a4affc8aa2b..87182cd5c14 100644 --- a/src/i18n/Formatter.php +++ b/src/i18n/Formatter.php @@ -80,7 +80,7 @@ public function asDate($value, $format = null): string $format = $this->dateTimeFormats[$format]['date']; } - if (strncmp($format, 'php:', 4) === 0) { + if (str_starts_with($format, 'php:')) { return $this->_formatDateTimeValueWithPhpFormat($value, substr($format, 4), 'date'); } @@ -105,7 +105,7 @@ public function asTime($value, $format = null): string $format = $this->dateTimeFormats[$format]['time']; } - if (strncmp($format, 'php:', 4) === 0) { + if (str_starts_with($format, 'php:')) { return $this->_formatDateTimeValueWithPhpFormat($value, substr($format, 4), 'time'); } @@ -130,7 +130,7 @@ public function asDatetime($value, $format = null): string $format = $this->dateTimeFormats[$format]['datetime']; } - if (strncmp($format, 'php:', 4) === 0) { + if (str_starts_with($format, 'php:')) { return $this->_formatDateTimeValueWithPhpFormat($value, substr($format, 4), 'datetime'); } diff --git a/src/i18n/Locale.php b/src/i18n/Locale.php index e9f57c6b393..9eb2ce14cc6 100644 --- a/src/i18n/Locale.php +++ b/src/i18n/Locale.php @@ -11,6 +11,7 @@ use DateTime; use IntlDateFormatter; use NumberFormatter; +use Stringable; use yii\base\BaseObject; use yii\base\Exception; use yii\base\InvalidArgumentException; @@ -22,7 +23,7 @@ * @author Pixel & Tonic, Inc. * @since 3.0.0 */ -class Locale extends BaseObject +class Locale extends BaseObject implements Stringable { /** * @var int Positive prefix. diff --git a/src/migrations/BaseContentRefactorMigration.php b/src/migrations/BaseContentRefactorMigration.php index 5f2907a162c..8ce35b16666 100644 --- a/src/migrations/BaseContentRefactorMigration.php +++ b/src/migrations/BaseContentRefactorMigration.php @@ -309,27 +309,12 @@ private function decodeValue(mixed $value, string|array|null $dbType, ColumnSche return ['date' => $value]; } } - - switch ($dbType) { - case Schema::TYPE_TINYINT: - case Schema::TYPE_SMALLINT: - case Schema::TYPE_INTEGER: - case Schema::TYPE_BIGINT: - return (int)$value; - - case Schema::TYPE_FLOAT: - case Schema::TYPE_DOUBLE: - case Schema::TYPE_DECIMAL: - case Schema::TYPE_MONEY: - return (float)$value; - - case Schema::TYPE_BOOLEAN: - return (bool)$value; - - case Schema::TYPE_JSON: - return Json::decodeIfJson($value); - } - - return $value; + return match ($dbType) { + Schema::TYPE_TINYINT, Schema::TYPE_SMALLINT, Schema::TYPE_INTEGER, Schema::TYPE_BIGINT => (int)$value, + Schema::TYPE_FLOAT, Schema::TYPE_DOUBLE, Schema::TYPE_DECIMAL, Schema::TYPE_MONEY => (float)$value, + Schema::TYPE_BOOLEAN => (bool)$value, + Schema::TYPE_JSON => Json::decodeIfJson($value), + default => $value, + }; } } diff --git a/src/models/AssetIndexData.php b/src/models/AssetIndexData.php index 146cfb280f7..a147eb948a7 100644 --- a/src/models/AssetIndexData.php +++ b/src/models/AssetIndexData.php @@ -9,6 +9,7 @@ use craft\base\Model; use DateTime; +use Stringable; /** * AssetIndexData model class. @@ -16,7 +17,7 @@ * @author Pixel & Tonic, Inc. * @since 3.0.0 */ -class AssetIndexData extends Model +class AssetIndexData extends Model implements Stringable { /** * @var int|null ID diff --git a/src/models/CategoryGroup.php b/src/models/CategoryGroup.php index 81c65f96883..53a956e1de6 100644 --- a/src/models/CategoryGroup.php +++ b/src/models/CategoryGroup.php @@ -23,6 +23,7 @@ use craft\validators\HandleValidator; use craft\validators\UniqueValidator; use DateTime; +use Stringable; /** * CategoryGroup model. @@ -35,7 +36,8 @@ class CategoryGroup extends Model implements Chippable, CpEditable, - FieldLayoutProviderInterface + FieldLayoutProviderInterface, + Stringable { /** @since 3.7.0 */ public const DEFAULT_PLACEMENT_BEGINNING = 'beginning'; diff --git a/src/models/EntryType.php b/src/models/EntryType.php index 7c32a6b5c01..199fa8d29b3 100644 --- a/src/models/EntryType.php +++ b/src/models/EntryType.php @@ -27,6 +27,7 @@ use craft\records\EntryType as EntryTypeRecord; use craft\validators\HandleValidator; use craft\validators\UniqueValidator; +use Stringable; /** * EntryType model class. @@ -43,7 +44,8 @@ class EntryType extends Model implements Iconic, Indicative, Colorable, - Actionable + Actionable, + Stringable { /** * @inheritdoc diff --git a/src/models/FieldLayoutTab.php b/src/models/FieldLayoutTab.php index 3ce2fdbf257..9867ce68cc1 100644 --- a/src/models/FieldLayoutTab.php +++ b/src/models/FieldLayoutTab.php @@ -215,7 +215,7 @@ public function getElementConfigs(): array if (!isset($layoutElement->uid)) { $layoutElement->uid = StringHelper::UUID(); } - $elementConfig = ['type' => get_class($layoutElement)] + $layoutElement->toArray(); + $elementConfig = ['type' => $layoutElement::class] + $layoutElement->toArray(); if (!isset($elementConfig['dateAdded'])) { // Default `dateAdded` to a minute ago, so there’s no chance that an element that predated 5.3 would get // the same timestamp as a newly-added element, if the layout was saved within a minute of being edited, diff --git a/src/models/GqlSchema.php b/src/models/GqlSchema.php index 865ddd842a2..b42d0a67a27 100644 --- a/src/models/GqlSchema.php +++ b/src/models/GqlSchema.php @@ -11,6 +11,7 @@ use craft\helpers\StringHelper; use craft\records\GqlSchema as GqlSchemaRecord; use craft\validators\UniqueValidator; +use Stringable; /** * GraphQL schema class @@ -18,7 +19,7 @@ * @author Pixel & Tonic, Inc. * @since 3.3.0 */ -class GqlSchema extends Model +class GqlSchema extends Model implements Stringable { /** * @var int|null ID @@ -74,7 +75,7 @@ protected function defineRules(): array */ public function __toString(): string { - return $this->name; + return (string) $this->name; } /** diff --git a/src/models/GqlToken.php b/src/models/GqlToken.php index c67d20acb22..e310f19359f 100644 --- a/src/models/GqlToken.php +++ b/src/models/GqlToken.php @@ -13,6 +13,7 @@ use craft\records\GqlToken as GqlSchemaRecord; use craft\validators\UniqueValidator; use DateTime; +use Stringable; /** * GraphQL token class @@ -21,7 +22,7 @@ * @author Pixel & Tonic, Inc. * @since 3.4.0 */ -class GqlToken extends Model +class GqlToken extends Model implements Stringable { /** * The public access token value. @@ -126,7 +127,7 @@ protected function defineRules(): array */ public function __toString(): string { - return $this->name; + return (string) $this->name; } /** diff --git a/src/models/ImageTransform.php b/src/models/ImageTransform.php index 15ef718faca..7b9f890bca9 100644 --- a/src/models/ImageTransform.php +++ b/src/models/ImageTransform.php @@ -17,6 +17,7 @@ use craft\validators\HandleValidator; use craft\validators\UniqueValidator; use DateTime; +use Stringable; /** * The ImageTransform model class. @@ -25,7 +26,7 @@ * @author Pixel & Tonic, Inc. * @since 4.0.0 */ -class ImageTransform extends Model +class ImageTransform extends Model implements Stringable { /** * @var string The default image transformer diff --git a/src/models/ImageTransformIndex.php b/src/models/ImageTransformIndex.php index 46891be8100..4df47255f9b 100644 --- a/src/models/ImageTransformIndex.php +++ b/src/models/ImageTransformIndex.php @@ -13,6 +13,7 @@ use craft\helpers\ImageTransforms; use craft\validators\DateTimeValidator; use DateTime; +use Stringable; use yii\base\InvalidConfigException; /** @@ -22,7 +23,7 @@ * @author Pixel & Tonic, Inc. * @since 4.0.0 */ -class ImageTransformIndex extends Model +class ImageTransformIndex extends Model implements Stringable { /** * @var int|null ID diff --git a/src/models/ReadOnlyProjectConfigData.php b/src/models/ReadOnlyProjectConfigData.php index 83744acb582..fcfdc66277c 100644 --- a/src/models/ReadOnlyProjectConfigData.php +++ b/src/models/ReadOnlyProjectConfigData.php @@ -20,14 +20,11 @@ */ class ReadOnlyProjectConfigData extends Model { - protected array $data; - /** @since 4.4.17 */ protected ProjectConfig $projectConfig; - public function __construct(array $data = [], ?ProjectConfig $projectConfig = null, array $config = []) + public function __construct(protected array $data = [], ?ProjectConfig $projectConfig = null, array $config = []) { - $this->data = $data; $this->projectConfig = $projectConfig ?? Craft::$app->getProjectConfig(); parent::__construct($config); diff --git a/src/models/Section.php b/src/models/Section.php index 558b0b7b159..a8f99163454 100644 --- a/src/models/Section.php +++ b/src/models/Section.php @@ -24,6 +24,7 @@ use craft\records\Section as SectionRecord; use craft\validators\HandleValidator; use craft\validators\UniqueValidator; +use Stringable; /** * Section model class. @@ -34,7 +35,7 @@ * @property EntryType[] $entryTypes Entry types * @property bool $hasMultiSiteEntries Whether entries in this section support multiple sites */ -class Section extends Model implements Chippable, CpEditable, Iconic +class Section extends Model implements Chippable, CpEditable, Iconic, Stringable { public const TYPE_SINGLE = 'single'; public const TYPE_CHANNEL = 'channel'; diff --git a/src/models/Site.php b/src/models/Site.php index 4e60f4f1968..4316ce3dd90 100644 --- a/src/models/Site.php +++ b/src/models/Site.php @@ -18,6 +18,7 @@ use craft\validators\UniqueValidator; use craft\validators\UrlValidator; use DateTime; +use Stringable; use yii\base\InvalidConfigException; /** @@ -30,7 +31,7 @@ * @author Pixel & Tonic, Inc. * @since 3.0.0 */ -class Site extends Model implements Chippable +class Site extends Model implements Chippable, Stringable { public static function get(int|string $id): ?static { diff --git a/src/models/SiteGroup.php b/src/models/SiteGroup.php index 5d63df812b2..ffdd9329932 100644 --- a/src/models/SiteGroup.php +++ b/src/models/SiteGroup.php @@ -12,6 +12,7 @@ use craft\helpers\App; use craft\records\SiteGroup as SiteGroupRecord; use craft\validators\UniqueValidator; +use Stringable; /** * SiteGroup model class. @@ -20,7 +21,7 @@ * @author Pixel & Tonic, Inc. * @since 3.0.0 */ -class SiteGroup extends Model +class SiteGroup extends Model implements Stringable { /** * @var int|null ID diff --git a/src/models/TagGroup.php b/src/models/TagGroup.php index 23d1eee4b20..3ba51bc8db6 100644 --- a/src/models/TagGroup.php +++ b/src/models/TagGroup.php @@ -16,6 +16,7 @@ use craft\validators\HandleValidator; use craft\validators\UniqueValidator; use DateTime; +use Stringable; /** * TagGroup model. @@ -24,7 +25,7 @@ * @author Pixel & Tonic, Inc. * @since 3.0.0 */ -class TagGroup extends Model implements FieldLayoutProviderInterface +class TagGroup extends Model implements FieldLayoutProviderInterface, Stringable { /** * @var int|null ID diff --git a/src/models/UserGroup.php b/src/models/UserGroup.php index 2cca1fb27fd..3303e075798 100644 --- a/src/models/UserGroup.php +++ b/src/models/UserGroup.php @@ -12,6 +12,7 @@ use craft\records\UserGroup as UserGroupRecord; use craft\validators\HandleValidator; use craft\validators\UniqueValidator; +use Stringable; /** * UserGroup model class. @@ -19,7 +20,7 @@ * @author Pixel & Tonic, Inc. * @since 3.0.0 */ -class UserGroup extends Model +class UserGroup extends Model implements Stringable { /** * @var int|null ID diff --git a/src/models/VolumeFolder.php b/src/models/VolumeFolder.php index 6e6cb263cb8..e18804b4aaf 100644 --- a/src/models/VolumeFolder.php +++ b/src/models/VolumeFolder.php @@ -11,6 +11,7 @@ use craft\base\FsInterface; use craft\base\Model; use craft\helpers\Html; +use Stringable; use yii\base\InvalidConfigException; /** @@ -22,7 +23,7 @@ * @author Pixel & Tonic, Inc. * @since 3.0.0 */ -class VolumeFolder extends Model +class VolumeFolder extends Model implements Stringable { /** * @var int|null ID diff --git a/src/queue/jobs/ApplyNewPropagationMethod.php b/src/queue/jobs/ApplyNewPropagationMethod.php index d24b10dbae2..99767e88811 100644 --- a/src/queue/jobs/ApplyNewPropagationMethod.php +++ b/src/queue/jobs/ApplyNewPropagationMethod.php @@ -131,7 +131,7 @@ protected function processItem(mixed $item): void // Just log it and move along Craft::warning(sprintf( "Unable to duplicate “%s” to site %d: %s", - get_class($otherSiteElement), + $otherSiteElement::class, $otherSiteElement->siteId, $e->getMessage() )); diff --git a/src/queue/jobs/PropagateElements.php b/src/queue/jobs/PropagateElements.php index ef52d544fd6..37debf4390e 100644 --- a/src/queue/jobs/PropagateElements.php +++ b/src/queue/jobs/PropagateElements.php @@ -88,7 +88,7 @@ protected function processItem(mixed $item): void foreach ($elementSiteIds as $siteId) { if ($siteId !== $item->siteId) { // Make sure the site element wasn't updated more recently than the main one - $siteElement = $elementsService->getElementById($item->id, get_class($item), $siteId); + $siteElement = $elementsService->getElementById($item->id, $item::class, $siteId); if ($siteElement === null || $siteElement->dateUpdated < $item->dateUpdated) { $elementsService->propagateElement($item, $siteId, $siteElement ?? false); } diff --git a/src/search/SearchQueryTermGroup.php b/src/search/SearchQueryTermGroup.php index 9af28c0f566..c1e0933332a 100644 --- a/src/search/SearchQueryTermGroup.php +++ b/src/search/SearchQueryTermGroup.php @@ -16,18 +16,12 @@ */ class SearchQueryTermGroup { - /** - * @var SearchQueryTerm[] - */ - public array $terms; - /** * Constructor * * @param SearchQueryTerm[] $terms */ - public function __construct(array $terms = []) + public function __construct(public array $terms = []) { - $this->terms = $terms; } } diff --git a/src/services/Auth.php b/src/services/Auth.php index a84a52e8e87..45c6193fae1 100644 --- a/src/services/Auth.php +++ b/src/services/Auth.php @@ -338,7 +338,7 @@ public function getActiveMethods(?User $user = null): array public function getMethod(string $class, ?User $user = null): AuthMethodInterface { foreach ($this->getAllMethods($user) as $method) { - if (get_class($method) === $class) { + if ($method::class === $class) { return $method; } } diff --git a/src/services/Dashboard.php b/src/services/Dashboard.php index 351295a4d3b..27340fd2ec4 100644 --- a/src/services/Dashboard.php +++ b/src/services/Dashboard.php @@ -221,7 +221,7 @@ public function saveWidget(WidgetInterface $widget, bool $runValidation = true): try { $widgetRecord = $this->_getUserWidgetRecordById($widget->id); - $widgetRecord->type = get_class($widget); + $widgetRecord->type = $widget::class; $widgetRecord->settings = $widget->getSettings(); if ($isNewWidget) { diff --git a/src/services/Deprecator.php b/src/services/Deprecator.php index a0ef1df1ea0..5ae7fbf3991 100644 --- a/src/services/Deprecator.php +++ b/src/services/Deprecator.php @@ -384,7 +384,7 @@ private function _processStackTrace(array $traces): array } $logTraces[] = [ - 'objectClass' => !empty($trace['object']) ? get_class($trace['object']) : null, + 'objectClass' => !empty($trace['object']) ? $trace['object']::class : null, 'file' => $file, 'line' => $line, 'class' => !empty($trace['class']) ? $trace['class'] : null, @@ -442,7 +442,7 @@ private function _argsToString(array $args): string } if (is_object($value)) { - $strValue = get_class($value); + $strValue = $value::class; } elseif (is_bool($value)) { $strValue = $value ? 'true' : 'false'; } elseif (is_string($value)) { diff --git a/src/services/Elements.php b/src/services/Elements.php index abeada17014..d51e9082f17 100644 --- a/src/services/Elements.php +++ b/src/services/Elements.php @@ -697,7 +697,7 @@ public function collectCacheInfoForElement(ElementInterface $element): void return; } - $class = get_class($element); + $class = $element::class; $this->collectCacheTags([ 'element', "element::$class", @@ -1350,7 +1350,7 @@ public function mergeCanonicalChanges(ElementInterface $element): void } if (!$element::trackChanges()) { - throw new InvalidArgumentException(get_class($element) . ' elements don’t track their changes'); + throw new InvalidArgumentException($element::class . ' elements don’t track their changes'); } // Make sure the derivative element actually supports its own site ID @@ -1676,7 +1676,7 @@ public function propagateElements(ElementQueryInterface $query, array|int $siteI $supportedSites = ArrayHelper::index(ElementHelper::supportedSitesForElement($element), 'siteId'); $supportedSiteIds = array_keys($supportedSites); $elementSiteIds = $siteIds !== null ? array_intersect($siteIds, $supportedSiteIds) : $supportedSiteIds; - $elementType = get_class($element); + $elementType = $element::class; $e = null; try { @@ -2033,7 +2033,7 @@ public function updateElementSlugAndUri(ElementInterface $element, bool $updateO if ($queue) { Queue::push(new UpdateElementSlugsAndUris([ 'elementId' => $element->id, - 'elementType' => get_class($element), + 'elementType' => $element::class, 'siteId' => $element->siteId, 'updateOtherSites' => $updateOtherSites, 'updateDescendants' => $updateDescendants, @@ -2111,7 +2111,7 @@ public function updateElementSlugAndUriInOtherSites(ElementInterface $element): */ public function updateDescendantSlugsAndUris(ElementInterface $element, bool $updateOtherSites = true, bool $queue = false): void { - $query = $this->createElementQuery(get_class($element)) + $query = $this->createElementQuery($element::class) ->descendantOf($element) ->descendantDist(1) ->status(null) @@ -2123,7 +2123,7 @@ public function updateDescendantSlugsAndUris(ElementInterface $element, bool $up if (!empty($childIds)) { Queue::push(new UpdateElementSlugsAndUris([ 'elementId' => $childIds, - 'elementType' => get_class($element), + 'elementType' => $element::class, 'siteId' => $element->siteId, 'updateOtherSites' => $updateOtherSites, 'updateDescendants' => true, @@ -2443,10 +2443,10 @@ public function deleteElementsForSite(array $elements): void // Make sure each element has the same type and site ID $firstElement = reset($elements); - $elementType = get_class($firstElement); + $elementType = $firstElement::class; foreach ($elements as $element) { - if (get_class($element) !== $elementType || $element->siteId !== $firstElement->siteId) { + if ($element::class !== $elementType || $element->siteId !== $firstElement->siteId) { throw new InvalidArgumentException('All elements must have the same type and site ID.'); } } @@ -3627,7 +3627,7 @@ private function _saveElementInternal( } } else { $elementRecord = new ElementRecord(); - $elementRecord->type = get_class($element); + $elementRecord->type = $element::class; } // Set the attributes @@ -3950,7 +3950,7 @@ private function updateSearchIndex( Craft::$app->getSearch()->indexElementAttributes($element, $searchableDirtyFields); } else { Queue::push(new UpdateSearchIndex([ - 'elementType' => get_class($element), + 'elementType' => $element::class, 'elementId' => $element->id, 'siteId' => $element->siteId, 'fieldHandles' => $searchableDirtyFields, @@ -4008,7 +4008,7 @@ private function _propagateElement( // Try to fetch the element in this site if ($siteElement === null && $element->id) { - $siteElement = $this->getElementById($element->id, get_class($element), $siteInfo['siteId']); + $siteElement = $this->getElementById($element->id, $element::class, $siteInfo['siteId']); } elseif (!$siteElement) { $siteElement = null; } @@ -4257,7 +4257,7 @@ private function _getRefTokenReplacement(?ElementInterface $element, ?string $at $value = $element->$attribute; if (is_object($value) && !method_exists($value, '__toString')) { - throw new Exception('Object of class ' . get_class($value) . ' could not be converted to string'); + throw new Exception('Object of class ' . $value::class . ' could not be converted to string'); } return $this->parseRefs((string)$value); diff --git a/src/services/Fields.php b/src/services/Fields.php index bfbc4a2c083..42913c19ce2 100644 --- a/src/services/Fields.php +++ b/src/services/Fields.php @@ -303,8 +303,8 @@ public function getCompatibleFieldTypes(FieldInterface $field, bool $includeCurr // Make sure the current field class is in there if it's supposed to be /** @var FieldInterface $field */ - if ($includeCurrent && !in_array(get_class($field), $types, true)) { - $types[] = get_class($field); + if ($includeCurrent && !in_array($field::class, $types, true)) { + $types[] = $field::class; } // Fire a 'defineCompatibleFieldTypes' event @@ -587,7 +587,7 @@ public function createFieldConfig(FieldInterface $field): array 'searchable' => $field->searchable, 'translationMethod' => $field->translationMethod, 'translationKeyFormat' => $field->translationKeyFormat, - 'type' => get_class($field), + 'type' => $field::class, 'settings' => ProjectConfigHelper::packAssociativeArrays($field->getSettings()), ]; } diff --git a/src/services/Fs.php b/src/services/Fs.php index a9e92beccb1..e1645390208 100644 --- a/src/services/Fs.php +++ b/src/services/Fs.php @@ -72,7 +72,7 @@ public function createFilesystemConfig(FsInterface $fs): array { $config = [ 'name' => $fs->name, - 'type' => get_class($fs), + 'type' => $fs::class, 'settings' => ProjectConfigHelper::packAssociativeArrays($fs->getSettings()), ]; diff --git a/src/services/ProjectConfig.php b/src/services/ProjectConfig.php index c4ed8a9885a..43cec4a92ab 100644 --- a/src/services/ProjectConfig.php +++ b/src/services/ProjectConfig.php @@ -1645,7 +1645,7 @@ public function writeYamlFiles(bool $force = false): void FileHelper::clearDirectory($basePath, [ 'except' => ['.*', '.*/'], ]); - } catch (Throwable $e) { + } catch (Throwable) { // oh well } } diff --git a/src/services/Revisions.php b/src/services/Revisions.php index 2fc64202225..2bf4f6d8152 100644 --- a/src/services/Revisions.php +++ b/src/services/Revisions.php @@ -199,7 +199,7 @@ public function createRevision( // Prune any excess revisions if (Craft::$app->getConfig()->getGeneral()->maxRevisions) { Queue::push(new PruneRevisions([ - 'elementType' => get_class($canonical), + 'elementType' => $canonical::class, 'canonicalId' => $canonical->id, 'siteId' => $canonical->siteId, ]), 2049); diff --git a/src/test/Craft.php b/src/test/Craft.php index b287738b424..b4e857ac444 100644 --- a/src/test/Craft.php +++ b/src/test/Craft.php @@ -497,7 +497,7 @@ public function mockMethods(Module $module, string $component, array $params = [ { $componentInstance = $module->get($component); - $module->set($component, Stub::construct(get_class($componentInstance), $constructorParams, $params)); + $module->set($component, Stub::construct($componentInstance::class, $constructorParams, $params)); } /** diff --git a/src/test/CraftConnector.php b/src/test/CraftConnector.php index fa70537836c..64434ecb738 100644 --- a/src/test/CraftConnector.php +++ b/src/test/CraftConnector.php @@ -91,7 +91,7 @@ protected function resetRequest(Application $app): void /** @var Module $module */ foreach (Craft::$app->getModules(true) as $module) { - $moduleClass = get_class($module); + $moduleClass = $module::class; $moduleId = $module->id; if ($module instanceof PluginInterface) { diff --git a/src/test/TestCase.php b/src/test/TestCase.php index 7cb8cea6169..bb3731967fd 100644 --- a/src/test/TestCase.php +++ b/src/test/TestCase.php @@ -41,7 +41,7 @@ public function _fixtures(): array public function assertObjectIsInstanceOfClassCallback(string $class): callable { return function($object) use ($class) { - $this->assertSame($class, get_class($object)); + $this->assertSame($class, $object::class); }; } diff --git a/src/test/console/CommandTest.php b/src/test/console/CommandTest.php index 2e9d9691eaf..7a39c821c94 100644 --- a/src/test/console/CommandTest.php +++ b/src/test/console/CommandTest.php @@ -34,16 +34,6 @@ class CommandTest */ protected ConsoleTest $test; - /** - * @var string - */ - protected string $command; - - /** - * @var array - */ - protected array $parameters; - /** * @var bool */ @@ -98,10 +88,8 @@ class CommandTest * @param bool $ignoreStdOut * @throws InvalidConfigException */ - public function __construct(ConsoleTest $consoleTest, string $command, array $parameters = [], bool $ignoreStdOut = false) + public function __construct(ConsoleTest $consoleTest, protected string $command, protected array $parameters = [], bool $ignoreStdOut = false) { - $this->command = $command; - $this->parameters = $parameters; $this->ignoreStdout = $ignoreStdOut; $this->test = $consoleTest; $this->setupController(); @@ -236,7 +224,7 @@ protected function setupController(): void $actionId = $controllerArray[1]; - $stubController = Stub::construct(get_class($controller), [$controller->id, Craft::$app], [ + $stubController = Stub::construct($controller::class, [$controller->id, Craft::$app], [ 'stdOut' => $this->stdoutHandler(), 'stderr' => $this->stderrHandler(), 'prompt' => $this->promptHandler(), diff --git a/src/test/mockclasses/ToString.php b/src/test/mockclasses/ToString.php index a6db48c3c8f..7c7cb524939 100644 --- a/src/test/mockclasses/ToString.php +++ b/src/test/mockclasses/ToString.php @@ -7,6 +7,8 @@ namespace craft\test\mockclasses; +use Stringable; + /** * Class ToString. * @@ -14,7 +16,7 @@ * @author Global Network Group | Giel Tettelaar * @since 3.2 */ -class ToString +class ToString implements Stringable { /** * @var string diff --git a/src/utilities/SystemReport.php b/src/utilities/SystemReport.php index 3589cadd5d1..bd21f840db7 100644 --- a/src/utilities/SystemReport.php +++ b/src/utilities/SystemReport.php @@ -61,7 +61,7 @@ public static function contentHtml(): string continue; } if ($module instanceof Module) { - $modules[$id] = get_class($module); + $modules[$id] = $module::class; } elseif (is_string($module)) { $modules[$id] = $module; } elseif (is_array($module) && isset($module['class'])) { diff --git a/src/validators/UrlValidator.php b/src/validators/UrlValidator.php index 464a8226680..942ee80afd2 100644 --- a/src/validators/UrlValidator.php +++ b/src/validators/UrlValidator.php @@ -53,7 +53,7 @@ public function __construct(array $config = []) */ public function validateValue($value): ?array { - if ($this->allowAlias && strncmp($value, '@', 1) === 0) { + if ($this->allowAlias && str_starts_with($value, '@')) { $value = Craft::getAlias($value); // Prevent validateAttribute() from prepending a default scheme if the alias is missing one diff --git a/src/web/Controller.php b/src/web/Controller.php index 5b90c3f84f5..f735caa5273 100644 --- a/src/web/Controller.php +++ b/src/web/Controller.php @@ -426,7 +426,7 @@ public function asModelSuccess( ): YiiResponse { $data += array_filter([ 'modelName' => $modelName, - 'modelClass' => get_class($model), + 'modelClass' => $model::class, ($modelName ?? 'model') => $model->toArray(), ]); diff --git a/src/web/ErrorHandler.php b/src/web/ErrorHandler.php index 2684f42c618..7b6b6da396b 100644 --- a/src/web/ErrorHandler.php +++ b/src/web/ErrorHandler.php @@ -236,7 +236,7 @@ protected function renderException($exception): void public function exceptionAsArray(Throwable $e) { $array = [ - 'exception' => get_class($e), + 'exception' => $e::class, 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), diff --git a/src/web/Request.php b/src/web/Request.php index 8371304308b..b705edb4275 100644 --- a/src/web/Request.php +++ b/src/web/Request.php @@ -579,7 +579,7 @@ public function hasValidSiteToken(): bool { try { return $this->_validateSiteToken() !== null; - } catch (BadRequestHttpException $e) { + } catch (BadRequestHttpException) { return false; } } diff --git a/src/web/UrlManager.php b/src/web/UrlManager.php index 225c7b7ac1b..546b8fff43f 100644 --- a/src/web/UrlManager.php +++ b/src/web/UrlManager.php @@ -444,7 +444,7 @@ private function _getMatchedUrlRoute(Request $request): array|false if (App::devMode()) { Craft::debug([ - 'rule' => 'URL Rule: ' . (method_exists($rule, '__toString') ? $rule->__toString() : get_class($rule)), + 'rule' => 'URL Rule: ' . (method_exists($rule, '__toString') ? $rule->__toString() : $rule::class), 'match' => $route !== false, 'parent' => null, ], __METHOD__); diff --git a/src/web/UrlRule.php b/src/web/UrlRule.php index 648a91a3659..17abdda69c9 100644 --- a/src/web/UrlRule.php +++ b/src/web/UrlRule.php @@ -36,7 +36,7 @@ public static function regexTokens(): array return [ '{handle}' => sprintf('(?:%s)', HandleValidator::$handlePattern), // Reference: http://www.regular-expressions.info/unicode.html - '{slug}' => sprintf('(?:[\p{L}\p{N}\p{M}%s]+)', preg_quote(implode($slugChars), '/')), + '{slug}' => sprintf('(?:[\p{L}\p{N}\p{M}%s]+)', preg_quote(implode('', $slugChars), '/')), '{uid}' => sprintf('(?:%s)', StringHelper::UUID_PATTERN), ]; } diff --git a/src/web/View.php b/src/web/View.php index 7c0b9d7437a..ec6999942d1 100644 --- a/src/web/View.php +++ b/src/web/View.php @@ -490,7 +490,7 @@ public function registerTwigExtension(ExtensionInterface $extension): void public function registerCpTwigExtension(ExtensionInterface $extension): void { // Make sure this extension isn't already registered - $class = get_class($extension); + $class = $extension::class; if (isset($this->_cpTwigExtensions[$class])) { return; } @@ -515,7 +515,7 @@ public function registerCpTwigExtension(ExtensionInterface $extension): void public function registerSiteTwigExtension(ExtensionInterface $extension): void { // Make sure this extension isn't already registered - $class = get_class($extension); + $class = $extension::class; if (isset($this->_siteTwigExtensions[$class])) { return; } diff --git a/src/web/twig/Extension.php b/src/web/twig/Extension.php index 0fc8f01acc3..bb59cfdda6f 100644 --- a/src/web/twig/Extension.php +++ b/src/web/twig/Extension.php @@ -129,26 +129,14 @@ private static function checkArrowFunction(mixed $arrow, string $thing, string $ } } - /** - * @var View|null - */ - protected ?View $view = null; - - /** - * @var TwigEnvironment|null - */ - protected ?TwigEnvironment $environment = null; - /** * Constructor * * @param View $view * @param TwigEnvironment $environment */ - public function __construct(View $view, TwigEnvironment $environment) + public function __construct(protected ?View $view, protected ?TwigEnvironment $environment) { - $this->view = $view; - $this->environment = $environment; } /** diff --git a/src/web/twig/TemplateLoader.php b/src/web/twig/TemplateLoader.php index 36a179be54c..062c9978aa8 100644 --- a/src/web/twig/TemplateLoader.php +++ b/src/web/twig/TemplateLoader.php @@ -20,19 +20,13 @@ */ class TemplateLoader implements LoaderInterface { - /** - * @var View|null - */ - protected ?View $view = null; - /** * Constructor * * @param View $view */ - public function __construct(View $view) + public function __construct(protected ?View $view) { - $this->view = $view; } /** diff --git a/src/web/twig/TemplateLoaderException.php b/src/web/twig/TemplateLoaderException.php index 45f18e3df2a..2179aca933b 100644 --- a/src/web/twig/TemplateLoaderException.php +++ b/src/web/twig/TemplateLoaderException.php @@ -17,18 +17,12 @@ */ class TemplateLoaderException extends LoaderError { - /** - * @var string|null - */ - public ?string $template = null; - /** * @param string $template The requested template * @param string $message The exception message */ - public function __construct(string $template, string $message) + public function __construct(public ?string $template, string $message) { - $this->template = $template; parent::__construct($message); } } diff --git a/src/web/twig/nodevisitors/GetAttrAdjuster.php b/src/web/twig/nodevisitors/GetAttrAdjuster.php index 412f260b2e8..717819e838f 100644 --- a/src/web/twig/nodevisitors/GetAttrAdjuster.php +++ b/src/web/twig/nodevisitors/GetAttrAdjuster.php @@ -27,7 +27,7 @@ class GetAttrAdjuster implements NodeVisitorInterface public function enterNode(Node $node, Environment $env): Node { // Make sure this is a GetAttrExpression (and not a subclass) - if (get_class($node) !== GetAttrExpression::class) { + if ($node::class !== GetAttrExpression::class) { return $node; } diff --git a/src/web/twig/tokenparsers/RegisterResourceTokenParser.php b/src/web/twig/tokenparsers/RegisterResourceTokenParser.php index 1e7e397466b..85b5a90a20f 100644 --- a/src/web/twig/tokenparsers/RegisterResourceTokenParser.php +++ b/src/web/twig/tokenparsers/RegisterResourceTokenParser.php @@ -21,16 +21,6 @@ */ class RegisterResourceTokenParser extends AbstractTokenParser { - /** - * @var string The tag name - */ - public string $tag; - - /** - * @var string The View method the tag represents - */ - public string $method; - /** * @var bool Whether the tag supports a tag pair mode for capturing the JS/CSS */ @@ -62,11 +52,8 @@ class RegisterResourceTokenParser extends AbstractTokenParser * @param string $method the View method the tag represents * @param array $config name-value pairs that will be used to initialize the object properties */ - public function __construct(string $tag, string $method, array $config = []) + public function __construct(public string $tag, public string $method, array $config = []) { - $this->tag = $tag; - $this->method = $method; - if (!empty($config)) { Craft::configure($this, $config); } diff --git a/src/web/twig/variables/Image.php b/src/web/twig/variables/Image.php index 4b2737ad5be..ed0b17bdc06 100644 --- a/src/web/twig/variables/Image.php +++ b/src/web/twig/variables/Image.php @@ -19,16 +19,6 @@ */ class Image { - /** - * @var string|null - */ - protected ?string $path = null; - - /** - * @var string|null - */ - protected ?string $url = null; - /** * @var array|null */ @@ -40,10 +30,8 @@ class Image * @param string $path * @param string $url */ - public function __construct(string $path, string $url = '') + public function __construct(protected ?string $path, protected ?string $url = '') { - $this->path = $path; - $this->url = $url; } /** diff --git a/tests/unit/elements/ElementCollectionTest.php b/tests/unit/elements/ElementCollectionTest.php index 58cf76ad9fb..1f4d04c8623 100644 --- a/tests/unit/elements/ElementCollectionTest.php +++ b/tests/unit/elements/ElementCollectionTest.php @@ -187,12 +187,12 @@ public function testBaseMethods(): void { $collection = Entry::find()->collect(); self::assertInstanceOf(ElementCollection::class, $collection); - self::assertSame(Collection::class, get_class($collection->countBy(fn(Entry $entry) => $entry->sectionId))); - self::assertSame(Collection::class, get_class($collection->collapse())); - self::assertSame(Collection::class, get_class($collection->flatten(1))); - self::assertSame(Collection::class, get_class($collection->keys())); - self::assertSame(Collection::class, get_class($collection->pad(100, null))); - self::assertSame(Collection::class, get_class($collection->pluck('title'))); - self::assertSame(Collection::class, get_class($collection->zip($collection->ids()))); + self::assertSame(Collection::class, $collection->countBy(fn(Entry $entry) => $entry->sectionId)::class); + self::assertSame(Collection::class, $collection->collapse()::class); + self::assertSame(Collection::class, $collection->flatten(1)::class); + self::assertSame(Collection::class, $collection->keys()::class); + self::assertSame(Collection::class, $collection->pad(100, null)::class); + self::assertSame(Collection::class, $collection->pluck('title')::class); + self::assertSame(Collection::class, $collection->zip($collection->ids())::class); } }