From 18c9a98b408124fc18a29d54560a7d5cbe9f612f Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Tue, 19 Nov 2024 12:03:12 -0800 Subject: [PATCH 1/5] PhpStorm has basic support for class-string now --- src/Craft.php | 5 +- src/base/ElementAction.php | 3 +- src/base/ElementActionInterface.php | 3 +- src/base/ElementExporter.php | 3 +- src/base/ElementExporterInterface.php | 3 +- src/base/FieldLayoutComponent.php | 14 ++--- src/base/MissingComponentTrait.php | 6 +- .../BaseElementSelectConditionRule.php | 7 +-- src/behaviors/FieldLayoutBehavior.php | 3 +- src/behaviors/SessionBehavior.php | 3 +- src/console/controllers/ResaveController.php | 5 +- .../controllers/utils/RepairController.php | 3 +- src/controllers/BaseElementsController.php | 2 +- src/controllers/DashboardController.php | 3 +- .../ElementIndexSettingsController.php | 3 +- src/controllers/ElementIndexesController.php | 58 +++++-------------- src/controllers/ElementsController.php | 6 +- src/controllers/PreviewController.php | 3 +- src/controllers/SystemSettingsController.php | 3 +- src/controllers/UtilitiesController.php | 17 ++---- src/db/Paginator.php | 3 +- src/elements/actions/CopyReferenceTag.php | 10 +--- src/elements/actions/NewChild.php | 3 - src/elements/actions/NewSiblingAfter.php | 3 - src/elements/actions/NewSiblingBefore.php | 3 - src/elements/actions/Restore.php | 3 - src/elements/conditions/ElementCondition.php | 26 ++++----- .../conditions/RelatedToConditionRule.php | 6 +- src/elements/db/ElementQuery.php | 28 +++------ src/errors/InvalidTypeException.php | 12 ++-- src/events/DefineEagerLoadingMapEvent.php | 3 +- src/events/DefineSourceSortOptionsEvent.php | 3 +- .../DefineSourceTableAttributesEvent.php | 3 +- src/events/EagerLoadElementsEvent.php | 3 +- src/fields/BaseRelationField.php | 12 +--- src/filters/UtilityAccess.php | 3 +- src/gql/base/RelationArgumentHandler.php | 3 +- src/helpers/App.php | 6 +- src/helpers/Component.php | 13 ++--- src/helpers/ElementHelper.php | 3 +- src/helpers/MailerHelper.php | 3 +- src/helpers/Typecast.php | 6 +- src/models/FieldLayout.php | 15 ++--- src/models/ImageTransform.php | 3 +- src/models/ImageTransformIndex.php | 3 +- src/models/MailSettings.php | 3 +- src/mutex/Mutex.php | 2 +- src/queue/jobs/ApplyNewPropagationMethod.php | 8 +-- src/queue/jobs/PropagateElements.php | 15 ++--- src/queue/jobs/PruneRevisions.php | 8 +-- src/queue/jobs/ResaveElements.php | 13 +---- src/queue/jobs/UpdateElementSlugsAndUris.php | 9 +-- src/queue/jobs/UpdateSearchIndex.php | 8 +-- src/services/Conditions.php | 4 +- src/services/Dashboard.php | 5 +- src/services/ElementSources.php | 31 +++------- src/services/Elements.php | 33 ++++------- src/services/Fields.php | 17 ++---- src/services/Fs.php | 2 +- src/services/Gc.php | 6 +- src/services/Gql.php | 8 +-- src/services/ImageTransforms.php | 3 +- src/services/Plugins.php | 9 +-- src/services/Utilities.php | 11 ++-- src/services/Webpack.php | 21 +++---- src/test/Craft.php | 7 +-- src/test/CraftConnector.php | 7 +-- src/test/TestCase.php | 3 +- src/test/TestSetup.php | 12 ++-- .../fixtures/elements/BaseContentFixture.php | 3 +- .../mockclasses/elements/MockElementQuery.php | 3 +- src/web/assets/cp/CpAsset.php | 3 +- 72 files changed, 182 insertions(+), 404 deletions(-) diff --git a/src/Craft.php b/src/Craft.php index 4b39b0f6310..4ef530b9b8d 100644 --- a/src/Craft.php +++ b/src/Craft.php @@ -45,7 +45,7 @@ class Craft extends Yii /** * @inheritdoc * @template T - * @param string|array|callable $type + * @param class-string|array|callable $type * @phpstan-param class-string|array{class:class-string}|callable():T $type * @param array $params * @return T @@ -185,8 +185,7 @@ public static function cookieConfig(array $config = [], ?Request $request = null /** * Class autoloader. * - * @param string $className - * @phpstan-param class-string $className + * @param class-string $className */ public static function autoload($className): void { diff --git a/src/base/ElementAction.php b/src/base/ElementAction.php index 647b59180ae..83ea1a59233 100644 --- a/src/base/ElementAction.php +++ b/src/base/ElementAction.php @@ -34,8 +34,7 @@ public static function isDownload(): bool } /** - * @var string - * @phpstan-var class-string + * @var class-string * @since 3.0.30 */ protected string $elementType; diff --git a/src/base/ElementActionInterface.php b/src/base/ElementActionInterface.php index 62aa017cd8c..ce2ef8c577e 100644 --- a/src/base/ElementActionInterface.php +++ b/src/base/ElementActionInterface.php @@ -41,8 +41,7 @@ public static function isDownload(): bool; /** * Sets the element type on the action. * - * @param string $elementType - * @phpstan-param class-string $elementType + * @param class-string $elementType */ public function setElementType(string $elementType): void; diff --git a/src/base/ElementExporter.php b/src/base/ElementExporter.php index 0fdf21dc194..c16e564e7ab 100644 --- a/src/base/ElementExporter.php +++ b/src/base/ElementExporter.php @@ -24,8 +24,7 @@ public static function isFormattable(): bool } /** - * @var string - * @phpstan-var class-string + * @var class-string */ protected string $elementType; diff --git a/src/base/ElementExporterInterface.php b/src/base/ElementExporterInterface.php index 4fa1248a37f..b588ffbaa40 100644 --- a/src/base/ElementExporterInterface.php +++ b/src/base/ElementExporterInterface.php @@ -28,8 +28,7 @@ public static function isFormattable(): bool; /** * Sets the element type on the exporter. * - * @param string $elementType - * @phpstan-param class-string $elementType + * @param class-string $elementType */ public function setElementType(string $elementType): void; diff --git a/src/base/FieldLayoutComponent.php b/src/base/FieldLayoutComponent.php index 53c54c1537d..ec4af36f45c 100644 --- a/src/base/FieldLayoutComponent.php +++ b/src/base/FieldLayoutComponent.php @@ -48,14 +48,12 @@ private static function defaultUserCondition(): UserCondition } /** - * @param string $elementType - * @phpstan-param class-string $elementType + * @param class-string $elementType * @return ElementConditionInterface */ private static function defaultElementCondition(string $elementType): ElementConditionInterface { if (!isset(self::$defaultElementConditions[$elementType])) { - /** @var string|ElementInterface $elementType */ self::$defaultElementConditions[$elementType] = $elementType::createCondition(); } return self::$defaultElementConditions[$elementType]; @@ -74,7 +72,7 @@ private static function defaultElementCondition(string $elementType): ElementCon private FieldLayout $_layout; /** - * @var UserCondition|string|array|null + * @var UserCondition|class-string|array|null * @phpstan-var UserCondition|class-string|array{class:class-string}|null * @see getUserCondition() * @see setUserCondition() @@ -82,7 +80,7 @@ private static function defaultElementCondition(string $elementType): ElementCon private mixed $_userCondition = null; /** - * @var ElementConditionInterface|string|array|null + * @var ElementConditionInterface|class-string|array|null * @phpstan-var ElementConditionInterface|class-string|array{class:class-string}|null * @see getElementCondition() * @see setElementCondition() @@ -146,7 +144,7 @@ public function getUserCondition(): ?UserCondition /** * Sets the user condition for this layout element. * - * @param UserCondition|string|array|null $userCondition + * @param UserCondition|class-string|array|null $userCondition * @phpstan-param UserCondition|class-string|array{class:class-string}|null $userCondition */ public function setUserCondition(mixed $userCondition): void @@ -171,7 +169,7 @@ public function getElementCondition(): ?ElementConditionInterface /** * Sets the element condition for this layout element. * - * @param ElementConditionInterface|string|array|null $elementCondition + * @param ElementConditionInterface|class-string|array|null $elementCondition * @phpstan-param ElementConditionInterface|class-string|array{class:class-string}|null $elementCondition */ public function setElementCondition(mixed $elementCondition): void @@ -183,7 +181,7 @@ public function setElementCondition(mixed $elementCondition): void * Normalizes a condition. * * @template T of ConditionInterface - * @param T|string|array|null $condition + * @param T|class-string|array|null $condition * @phpstan-param T|class-string|array{class:class-string}|null $condition * @return T|null */ diff --git a/src/base/MissingComponentTrait.php b/src/base/MissingComponentTrait.php index 9517b1da136..e8597fbfa0a 100644 --- a/src/base/MissingComponentTrait.php +++ b/src/base/MissingComponentTrait.php @@ -21,8 +21,7 @@ trait MissingComponentTrait { /** - * @var string The expected component class name. - * @phpstan-var class-string + * @var class-string The expected component class name. */ public string $expectedType; @@ -39,8 +38,7 @@ trait MissingComponentTrait /** * Creates a new component of a given type based on this one’s properties. * - * @param string $type The component class that should be used as the fallback - * @phpstan-param class-string $type + * @param class-string $type The component class that should be used as the fallback * @return ComponentInterface */ public function createFallback(string $type): ComponentInterface diff --git a/src/base/conditions/BaseElementSelectConditionRule.php b/src/base/conditions/BaseElementSelectConditionRule.php index 96d61e7a663..3f5a0d17858 100644 --- a/src/base/conditions/BaseElementSelectConditionRule.php +++ b/src/base/conditions/BaseElementSelectConditionRule.php @@ -29,7 +29,7 @@ abstract class BaseElementSelectConditionRule extends BaseConditionRule /** * Returns the element type that can be selected. * - * @return string + * @return class-string */ abstract protected function elementType(): string; @@ -148,10 +148,7 @@ private function _element(): ?ElementInterface return null; } - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType(); - return $elementType::find() + return $this->elementType()::find() ->site('*') ->preferSites(array_filter([Cp::requestedSite()?->id])) ->unique() diff --git a/src/behaviors/FieldLayoutBehavior.php b/src/behaviors/FieldLayoutBehavior.php index 19616074235..5d4416176b5 100644 --- a/src/behaviors/FieldLayoutBehavior.php +++ b/src/behaviors/FieldLayoutBehavior.php @@ -27,8 +27,7 @@ class FieldLayoutBehavior extends Behavior { /** - * @var string|null The element type that the field layout will be associated with - * @phpstan-var class-string|null + * @var class-string|null The element type that the field layout will be associated with */ public ?string $elementType = null; diff --git a/src/behaviors/SessionBehavior.php b/src/behaviors/SessionBehavior.php index 9d62f6f3714..0ab350d687c 100644 --- a/src/behaviors/SessionBehavior.php +++ b/src/behaviors/SessionBehavior.php @@ -174,8 +174,7 @@ private function _setNotificationFlash(string $type, string $message, array $set * Asset bundles that were queued with this method can be registered using [[getAssetBundleFlashes()]] or * [[\craft\web\View::getBodyHtml()]]. * - * @param string $name the class name of the asset bundle - * @phpstan-param class-string $name + * @param class-string $name the class name of the asset bundle * @param int|null $position if set, this forces a minimum position for javascript files. * @throws Exception if $name isn't an asset bundle class name * @see getAssetBundleFlashes() diff --git a/src/console/controllers/ResaveController.php b/src/console/controllers/ResaveController.php index 31f12149533..9f896096b74 100644 --- a/src/console/controllers/ResaveController.php +++ b/src/console/controllers/ResaveController.php @@ -440,16 +440,13 @@ public function actionUsers(): int } /** - * @param string $elementType The element type that should be resaved - * @phpstan-param class-string $elementType + * @param class-string $elementType The element type that should be resaved * @param array $criteria The element criteria that determines which elements should be resaved * @return int * @since 3.7.0 */ public function resaveElements(string $elementType, array $criteria = []): int { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ $criteria += $this->_baseCriteria(); if ($this->queue) { diff --git a/src/console/controllers/utils/RepairController.php b/src/console/controllers/utils/RepairController.php index 2501a6753a3..9b5ec3fa86c 100644 --- a/src/console/controllers/utils/RepairController.php +++ b/src/console/controllers/utils/RepairController.php @@ -139,8 +139,7 @@ protected function repairStructure(int $structureId, ElementQuery $query): int ]) ->all(); - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ + /** @var class-string $elementType */ $elementType = $query->elementType; $displayName = $elementType::pluralLowerDisplayName(); diff --git a/src/controllers/BaseElementsController.php b/src/controllers/BaseElementsController.php index a4fb5fde4a9..587a4bc9c62 100644 --- a/src/controllers/BaseElementsController.php +++ b/src/controllers/BaseElementsController.php @@ -40,7 +40,7 @@ public function beforeAction($action): bool /** * Returns the posted element type class. * - * @return string + * @return class-string * @throws BadRequestHttpException if the requested element type is invalid */ protected function elementType(): string diff --git a/src/controllers/DashboardController.php b/src/controllers/DashboardController.php index 3a6b5cb8b65..584a0d394be 100644 --- a/src/controllers/DashboardController.php +++ b/src/controllers/DashboardController.php @@ -65,8 +65,7 @@ public function actionIndex(): Response $widgetTypeInfo = []; foreach ($widgetTypes as $widgetType) { - /** @var string|WidgetInterface $widgetType */ - /** @phpstan-var class-string|WidgetInterface $widgetType */ + /** @var class-string $widgetType */ if (!$widgetType::isSelectable()) { continue; } diff --git a/src/controllers/ElementIndexSettingsController.php b/src/controllers/ElementIndexSettingsController.php index 816c0d1aa91..4d08f91fb16 100644 --- a/src/controllers/ElementIndexSettingsController.php +++ b/src/controllers/ElementIndexSettingsController.php @@ -49,8 +49,7 @@ public function beforeAction($action): bool */ public function actionGetCustomizeSourcesModalData(): Response { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ + /** @var class-string $elementType */ $elementType = $this->elementType(); $conditionsService = Craft::$app->getConditions(); $view = Craft::$app->getView(); diff --git a/src/controllers/ElementIndexesController.php b/src/controllers/ElementIndexesController.php index 370fb750984..40fe9ed567d 100644 --- a/src/controllers/ElementIndexesController.php +++ b/src/controllers/ElementIndexesController.php @@ -39,8 +39,7 @@ class ElementIndexesController extends BaseElementsController { /** - * @var string - * @phpstan-var class-string + * @var class-string */ protected string $elementType; @@ -144,10 +143,8 @@ public function getElementQuery(): ElementQueryInterface */ public function actionSourcePath(): Response { - /** @var string|ElementInterface $elementType */ - $elementType = $this->elementType; $stepKey = $this->request->getRequiredBodyParam('stepKey'); - $sourcePath = $elementType::sourcePath($this->sourceKey, $stepKey, $this->context); + $sourcePath = $this->elementType::sourcePath($this->sourceKey, $stepKey, $this->context); return $this->asJson([ 'sourcePath' => $sourcePath, @@ -185,11 +182,9 @@ public function actionGetMoreElements(): Response */ public function actionCountElements(): Response { - /** @var string|ElementInterface $elementType */ - $elementType = $this->elementType; return $this->asJson([ 'resultSet' => $this->request->getParam('resultSet'), - 'count' => $elementType::indexElementCount($this->elementQuery, $this->sourceKey), + 'count' => $this->elementType::indexElementCount($this->elementQuery, $this->sourceKey), ]); } @@ -284,11 +279,8 @@ public function actionPerformAction(): ?Response $responseData = $this->elementResponseData(true, true); // Send updated badge counts - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; $formatter = Craft::$app->getFormatter(); - foreach (Craft::$app->getElementSources()->getSources($elementType, $this->context) as $source) { + foreach (Craft::$app->getElementSources()->getSources($this->elementType, $this->context) as $source) { if (isset($source['key'])) { if (isset($source['badgeCount'])) { $responseData['badgeCounts'][$source['key']] = $formatter->asDecimal($source['badgeCount'], 0); @@ -359,10 +351,7 @@ public function actionExport(): Response break; case Response::FORMAT_XML: Craft::$app->language = 'en-US'; - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; - $this->response->formatters[Response::FORMAT_XML]['rootTag'] = $elementType::pluralLowerDisplayName(); + $this->response->formatters[Response::FORMAT_XML]['rootTag'] = $this->elementType::pluralLowerDisplayName(); break; } } elseif ( @@ -415,9 +404,6 @@ private function _exporter(): ElementExporterInterface */ public function actionFilterHud(): Response { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType(); $id = $this->request->getRequiredBodyParam('id'); $conditionConfig = $this->request->getBodyParam('conditionConfig'); $serialized = $this->request->getBodyParam('serialized'); @@ -434,7 +420,7 @@ public function actionFilterHud(): Response $condition = $conditionsService->createCondition($conditionConfig['condition']); } else { /** @var ElementConditionInterface $condition */ - $condition = $elementType::createCondition(); + $condition = $this->elementType()::createCondition(); } $condition->mainTag = 'div'; @@ -565,10 +551,7 @@ protected function viewState(): array */ protected function elementQuery(): ElementQueryInterface { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; - $query = $elementType::find(); + $query = $this->elementType::find(); $conditionsService = Craft::$app->getConditions(); if (!$this->source) { @@ -679,9 +662,6 @@ protected function elementQuery(): ElementQueryInterface */ protected function elementResponseData(bool $includeContainer, bool $includeActions): array { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; $responseData = []; $view = $this->getView(); @@ -697,7 +677,7 @@ protected function elementResponseData(bool $includeContainer, bool $includeActi $showCheckboxes = !empty($this->actions); if ($this->sourceKey) { - $responseData['html'] = $elementType::indexHtml( + $responseData['html'] = $this->elementType::indexHtml( $this->elementQuery, $disabledElementIds, $this->viewState, @@ -727,22 +707,19 @@ protected function availableActions(): ?array return null; } - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; - $actions = $elementType::actions($this->sourceKey); + $actions = $this->elementType::actions($this->sourceKey); foreach ($actions as $i => $action) { // $action could be a string or config array if ($action instanceof ElementActionInterface) { - $action->setElementType($elementType); + $action->setElementType($this->elementType); } else { if (is_string($action)) { $action = ['type' => $action]; } /** @var array $action */ /** @phpstan-var array{type:class-string} $action */ - $action['elementType'] = $elementType; + $action['elementType'] = $this->elementType; $actions[$i] = $action = Craft::$app->getElements()->createAction($action); } @@ -785,20 +762,17 @@ protected function availableExporters(): ?array return null; } - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; - $exporters = $elementType::exporters($this->sourceKey); + $exporters = $this->elementType::exporters($this->sourceKey); foreach ($exporters as $i => $exporter) { // $action could be a string or config array if ($exporter instanceof ElementExporterInterface) { - $exporter->setElementType($elementType); + $exporter->setElementType($this->elementType); } else { if (is_string($exporter)) { $exporter = ['type' => $exporter]; } - $exporter['elementType'] = $elementType; + $exporter['elementType'] = $this->elementType; $exporters[$i] = Craft::$app->getElements()->createExporter($exporter); } } @@ -875,8 +849,6 @@ public function actionElementTableHtml(): Response throw new BadRequestHttpException("Request missing required body param"); } - /** @var string|ElementInterface $elementType */ - $elementType = $this->elementType; $id = $this->request->getRequiredBodyParam('id'); $siteId = $this->request->getRequiredBodyParam('siteId'); $site = $siteId ? Craft::$app->getSites()->getSiteById($siteId) : null; @@ -894,7 +866,7 @@ public function actionElementTableHtml(): Response } /** @var ElementInterface|null $element */ - $element = $elementType::find() + $element = $this->elementType::find() ->id($id) ->drafts(null) ->provisionalDrafts(null) diff --git a/src/controllers/ElementsController.php b/src/controllers/ElementsController.php index a2f8ece303a..1e21e0ffe75 100644 --- a/src/controllers/ElementsController.php +++ b/src/controllers/ElementsController.php @@ -1896,8 +1896,7 @@ private function _element( throw new BadRequestHttpException('Request missing required param.'); } - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ + /** @var class-string $elementType */ $this->_validateElementType($elementType); if ($elementType::isLocalized()) { @@ -2035,8 +2034,7 @@ private function _elementById( /** * Ensures the given element type is valid. * - * @param string $elementType - * @phpstan-param class-string $elementType + * @param class-string $elementType * @throws BadRequestHttpException */ private function _validateElementType(string $elementType): void diff --git a/src/controllers/PreviewController.php b/src/controllers/PreviewController.php index e373b377119..08d2bf704c9 100644 --- a/src/controllers/PreviewController.php +++ b/src/controllers/PreviewController.php @@ -97,8 +97,7 @@ public function actionCreateToken(): Response /** * Substitutes an element for the element being previewed for the remainder of the request, and reroutes the request. * - * @param string $elementType - * @phpstan-param class-string $elementType + * @param class-string $elementType * @param int $canonicalId * @param int $siteId * @param int|null $draftId diff --git a/src/controllers/SystemSettingsController.php b/src/controllers/SystemSettingsController.php index fa53d736c8b..33db0007d00 100644 --- a/src/controllers/SystemSettingsController.php +++ b/src/controllers/SystemSettingsController.php @@ -129,8 +129,7 @@ public function actionEditEmailSettings(?MailSettings $settings = null, ?Transpo $transportTypeOptions = []; foreach ($allTransportAdapterTypes as $transportAdapterType) { - /** @var string|TransportAdapterInterface $transportAdapterType */ - /** @phpstan-var class-string|TransportAdapterInterface $transportAdapterType */ + /** @var class-string $transportAdapterType */ if ($transportAdapterType === get_class($adapter) || $transportAdapterType::isSelectable()) { $allTransportAdapters[] = MailerHelper::createTransportAdapter($transportAdapterType); $transportTypeOptions[] = [ diff --git a/src/controllers/UtilitiesController.php b/src/controllers/UtilitiesController.php index 554b038d9b8..8481c1fc4c3 100644 --- a/src/controllers/UtilitiesController.php +++ b/src/controllers/UtilitiesController.php @@ -108,13 +108,12 @@ public function actionIndex(): Response public function actionShowUtility(string $id): Response { $utilitiesService = Craft::$app->getUtilities(); + $class = $utilitiesService->getUtilityTypeById($id); - if (($class = $utilitiesService->getUtilityTypeById($id)) === null) { + if ($class === null) { return $this->run('index'); } - /** @var string|UtilityInterface $class */ - /** @phpstan-var class-string|UtilityInterface $class */ if ($utilitiesService->checkAuthorization($class) === false) { throw new ForbiddenHttpException('User not permitted to access the "' . $class::displayName() . '".'); } @@ -323,8 +322,7 @@ private function _utilityInfo(): array $info = []; foreach (Craft::$app->getUtilities()->getAuthorizedUtilityTypes() as $class) { - /** @var string|UtilityInterface $class */ - /** @phpstan-var class-string|UtilityInterface $class */ + /** @var class-string $class */ $info[] = [ 'id' => $class::id(), 'iconSvg' => $this->_getUtilityIconSvg($class), @@ -340,13 +338,11 @@ private function _utilityInfo(): array /** * Returns a utility type’s SVG icon. * - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return string */ private function _getUtilityIconSvg(string $class): string { - /** @var UtilityInterface|string $class */ $iconPath = $class::iconPath(); if ($iconPath === null) { @@ -369,14 +365,11 @@ private function _getUtilityIconSvg(string $class): string /** * Returns the default icon SVG for a given utility type. * - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return string */ private function _getDefaultUtilityIconSvg(string $class): string { - /** @var string|UtilityInterface $class */ - /** @phpstan-var class-string|UtilityInterface $class */ return $this->getView()->renderTemplate('_includes/defaulticon.svg.twig', [ 'label' => $class::displayName(), ]); diff --git a/src/db/Paginator.php b/src/db/Paginator.php index 2e481983122..0d0d695e964 100644 --- a/src/db/Paginator.php +++ b/src/db/Paginator.php @@ -48,9 +48,8 @@ class Paginator extends BaseObject { /** - * @var YiiConnection|array|string|null The DB connection to be used with the query. + * @var YiiConnection|array|class-string|null The DB connection to be used with the query. * If null, the query will choose the connection to use. - * @phpstan-var YiiConnection|array{class:class-string}|class-string|null */ public YiiConnection|array|string|null $db = null; diff --git a/src/elements/actions/CopyReferenceTag.php b/src/elements/actions/CopyReferenceTag.php index c78fc6ba6d7..b5dcd6d4d37 100644 --- a/src/elements/actions/CopyReferenceTag.php +++ b/src/elements/actions/CopyReferenceTag.php @@ -9,7 +9,6 @@ use Craft; use craft\base\ElementAction; -use craft\base\ElementInterface; use yii\base\Exception; /** @@ -33,12 +32,9 @@ public function getTriggerLabel(): string */ public function getTriggerHtml(): ?string { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; - - if (($refHandle = $elementType::refHandle()) === null) { - throw new Exception("Element type \"$elementType\" doesn't have a reference handle."); + $refHandle = $this->elementType::refHandle(); + if ($refHandle === null) { + throw new Exception("Element type \"$this->elementType\" doesn't have a reference handle."); } Craft::$app->getView()->registerJsWithVars(fn($type, $refHandle) => << $elementType */ parent::setElementType($elementType); if (!isset($this->label)) { diff --git a/src/elements/actions/NewSiblingAfter.php b/src/elements/actions/NewSiblingAfter.php index 49239fa7bfd..390278cdec3 100644 --- a/src/elements/actions/NewSiblingAfter.php +++ b/src/elements/actions/NewSiblingAfter.php @@ -9,7 +9,6 @@ use Craft; use craft\base\ElementAction; -use craft\base\ElementInterface; /** * NewSibling represents a “Create a new X after” element action. @@ -34,8 +33,6 @@ class NewSiblingAfter extends ElementAction */ public function setElementType(string $elementType): void { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string $elementType */ parent::setElementType($elementType); if (!isset($this->label)) { diff --git a/src/elements/actions/NewSiblingBefore.php b/src/elements/actions/NewSiblingBefore.php index 65ecdc3e968..1e42d23833d 100644 --- a/src/elements/actions/NewSiblingBefore.php +++ b/src/elements/actions/NewSiblingBefore.php @@ -9,7 +9,6 @@ use Craft; use craft\base\ElementAction; -use craft\base\ElementInterface; /** * NewSibling represents a “Create a new X before” element action. @@ -34,8 +33,6 @@ class NewSiblingBefore extends ElementAction */ public function setElementType(string $elementType): void { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string $elementType */ parent::setElementType($elementType); if (!isset($this->label)) { diff --git a/src/elements/actions/Restore.php b/src/elements/actions/Restore.php index 7f928fe509a..e39a61b4f1b 100644 --- a/src/elements/actions/Restore.php +++ b/src/elements/actions/Restore.php @@ -9,7 +9,6 @@ use Craft; use craft\base\ElementAction; -use craft\base\ElementInterface; use craft\elements\db\ElementQueryInterface; /** @@ -46,8 +45,6 @@ class Restore extends ElementAction */ public function setElementType(string $elementType): void { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string $elementType */ parent::setElementType($elementType); if (!isset($this->successMessage)) { diff --git a/src/elements/conditions/ElementCondition.php b/src/elements/conditions/ElementCondition.php index d42a103b2c0..0997b762711 100644 --- a/src/elements/conditions/ElementCondition.php +++ b/src/elements/conditions/ElementCondition.php @@ -25,8 +25,7 @@ class ElementCondition extends BaseCondition implements ElementConditionInterfac public bool $sortable = false; /** - * @var string|null The element type being queried. - * @phpstan-var class-string|null + * @var class-string|null The element type being queried. */ public ?string $elementType = null; @@ -57,8 +56,7 @@ class ElementCondition extends BaseCondition implements ElementConditionInterfac /** * Constructor. * - * @param string|null $elementType - * @phpstan-param class-string|null $elementType + * @param class-string|null $elementType * @param array $config */ public function __construct(?string $elementType = null, array $config = []) @@ -124,11 +122,7 @@ protected function conditionRuleTypes(): array SlugConditionRule::class, ]; - /** @var string|ElementInterface|null $elementType */ - /** @phpstan-var class-string|ElementInterface|null $elementType */ - $elementType = $this->elementType; - - if (Craft::$app->getIsMultiSite() && (!$elementType || $elementType::isLocalized())) { + if (Craft::$app->getIsMultiSite() && ($this->elementType === null || $this->elementType::isLocalized())) { $types[] = SiteConditionRule::class; $types[] = LanguageConditionRule::class; @@ -137,26 +131,26 @@ protected function conditionRuleTypes(): array } } - if ($elementType !== null) { - if ($elementType::hasUris()) { + if ($this->elementType !== null) { + if ($this->elementType::hasUris()) { $types[] = HasUrlConditionRule::class; $types[] = UriConditionRule::class; } - if ($elementType::hasStatuses()) { + if ($this->elementType::hasStatuses()) { $types[] = StatusConditionRule::class; } - if ($elementType::hasContent()) { - if ($elementType::hasTitles()) { + if ($this->elementType::hasContent()) { + if ($this->elementType::hasTitles()) { $types[] = TitleConditionRule::class; } // If we have a source key, we can fetch just the field layouts that are available to it if ($this->sourceKey) { - $fieldLayouts = Craft::$app->getElementSources()->getFieldLayoutsForSource($elementType, $this->sourceKey); + $fieldLayouts = Craft::$app->getElementSources()->getFieldLayoutsForSource($this->elementType, $this->sourceKey); } else { - $fieldLayouts = Craft::$app->getFields()->getLayoutsByType($elementType); + $fieldLayouts = Craft::$app->getFields()->getLayoutsByType($this->elementType); } foreach ($fieldLayouts as $fieldLayout) { diff --git a/src/elements/conditions/RelatedToConditionRule.php b/src/elements/conditions/RelatedToConditionRule.php index 89df14cce0b..eec28f5f812 100644 --- a/src/elements/conditions/RelatedToConditionRule.php +++ b/src/elements/conditions/RelatedToConditionRule.php @@ -22,8 +22,7 @@ class RelatedToConditionRule extends BaseElementSelectConditionRule implements ElementConditionRuleInterface { /** - * @var string - * @phpstan-var class-string + * @var class-string */ public string $elementType = Entry::class; @@ -95,8 +94,7 @@ private function _elementTypeOptions(): array { $options = []; foreach (Craft::$app->getElements()->getAllElementTypes() as $elementType) { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ + /** @var class-string $elementType */ if (!is_subclass_of($elementType, BlockElementInterface::class)) { $options[] = [ 'value' => $elementType, diff --git a/src/elements/db/ElementQuery.php b/src/elements/db/ElementQuery.php index 7a7b4da47d8..f043c6e5a8e 100644 --- a/src/elements/db/ElementQuery.php +++ b/src/elements/db/ElementQuery.php @@ -104,8 +104,7 @@ class ElementQuery extends Query implements ElementQueryInterface public const EVENT_AFTER_POPULATE_ELEMENTS = 'afterPopulateElements'; /** - * @var string The name of the [[ElementInterface]] class. - * @phpstan-var class-string + * @var class-string The name of the [[ElementInterface]] class. */ public string $elementType; @@ -533,8 +532,7 @@ class ElementQuery extends Query implements ElementQueryInterface /** * Constructor * - * @param string $elementType The element type class associated with this query - * @phpstan-param class-string $elementType + * @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 = []) @@ -1378,8 +1376,8 @@ public function prepare($builder): Query if (isset($this->id) && empty($this->id)) { throw new QueryAbortedException(); } - /** @var string|ElementInterface $class */ - /** @phpstan-var class-string|ElementInterface $class */ + + /** @var class-string $class */ $class = $this->elementType; // Make sure the siteId param is set @@ -2015,8 +2013,7 @@ public function createElement(array $row): ElementInterface return $element; } - /** @var string|ElementInterface $class */ - /** @phpstan-var class-string|ElementInterface $class */ + /** @var class-string $class */ $class = $this->elementType; // Instantiate the element @@ -2399,13 +2396,11 @@ private function _placeholderCondition(mixed $condition): mixed /** * Joins the content table into the query being prepared. * - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @throws QueryAbortedException */ private function _joinContentTable(string $class): void { - /** @var ElementInterface|string $class */ // Join in the content table on both queries $joinCondition = [ 'and', @@ -2477,14 +2472,11 @@ private function _joinContentTable(string $class): void /** * Applies the 'status' param to the query being prepared. * - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @throws QueryAbortedException */ private function _applyStatusParam(string $class): void { - /** @var string|ElementInterface $class */ - /** @phpstan-var class-string|ElementInterface $class */ if (!$this->status || !$class::hasStatuses()) { return; } @@ -2572,8 +2564,7 @@ private function _shouldJoinStructureData(): bool /** * Applies the structure params to the query being prepared. * - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @throws QueryAbortedException */ private function _applyStructureParams(string $class): void @@ -2879,8 +2870,7 @@ private function _normalizeSiteId(): void * Normalizes a structure param value to either an Element object or false. * * @param string $property The parameter’s property name. - * @param string $class The element class - * @phpstan-param class-string $class + * @param class-string $class The element class * @return ElementInterface The normalized element * @throws QueryAbortedException if the element can't be found */ diff --git a/src/errors/InvalidTypeException.php b/src/errors/InvalidTypeException.php index 9bcece3a2e3..ff21687aa50 100644 --- a/src/errors/InvalidTypeException.php +++ b/src/errors/InvalidTypeException.php @@ -18,24 +18,20 @@ class InvalidTypeException extends Exception { /** - * @var string The invalid class name - * @phpstan-var class-string + * @var class-string The invalid class name */ public string $class; /** - * @var string The base class or interface that [[$class]] was supposed to be - * @phpstan-var class-string + * @var class-string The base class or interface that [[$class]] was supposed to be */ public string $requiredType; /** * Constructor. * - * @param string $class The class that doesn’t exist or doesn’t extend/implement $requiredType - * @phpstan-param class-string $class - * @param string $requiredType The base class or interface that $class was supposed to be - * @phpstan-param class-string $requiredType + * @param class-string $class The class that doesn’t exist or doesn’t extend/implement $requiredType + * @param class-string $requiredType The base class or interface that $class was supposed to be * @param string|null $message The error message * @param int $code The error code */ diff --git a/src/events/DefineEagerLoadingMapEvent.php b/src/events/DefineEagerLoadingMapEvent.php index 4eb1bcec30b..9d54db643a4 100644 --- a/src/events/DefineEagerLoadingMapEvent.php +++ b/src/events/DefineEagerLoadingMapEvent.php @@ -29,8 +29,7 @@ class DefineEagerLoadingMapEvent extends Event public string $handle; /** - * @var string|null The element type class to eager-load. - * @phpstan-var class-string|null + * @var class-string|null The element type class to eager-load. */ public ?string $elementType = null; diff --git a/src/events/DefineSourceSortOptionsEvent.php b/src/events/DefineSourceSortOptionsEvent.php index cc4d817d436..47efc66dcaa 100644 --- a/src/events/DefineSourceSortOptionsEvent.php +++ b/src/events/DefineSourceSortOptionsEvent.php @@ -19,8 +19,7 @@ class DefineSourceSortOptionsEvent extends Event { /** - * @var string The element type class - * @phpstan-var class-string + * @var class-string The element type class */ public string $elementType; diff --git a/src/events/DefineSourceTableAttributesEvent.php b/src/events/DefineSourceTableAttributesEvent.php index f3408473428..9b266320757 100644 --- a/src/events/DefineSourceTableAttributesEvent.php +++ b/src/events/DefineSourceTableAttributesEvent.php @@ -19,8 +19,7 @@ class DefineSourceTableAttributesEvent extends Event { /** - * @var string The element type class - * @phpstan-var class-string + * @var class-string The element type class */ public string $elementType; diff --git a/src/events/EagerLoadElementsEvent.php b/src/events/EagerLoadElementsEvent.php index aba127ff7e1..2fd81c904e7 100644 --- a/src/events/EagerLoadElementsEvent.php +++ b/src/events/EagerLoadElementsEvent.php @@ -20,8 +20,7 @@ class EagerLoadElementsEvent extends Event { /** - * @var string The source element type - * @phpstan-var class-string + * @var class-string The source element type */ public string $elementType; diff --git a/src/fields/BaseRelationField.php b/src/fields/BaseRelationField.php index bbd8fdd9a67..9794c7d6990 100644 --- a/src/fields/BaseRelationField.php +++ b/src/fields/BaseRelationField.php @@ -82,8 +82,7 @@ public static function supportedTranslationMethods(): array /** * Returns the element class associated with this field type. * - * @return string The Element class name - * @phpstan-return class-string + * @return class-string The Element class name */ abstract public static function elementType(): string; @@ -601,8 +600,6 @@ public function normalizeValue(mixed $value, ?ElementInterface $element = null): return $value; } - /** @var string|ElementInterface $class */ - /** @phpstan-var class-string|ElementInterface $class */ $class = static::elementType(); /** @var ElementQuery $query */ $query = $class::find() @@ -983,12 +980,8 @@ public function afterElementSave(ElementInterface $element, bool $isNew): void if ($this->maintainHierarchy) { $structuresService = Craft::$app->getStructures(); - - /** @var ElementInterface $class */ - $class = static::elementType(); - /** @var ElementInterface[] $structureElements */ - $structureElements = $class::find() + $structureElements = static::elementType()::find() ->id($targetIds) ->drafts(null) ->revisions(null) @@ -1087,7 +1080,6 @@ public function getSourceOptions(): array */ public function getTargetSiteFieldHtml(): ?string { - /** @var ElementInterface|string $class */ $class = static::elementType(); if (!Craft::$app->getIsMultiSite() || !$class::isLocalized()) { diff --git a/src/filters/UtilityAccess.php b/src/filters/UtilityAccess.php index 85492749c1c..3e2e67f6685 100644 --- a/src/filters/UtilityAccess.php +++ b/src/filters/UtilityAccess.php @@ -25,8 +25,7 @@ class UtilityAccess extends ActionFilter use ConditionalFilterTrait; /** - * @var string The utility class - * @phpstan-var class-string + * @var class-string The utility class */ public string $utility; diff --git a/src/gql/base/RelationArgumentHandler.php b/src/gql/base/RelationArgumentHandler.php index 52324b2e7cc..e7e989da4f3 100644 --- a/src/gql/base/RelationArgumentHandler.php +++ b/src/gql/base/RelationArgumentHandler.php @@ -27,8 +27,7 @@ abstract class RelationArgumentHandler extends ArgumentHandler /** * Get the IDs of elements returned by configuring the provided element query with given criteria. * - * @param string $elementType - * @phpstan-param class-string $elementType + * @param class-string $elementType * @param array $criteriaList * @return int[][] */ diff --git a/src/helpers/App.php b/src/helpers/App.php index d10f5acfdcd..5cf5b7536db 100644 --- a/src/helpers/App.php +++ b/src/helpers/App.php @@ -139,8 +139,7 @@ public static function env(string $name): mixed * For example, if an object has a `fooBar` property, and `X`/`X_` is passed as the prefix, the resulting array * may contain a `fooBar` key set to an `X_FOO_BAR` environment variable value, if it exists. * - * @param string $class The class name - * @phpstan-param class-string $class + * @param class-string $class The class name * @param string|null $envPrefix The environment variable name prefix * @return array * @phpstan-return array @@ -719,8 +718,7 @@ public static function supportsIdn(): bool /** * Returns a humanized class name. * - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return string */ public static function humanizeClass(string $class): string diff --git a/src/helpers/Component.php b/src/helpers/Component.php index d823776c7bb..e281264bc1b 100644 --- a/src/helpers/Component.php +++ b/src/helpers/Component.php @@ -25,10 +25,8 @@ class Component * Returns whether a component class exists, is an instance of a given interface, * and doesn't belong to a disabled plugin. * - * @param string $class The component’s class name. - * @phpstan-param class-string $class - * @param string|null $instanceOf The class or interface that the component must be an instance of. - * @phpstan-param class-string|null $instanceOf + * @param class-string $class The component’s class name. + * @param class-string|null $instanceOf The class or interface that the component must be an instance of. * @param bool $throwException Whether an exception should be thrown if an issue is encountered * @return bool * @throws InvalidConfigException if $config doesn’t contain a `type` value, or the type isn’t compatible with|null $instanceOf. @@ -52,8 +50,6 @@ public static function validateComponentClass(string $class, ?string $instanceOf throw new InvalidConfigException("Component class '$class' does not implement ComponentInterface."); } - /** @var string $class */ - /** @phpstan-var class-string $class */ if ($instanceOf !== null && !is_subclass_of($class, $instanceOf)) { if (!$throwException) { return false; @@ -106,10 +102,9 @@ public static function cleanseConfig(array $config): array * Instantiates and populates a component, and ensures that it is an instance of a given interface. * * @template T of ComponentInterface - * @param string|array $config The component’s class name, or its config, with a `type` value and optionally a `settings` value. + * @param class-string|array $config The component’s class name, or its config, with a `type` value and optionally a `settings` value. * @phpstan-param class-string|array{type:class-string,__class?:string} $config - * @param string|null $instanceOf The class or interface that the component must be an instance of. - * @phpstan-param class-string|null $instanceOf + * @param class-string|null $instanceOf The class or interface that the component must be an instance of. * @return T The component * @throws InvalidConfigException if $config doesn’t contain a `type` value, or the type isn’t compatible with|null $instanceOf. * @throws MissingComponentException if the class specified by $config doesn’t exist, or belongs to an uninstalled plugin diff --git a/src/helpers/ElementHelper.php b/src/helpers/ElementHelper.php index 05b7ccf335d..01de696272e 100644 --- a/src/helpers/ElementHelper.php +++ b/src/helpers/ElementHelper.php @@ -621,8 +621,7 @@ public static function rootSourceKey(string $sourceKey): string /** * Returns an element type's source definition based on a given source key/path and context. * - * @param string $elementType The element type class - * @phpstan-param class-string $elementType + * @param class-string $elementType The element type class * @param string $sourceKey The source key/path * @param string $context The context * @return array|null The source definition, or null if it cannot be found diff --git a/src/helpers/MailerHelper.php b/src/helpers/MailerHelper.php index 7d8c82e07ea..22b7ceb54b8 100644 --- a/src/helpers/MailerHelper.php +++ b/src/helpers/MailerHelper.php @@ -74,8 +74,7 @@ public static function allMailerTransportTypes(): array * Creates a transport adapter based on the given mail settings. * * @template T of TransportAdapterInterface - * @param string $type - * @phpstan-param class-string $type + * @param class-string $type * @param array|null $settings * @return T * @throws MissingComponentException if $type is missing diff --git a/src/helpers/Typecast.php b/src/helpers/Typecast.php index 5298043ab29..7734b43dfdf 100644 --- a/src/helpers/Typecast.php +++ b/src/helpers/Typecast.php @@ -38,8 +38,7 @@ final class Typecast /** * Typecasts the given property values based on their type declarations. * - * @param string $class The class name - * @phpstan-param class-string $class + * @param class-string $class The class name * @param array $properties The property values */ public static function properties(string $class, array &$properties): void @@ -52,8 +51,7 @@ public static function properties(string $class, array &$properties): void /** * Typecasts the given property value based on its type declaration. * - * @param string $class The class name - * @phpstan-param class-string $class + * @param class-string $class The class name * @param string $property The property name * @param mixed $value The property value */ diff --git a/src/models/FieldLayout.php b/src/models/FieldLayout.php index eaa81ade45b..a4aa464e78a 100644 --- a/src/models/FieldLayout.php +++ b/src/models/FieldLayout.php @@ -192,8 +192,7 @@ public static function createFromConfig(array $config): self public ?int $id = null; /** - * @var string|null The element type - * @phpstan-var class-string|null + * @var class-string|null The element type */ public ?string $type = null; @@ -528,8 +527,7 @@ public function getConfig(): ?array * Returns the layout elements of a given type. * * @template T - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return T[] * @since 4.0.0 */ @@ -543,8 +541,7 @@ public function getElementsByType(string $class): array * Returns the visible layout elements of a given type, taking conditions into account. * * @template T - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @param ElementInterface $element * @return T[] * @since 4.0.0 @@ -559,8 +556,7 @@ public function getVisibleElementsByType(string $class, ElementInterface $elemen * Returns the first layout element of a given type. * * @template T of FieldLayoutElement - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return T|null The layout element, or `null` if none were found * @since 4.0.0 */ @@ -574,8 +570,7 @@ public function getFirstElementByType(string $class): ?FieldLayoutElement * Returns the first visible layout element of a given type, taking conditions into account. * * @template T of FieldLayoutElement - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @param ElementInterface $element * @return T|null The layout element, or `null` if none were found * @since 4.0.0 diff --git a/src/models/ImageTransform.php b/src/models/ImageTransform.php index 32bf2be818b..2f0ddeb01cb 100644 --- a/src/models/ImageTransform.php +++ b/src/models/ImageTransform.php @@ -108,8 +108,7 @@ class ImageTransform extends Model public ?bool $upscale = null; /** - * @var string The image transformer to use. - * @phpstan-var class-string + * @var class-string The image transformer to use. */ protected string $transformer = self::DEFAULT_TRANSFORMER; diff --git a/src/models/ImageTransformIndex.php b/src/models/ImageTransformIndex.php index 39c5398bf3b..f8f1550d03d 100644 --- a/src/models/ImageTransformIndex.php +++ b/src/models/ImageTransformIndex.php @@ -34,8 +34,7 @@ class ImageTransformIndex extends Model public ?int $assetId = null; /** - * @var string The image transformer - * @phpstan-var class-string + * @var class-string The image transformer */ public string $transformer = ImageTransform::DEFAULT_TRANSFORMER; diff --git a/src/models/MailSettings.php b/src/models/MailSettings.php index 9f7d77b268c..1c22e6638d2 100644 --- a/src/models/MailSettings.php +++ b/src/models/MailSettings.php @@ -44,8 +44,7 @@ class MailSettings extends Model public ?string $template = null; /** - * @var string|null The transport type that should be used - * @phpstan-var class-string|null + * @var class-string|null The transport type that should be used */ public ?string $transportType = Sendmail::class; diff --git a/src/mutex/Mutex.php b/src/mutex/Mutex.php index 29a0f39ae72..ff50f723a8c 100644 --- a/src/mutex/Mutex.php +++ b/src/mutex/Mutex.php @@ -24,7 +24,7 @@ class Mutex extends YiiMutex } /** - * @var YiiMutex|array|string The internal mutex driver to use. + * @var YiiMutex|array|class-string The internal mutex driver to use. * @phpstan-var YiiMutex|array{class:class-string}|class-string * * This can be set from `config/app.php` like so: diff --git a/src/queue/jobs/ApplyNewPropagationMethod.php b/src/queue/jobs/ApplyNewPropagationMethod.php index 4621430333b..b68bcb3e730 100644 --- a/src/queue/jobs/ApplyNewPropagationMethod.php +++ b/src/queue/jobs/ApplyNewPropagationMethod.php @@ -32,8 +32,7 @@ class ApplyNewPropagationMethod extends BaseBatchedJob { /** - * @var string The element type to use - * @phpstan-var class-string + * @var class-string The element type to use */ public string $elementType; @@ -51,10 +50,7 @@ class ApplyNewPropagationMethod extends BaseBatchedJob */ protected function loadData(): Batchable { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; - $query = $elementType::find() + $query = $this->elementType::find() ->site('*') ->preferSites([Craft::$app->getSites()->getPrimarySite()->id]) ->unique() diff --git a/src/queue/jobs/PropagateElements.php b/src/queue/jobs/PropagateElements.php index 0bed8169d8e..fb1411ded11 100644 --- a/src/queue/jobs/PropagateElements.php +++ b/src/queue/jobs/PropagateElements.php @@ -25,8 +25,7 @@ class PropagateElements extends BaseBatchedJob { /** - * @var string The element type that should be propagated - * @phpstan-var class-string + * @var class-string The element type that should be propagated */ public string $elementType; @@ -59,10 +58,7 @@ public function init(): void */ protected function loadData(): Batchable { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; - $query = $elementType::find() + $query = $this->elementType::find() ->status(null) ->drafts(null) ->provisionalDrafts(null) @@ -109,11 +105,10 @@ protected function processItem(mixed $item): void */ protected function defaultDescription(): ?string { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; return Translation::prep('app', 'Propagating {type}', [ - 'type' => $this->totalItems() == 1 ? $elementType::lowerDisplayName() : $elementType::pluralLowerDisplayName(), + 'type' => $this->totalItems() == 1 + ? $this->elementType::lowerDisplayName() + : $this->elementType::pluralLowerDisplayName(), ]); } } diff --git a/src/queue/jobs/PruneRevisions.php b/src/queue/jobs/PruneRevisions.php index 6481f71f8bf..6582a26e9f4 100644 --- a/src/queue/jobs/PruneRevisions.php +++ b/src/queue/jobs/PruneRevisions.php @@ -21,8 +21,7 @@ class PruneRevisions extends BaseJob { /** - * @var string The type of elements to update. - * @phpstan-var class-string + * @var class-string The type of elements to update. */ public string $elementType; @@ -56,10 +55,7 @@ public function execute($queue): void $this->maxRevisions = $generalConfig->maxRevisions; } - /** @var string|ElementInterface $class */ - /** @phpstan-var class-string|ElementInterface $class */ - $class = $this->elementType; - $extraRevisions = $class::find() + $extraRevisions = $this->elementType::find() ->revisionOf($this->canonicalId) ->siteId($this->siteId) ->status(null) diff --git a/src/queue/jobs/ResaveElements.php b/src/queue/jobs/ResaveElements.php index e46693dbaa4..beec003b1dd 100644 --- a/src/queue/jobs/ResaveElements.php +++ b/src/queue/jobs/ResaveElements.php @@ -28,8 +28,7 @@ class ResaveElements extends BaseBatchedJob { /** - * @var string The element type that should be resaved - * @phpstan-var class-string + * @var class-string The element type that should be resaved */ public string $elementType; @@ -79,10 +78,7 @@ class ResaveElements extends BaseBatchedJob */ protected function loadData(): Batchable { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; - $query = $elementType::find() + $query = $this->elementType::find() ->orderBy(['elements.id' => SORT_ASC]); if (!empty($this->criteria)) { @@ -140,11 +136,8 @@ protected function processItem(mixed $item): void */ protected function defaultDescription(): ?string { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; return Translation::prep('app', 'Resaving {type}', [ - 'type' => $elementType::pluralLowerDisplayName(), + 'type' => $this->elementType::pluralLowerDisplayName(), ]); } } diff --git a/src/queue/jobs/UpdateElementSlugsAndUris.php b/src/queue/jobs/UpdateElementSlugsAndUris.php index 616dc54716b..01f19081ae8 100644 --- a/src/queue/jobs/UpdateElementSlugsAndUris.php +++ b/src/queue/jobs/UpdateElementSlugsAndUris.php @@ -32,8 +32,7 @@ class UpdateElementSlugsAndUris extends BaseJob public array|int|null $elementId = null; /** - * @var string The type of elements to update. - * @phpstan-var class-string + * @var class-string The type of elements to update. */ public string $elementType; @@ -91,11 +90,7 @@ protected function defaultDescription(): ?string */ private function _createElementQuery(): ElementQueryInterface { - /** @var string|ElementInterface $class */ - /** @phpstan-var class-string|ElementInterface $class */ - $class = $this->elementType; - - return $class::find() + return $this->elementType::find() ->siteId($this->siteId) ->status(null); } diff --git a/src/queue/jobs/UpdateSearchIndex.php b/src/queue/jobs/UpdateSearchIndex.php index f11199953de..1ea786c0605 100644 --- a/src/queue/jobs/UpdateSearchIndex.php +++ b/src/queue/jobs/UpdateSearchIndex.php @@ -21,8 +21,7 @@ class UpdateSearchIndex extends BaseJob { /** - * @var string The type of elements to update. - * @phpstan-var class-string + * @var class-string The type of elements to update. */ public string $elementType; @@ -47,10 +46,7 @@ class UpdateSearchIndex extends BaseJob */ public function execute($queue): void { - /** @var string|ElementInterface $class */ - /** @phpstan-var class-string|ElementInterface $class */ - $class = $this->elementType; - $elements = $class::find() + $elements = $this->elementType::find() ->drafts(null) ->provisionalDrafts(null) ->id($this->elementId) diff --git a/src/services/Conditions.php b/src/services/Conditions.php index 22b43517244..985fe0cb161 100644 --- a/src/services/Conditions.php +++ b/src/services/Conditions.php @@ -32,8 +32,8 @@ class Conditions extends Component * Creates a condition instance. * * @template T of ConditionInterface - * @param array|string $config The condition class or configuration array - * @phpstan-param array{class:class-string}|string $config + * @param array|class-string $config The condition class or configuration array + * @phpstan-param array{class:class-string}|class-string $config * @return T * @throws InvalidArgumentException if the condition does not implement [[ConditionInterface]] * @throws InvalidConfigException diff --git a/src/services/Dashboard.php b/src/services/Dashboard.php index ce5e2284d02..e9b6bdbf215 100644 --- a/src/services/Dashboard.php +++ b/src/services/Dashboard.php @@ -112,7 +112,7 @@ public function getAllWidgetTypes(): array * Creates a widget with a given config. * * @template T of WidgetInterface - * @param string|array $config The widget’s class name, or its config, with a `type` value and optionally a `settings` value. + * @param class-string|array $config The widget’s class name, or its config, with a `type` value and optionally a `settings` value. * @phpstan-param class-string|array{type:class-string} $config * @return T */ @@ -157,8 +157,7 @@ public function getAllWidgets(): array /** * Returns whether the current user has a widget of the given type. * - * @param string $type The widget type - * @phpstan-param class-string $type + * @param class-string $type The widget type * @return bool Whether the current user has a widget of the given type */ public function doesUserHaveWidget(string $type): bool diff --git a/src/services/ElementSources.php b/src/services/ElementSources.php index 55657b419e6..b1b008eecf3 100644 --- a/src/services/ElementSources.php +++ b/src/services/ElementSources.php @@ -67,8 +67,7 @@ public static function filterExtraHeadings(array $sources): array /** * Returns the element index sources in the custom groupings/order. * - * @param string $elementType The element type class - * @phpstan-param class-string $elementType + * @param class-string $elementType The element type class * @param string $context The context * @param bool $withDisabled Whether disabled sources should be included * @return array[] @@ -167,14 +166,11 @@ private function _showCustomSource(array $source): bool /** * Returns the common table attributes that are available for a given element type, across all its sources. * - * @param string $elementType The element type class - * @phpstan-param class-string $elementType + * @param class-string $elementType The element type class * @return array[] */ public function getAvailableTableAttributes(string $elementType): array { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ $attributes = $elementType::tableAttributes(); // Normalize @@ -240,8 +236,7 @@ public function getTableAttributes(string $elementType, string $sourceKey, ?arra /** * Returns all the field layouts available for the given element source. * - * @param string $elementType - * @phpstan-param class-string $elementType + * @param class-string $elementType * @param string $sourceKey * @return FieldLayout[] */ @@ -253,18 +248,16 @@ public function getFieldLayoutsForSource(string $elementType, string $sourceKey) } if (!isset($this->_fieldLayouts[$elementType][$sourceKey])) { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ $this->_fieldLayouts[$elementType][$sourceKey] = $elementType::fieldLayouts($sourceKey); } + return $this->_fieldLayouts[$elementType][$sourceKey]; } /** * Returns additional sort options that should be available for a given element source. * - * @param string $elementType The element type class - * @phpstan-param class-string $elementType + * @param class-string $elementType The element type class * @param string $sourceKey The element source key * @return array[] */ @@ -301,8 +294,7 @@ public function getSourceSortOptions(string $elementType, string $sourceKey): ar /** * Returns any table attributes that should be available for a given source, in addition to the [[getAvailableTableAttributes()|common attributes]]. * - * @param string $elementType The element type class - * @phpstan-param class-string $elementType + * @param class-string $elementType The element type class * @param string $sourceKey The element source key * @return array[] */ @@ -356,15 +348,12 @@ public function getSourceTableAttributes(string $elementType, string $sourceKey) /** * Returns the native sources for a given element type and context, normalized with `type` keys. * - * @param string $elementType - * @phpstan-param class-string $elementType + * @param class-string $elementType * @param string $context * @return array[] */ private function _nativeSources(string $elementType, string $context): array { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ $sources = $elementType::sources($context); $normalized = []; @@ -402,8 +391,7 @@ private function normalizeNativeSource(array &$source): void /** * Returns the source configs for a given element type. * - * @param string $elementType The element type class - * @phpstan-param class-string $elementType + * @param class-string $elementType The element type class * @return array[]|null */ private function _sourceConfigs(string $elementType): ?array @@ -414,8 +402,7 @@ private function _sourceConfigs(string $elementType): ?array /** * Returns the source config for a given native source key. * - * @param string $elementType - * @phpstan-param class-string $elementType + * @param class-string $elementType * @param string $sourceKey * @return array|null */ diff --git a/src/services/Elements.php b/src/services/Elements.php index 736b9a94e23..3e17f127039 100644 --- a/src/services/Elements.php +++ b/src/services/Elements.php @@ -482,7 +482,7 @@ class Elements extends Component * Creates an element with a given config. * * @template T of ElementInterface - * @param string|array $config The element’s class name, or its config, with a `type` value + * @param class-string|array $config The element’s class name, or its config, with a `type` value * @phpstan-param class-string|array{type:class-string} $config * @return T The element */ @@ -498,8 +498,7 @@ public function createElement(mixed $config): ElementInterface /** * Creates an element query for a given element type. * - * @param string $elementType The element class - * @phpstan-param class-string $elementType + * @param class-string $elementType The element class * @return ElementQueryInterface The element query * @throws InvalidArgumentException if $elementType is not a valid element * @since 3.5.0 @@ -744,8 +743,7 @@ public function invalidateAllCaches(): void /** * Invalidates caches for the given element type. * - * @param string $elementType - * @phpstan-param class-string $elementType + * @param class-string $elementType * @since 3.5.0 */ public function invalidateCachesForElementType(string $elementType): void @@ -814,8 +812,7 @@ public function invalidateCachesForElement(ElementInterface $element): void * * @template T of ElementInterface * @param int $elementId The element’s ID. - * @param string|null $elementType The element class. - * @phpstan-param class-string|null $elementType + * @param class-string|null $elementType The element class. * @param int|string|int[]|null $siteId The site(s) to fetch the element in. * Defaults to the current site. * @param array $criteria @@ -835,8 +832,7 @@ public function getElementById(int $elementId, ?string $elementType = null, arra * * @template T of ElementInterface * @param string $uid The element’s UID. - * @param string|null $elementType The element class. - * @phpstan-param class-string|null $elementType + * @param class-string|null $elementType The element class. * @param int|string|int[]|null $siteId The site(s) to fetch the element in. * Defaults to the current site. * @param array $criteria @@ -854,8 +850,7 @@ public function getElementByUid(string $uid, ?string $elementType = null, array| * @template T of ElementInterface * @param string $property Either `id` or `uid` * @param int|string $elementId The element’s ID/UID - * @param string|null $elementType The element class. - * @phpstan-param class-string|null $elementType + * @param class-string|null $elementType The element class. * @param int|string|int[]|null $siteId The site(s) to fetch the element in. * Defaults to the current site. * @param array $criteria @@ -2057,8 +2052,7 @@ public function mergeElements(ElementInterface $mergedElement, ElementInterface * Deletes an element by its ID. * * @param int $elementId The element’s ID - * @param string|null $elementType The element class. - * @phpstan-param class-string|null $elementType + * @param class-string|null $elementType The element class. * @param int|null $siteId The site to fetch the element in. * Defaults to the current site. * @param bool $hardDelete Whether the element should be hard-deleted immediately, instead of soft-deleted @@ -2585,7 +2579,7 @@ public function getAllElementTypes(): array * Creates an element action with a given config. * * @template T of ElementActionInterface - * @param string|array $config The element action’s class name, or its config, with a `type` value and optionally a `settings` value + * @param class-string|array $config The element action’s class name, or its config, with a `type` value and optionally a `settings` value * @phpstan-param class-string|array{type:class-string} $config * @return T The element action */ @@ -2598,7 +2592,7 @@ public function createAction(mixed $config): ElementActionInterface * Creates an element exporter with a given config. * * @template T of ElementExporterInterface - * @param string|array $config The element exporter’s class name, or its config, with a `type` value and optionally a `settings` value + * @param class-string|array $config The element exporter’s class name, or its config, with a `type` value and optionally a `settings` value * @phpstan-param class-string|array{type:class-string} $config * @return T The element exporter */ @@ -2643,8 +2637,7 @@ private function elementTypeByRefHandle(string $refHandle): string|false } foreach ($this->getAllElementTypes() as $class) { - /** @var string|ElementInterface $class */ - /** @phpstan-var class-string|ElementInterface $class */ + /** @var class-string $class */ if ( ($elementRefHandle = $class::refHandle()) !== null && strcasecmp($elementRefHandle, $refHandle) === 0 @@ -2924,8 +2917,7 @@ public function createEagerLoadingPlans(string|array $with): array /** * Eager-loads additional elements onto a given set of elements. * - * @param string $elementType The root element type class - * @phpstan-param class-string $elementType + * @param class-string $elementType The root element type class * @param ElementInterface[] $elements The root element models that should be updated with the eager-loaded elements * @param array|string|EagerLoadPlan[] $with Dot-delimited paths of the elements that should be eager-loaded into the root elements */ @@ -2943,8 +2935,7 @@ public function eagerLoadElements(string $elementType, array $elements, array|st } /** - * @param string $elementType - * @phpstan-param class-string $elementType + * @param class-string $elementType * @param ElementInterface[][] $elementsBySite * @param EagerLoadPlan[] $with */ diff --git a/src/services/Fields.php b/src/services/Fields.php index a23975cda2f..1148908decd 100644 --- a/src/services/Fields.php +++ b/src/services/Fields.php @@ -536,8 +536,7 @@ public function getCompatibleFieldTypes(FieldInterface $field, bool $includeCurr } foreach ($this->getAllFieldTypes() as $class) { - /** @var string|FieldInterface $class */ - /** @phpstan-var class-string|FieldInterface $class */ + /** @var class-string $class */ if ($class === get_class($field)) { if ($includeCurrent) { $types[] = $class; @@ -586,7 +585,7 @@ public function getCompatibleFieldTypes(FieldInterface $field, bool $includeCurr * Creates a field with a given config. * * @template T of FieldInterface - * @param string|array $config The field’s class name, or its config, with a `type` value and optionally a `settings` value + * @param class-string|array $config The field’s class name, or its config, with a `type` value and optionally a `settings` value * @phpstan-param class-string|array{type:class-string,id?:int|string,uid?:string} $config * @return T The field */ @@ -688,8 +687,7 @@ public function getFieldsWithoutContent(mixed $context = null): array /** * Returns all fields of a certain type. * - * @param string $type The field type - * @phpstan-param class-string $type + * @param class-string $type The field type * @param string|string[]|false|null $context The field context(s) to fetch fields from. Defaults to [[\craft\services\Content::$fieldContext]]. * Set to `false` to get all fields regardless of context. * @return FieldInterface[] The fields @@ -1148,8 +1146,7 @@ public function getLayoutsByIds(array $layoutIds): array /** * Returns a field layout by its associated element type. * - * @param string $type The associated element type - * @phpstan-param class-string $type + * @param class-string $type The associated element type * @return FieldLayout The field layout */ public function getLayoutByType(string $type): FieldLayout @@ -1161,8 +1158,7 @@ public function getLayoutByType(string $type): FieldLayout /** * Returns all of the field layouts associated with a given element type. * - * @param string $type - * @phpstan-param class-string $type + * @param class-string $type * @return FieldLayout[] The field layouts * @since 3.5.0 */ @@ -1490,8 +1486,7 @@ public function deleteLayout(FieldLayout $layout): bool /** * Deletes field layouts associated with a given element type. * - * @param string $type The element type - * @phpstan-param class-string $type + * @param class-string $type The element type * @return bool Whether the field layouts were deleted successfully */ public function deleteLayoutsByType(string $type): bool diff --git a/src/services/Fs.php b/src/services/Fs.php index 11800771b06..d8d31ef169b 100644 --- a/src/services/Fs.php +++ b/src/services/Fs.php @@ -218,7 +218,7 @@ public function saveFilesystem(FsInterface $fs, bool $runValidation = true): boo * Creates a filesystem from a given config. * * @template T as FsInterface - * @param string|array $config The filesystem’s class name, or its config, with a `type` value and optionally a `settings` value + * @param class-string|array $config The filesystem’s class name, or its config, with a `type` value and optionally a `settings` value * @phpstan-param class-string|array{type:class-string} $config * @return T The filesystem */ diff --git a/src/services/Gc.php b/src/services/Gc.php index 4289ca4ae62..0459ed9d34f 100644 --- a/src/services/Gc.php +++ b/src/services/Gc.php @@ -284,8 +284,7 @@ public function hardDelete(array|string $tables): void /** * Deletes elements that are missing data in the given element extension table. * - * @param string $elementType The element type - * @phpstan-param class-string $elementType + * @param class-string $elementType The element type * @param string $table The extension table name * @param string $fk The column name that contains the foreign key to `elements.id` * @since 3.6.6 @@ -530,8 +529,7 @@ private function _deleteOrphanedStructureElements(): void /** * Deletes field layouts that are no longer used. * - * @param string $elementType The element type - * @phpstan-param class-string $elementType + * @param class-string $elementType The element type * @param string $table The table name that contains a foreign key to `fieldlayouts.id` * @param string $fk The column name that contains the foreign key to `fieldlayouts.id` * @since 4.13.0 diff --git a/src/services/Gql.php b/src/services/Gql.php index 528f8f882ea..c1f03f73d5a 100644 --- a/src/services/Gql.php +++ b/src/services/Gql.php @@ -1143,15 +1143,12 @@ public function getSchemas(): array * Return the content arguments based on an element class and contexts for it. * * @param array $contexts - * @param string $elementType - * @phpstan-param class-string<\craft\base\ElementInterface> $elementType + * @param class-string $elementType * @return array */ public function getContentArguments(array $contexts, string $elementType): array { /** @var FieldLayoutBehavior[] $contexts */ - /** @var string|BaseElementInterface $elementType */ - /** @phpstan-var class-string|BaseElementInterface $elementType */ if (!array_key_exists($elementType, $this->_contentFieldCache)) { $elementQuery = Craft::$app->getElements()->createElementQuery($elementType); $contentArguments = []; @@ -1314,8 +1311,7 @@ private function _registerGqlTypes(): array $this->trigger(self::EVENT_REGISTER_GQL_TYPES, $event); foreach ($event->types as $type) { - /** @var string|SingularTypeInterface $type */ - /** @phpstan-var class-string|SingularTypeInterface $type */ + /** @var class-string $type */ TypeLoader::registerType($type::getName(), "$type::getType"); } diff --git a/src/services/ImageTransforms.php b/src/services/ImageTransforms.php index 6d0eadf015d..36cfb48c59e 100644 --- a/src/services/ImageTransforms.php +++ b/src/services/ImageTransforms.php @@ -463,8 +463,7 @@ public function eagerLoadTransforms(array $assets, array $transforms): void /** * @template T of ImageTransformerInterface - * @param string $type - * @phpstan-param class-string $type + * @param class-string $type * @param array $config * @return T * @throws InvalidConfigException diff --git a/src/services/Plugins.php b/src/services/Plugins.php index b0a2f2b7c1d..f1f861f459e 100644 --- a/src/services/Plugins.php +++ b/src/services/Plugins.php @@ -332,8 +332,7 @@ public function getPluginByPackageName(string $packageName): ?PluginInterface * * The plugin may not actually be installed. * - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return string|null The plugin handle, or null if it can’t be determined */ public function getPluginHandleByClass(string $class): ?string @@ -685,8 +684,7 @@ public function switchEdition(string $handle, string $edition): void { $info = $this->getPluginInfo($handle); - /** @var string|PluginInterface $class */ - /** @phpstan-var class-string|PluginInterface $class */ + /** @var class-string $class */ $class = $info['class']; if (!in_array($edition, $class::editions(), true)) { @@ -905,8 +903,7 @@ public function createPlugin(string $handle, ?array $info = null): ?PluginInterf unset($config['aliases']); } - /** @var string|PluginInterface $class */ - /** @phpstan-var class-string|PluginInterface $class */ + /** @var class-string $class */ $class = $config['class']; // Make sure the class exists and it implements PluginInterface diff --git a/src/services/Utilities.php b/src/services/Utilities.php index af93d821bca..6c2f39bd284 100644 --- a/src/services/Utilities.php +++ b/src/services/Utilities.php @@ -115,6 +115,7 @@ public function getAllUtilityTypes(): array * Returns all utility type classes that the user has permission to use. * * @return string[] + * @phpstan-return class-string[] */ public function getAuthorizedUtilityTypes(): array { @@ -132,14 +133,11 @@ public function getAuthorizedUtilityTypes(): array /** * Returns whether the current user is authorized to use a given utility. * - * @param string $class The utility class - * @phpstan-param class-string $class + * @param class-string $class The utility class * @return bool */ public function checkAuthorization(string $class): bool { - /** @var string|UtilityInterface $class */ - /** @phpstan-var class-string|UtilityInterface $class */ $utilityId = $class::id(); // The Project Config utility is for admins only! @@ -163,13 +161,12 @@ public function checkAuthorization(string $class): bool * Returns a utility class by its ID * * @param string $id - * @return string|null + * @return class-string|null */ public function getUtilityTypeById(string $id): ?string { foreach ($this->getAllUtilityTypes() as $class) { - /** @var string|UtilityInterface $class */ - /** @phpstan-var class-string|UtilityInterface $class */ + /** @var class-string $class */ if ($class::id() === $id) { return $class; } diff --git a/src/services/Webpack.php b/src/services/Webpack.php index 9ec57ce16e6..a4a5d669df7 100644 --- a/src/services/Webpack.php +++ b/src/services/Webpack.php @@ -58,8 +58,7 @@ class Webpack extends Component /** * Returns the environment file. * - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return string|null * @throws ReflectionException */ @@ -97,8 +96,7 @@ private function _getEnvFilePath(string $class): ?string } /** - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return string * @throws ReflectionException */ @@ -113,8 +111,7 @@ private function _getDirectory(string $class): string /** * Load the environment variables. * - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return array|null * @throws ReflectionException */ @@ -148,8 +145,7 @@ private function _getEnvVars(string $class): ?array } /** - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return string|null * @throws Exception */ @@ -159,8 +155,7 @@ private function _getDevServerLoopback(string $class): ?string } /** - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return string|null * @throws Exception */ @@ -172,8 +167,7 @@ private function _getDevServerPublic(string $class): ?string /** * Get the dev server public path. * - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return string * @throws Exception */ @@ -241,8 +235,7 @@ private function _isDevServerRunning(string $class, string $loopback): bool /** * @param array $json - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return bool */ private function _matchAsset(array $json, string $class): bool diff --git a/src/test/Craft.php b/src/test/Craft.php index 0219e070638..20775278efb 100644 --- a/src/test/Craft.php +++ b/src/test/Craft.php @@ -418,7 +418,7 @@ public function deleteElement(ElementInterface $element, bool $hardDelete = true } /** - * @param string $elementType + * @param class-string $elementType * @param array $searchProperties * @param int $amount * @param bool $searchAll Whether `status(null)` and `trashed(null)` should be applied @@ -426,8 +426,6 @@ public function deleteElement(ElementInterface $element, bool $hardDelete = true */ public function assertElementsExist(string $elementType, array $searchProperties = [], int $amount = 1, bool $searchAll = false): array { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ $elementQuery = $elementType::find(); if ($searchAll) { $elementQuery->status(null); @@ -680,8 +678,7 @@ protected function mockModulesAndPlugins(CodeceptionTestCase $test): void /** * @param CodeceptionTestCase $test - * @param string $moduleClass - * @phpstan-param class-string $moduleClass + * @param class-string $moduleClass * @throws ReflectionException */ protected function addModule(CodeceptionTestCase $test, string $moduleClass): void diff --git a/src/test/CraftConnector.php b/src/test/CraftConnector.php index aca1e93d6fa..c15ad7229bf 100644 --- a/src/test/CraftConnector.php +++ b/src/test/CraftConnector.php @@ -107,11 +107,8 @@ protected function resetRequest(Application $app): void $module = new $moduleClass($moduleId, Craft::$app); } - /** @var string|Module $moduleClass */ - /** @phpstan-var class-string|Module $moduleClass */ - $moduleClass::setInstance( - $module - ); + /** @var class-string $moduleClass */ + $moduleClass::setInstance($module); Craft::$app->setModule($moduleId, $module); } } diff --git a/src/test/TestCase.php b/src/test/TestCase.php index 23327579329..7cb8cea6169 100644 --- a/src/test/TestCase.php +++ b/src/test/TestCase.php @@ -35,8 +35,7 @@ public function _fixtures(): array /** * Returns a callable that checks whether the passed in object is an instance of the $class param * - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return callable */ public function assertObjectIsInstanceOfClassCallback(string $class): callable diff --git a/src/test/TestSetup.php b/src/test/TestSetup.php index 7b884a7d971..96936ba1017 100644 --- a/src/test/TestSetup.php +++ b/src/test/TestSetup.php @@ -172,8 +172,7 @@ public static function cleanseDb(Connection $connection): bool } /** - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @param array $params * @param bool $ignorePreviousMigrations * @return bool @@ -300,8 +299,7 @@ public static function appType(): string /** * @param string $preDefinedAppType - * @return string - * @phpstan-return class-string + * @return class-string */ public static function appClass(string $preDefinedAppType = ''): string { @@ -505,8 +503,7 @@ public static function setupCraftDb(Connection $connection): void * @template T of Module * @param CodeceptionTestCase $test * @param array $serviceMap - * @param string|null $moduleClass - * @phpstan-param class-string|null $moduleClass + * @param class-string|null $moduleClass * @return T * @credit https://github.com/nerds-and-company/schematic/blob/master/tests/_support/Helper/Unit.php */ @@ -551,8 +548,7 @@ public static function getMockModule(CodeceptionTestCase $test, array $serviceMa /** * @template T * @param CodeceptionTestCase $test - * @param string $class - * @phpstan-param class-string $class + * @param class-string $class * @return T|MockObject * @credit https://github.com/nerds-and-company/schematic/blob/master/tests/_support/Helper/Unit.php */ diff --git a/src/test/fixtures/elements/BaseContentFixture.php b/src/test/fixtures/elements/BaseContentFixture.php index bd6f4a1672b..48cd249dc8e 100644 --- a/src/test/fixtures/elements/BaseContentFixture.php +++ b/src/test/fixtures/elements/BaseContentFixture.php @@ -35,8 +35,7 @@ abstract class BaseContentFixture extends DbFixture use FileFixtureTrait; /** - * @var string The element type this is for - * @phpstan-var class-string + * @var class-string The element type this is for */ public string $elementType; diff --git a/src/test/mockclasses/elements/MockElementQuery.php b/src/test/mockclasses/elements/MockElementQuery.php index 1fd19897093..d19c68d7009 100644 --- a/src/test/mockclasses/elements/MockElementQuery.php +++ b/src/test/mockclasses/elements/MockElementQuery.php @@ -48,8 +48,7 @@ public function __construct() /** * Generate a more specific query class for the provided element type class. * - * @param string $elementClass - * @phpstan-param class-string $elementClass + * @param class-string $elementClass * @return ElementQuery */ public static function generateSpecificQueryClass(string $elementClass): ElementQuery diff --git a/src/web/assets/cp/CpAsset.php b/src/web/assets/cp/CpAsset.php index 7210f90642a..024d85d9d66 100644 --- a/src/web/assets/cp/CpAsset.php +++ b/src/web/assets/cp/CpAsset.php @@ -461,8 +461,7 @@ private function _craftData(): array $elementTypeNames = []; foreach (Craft::$app->getElements()->getAllElementTypes() as $elementType) { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ + /** @var class-string $elementType */ $elementTypeNames[$elementType] = [ $elementType::displayName(), $elementType::pluralDisplayName(), From 6af023ab38bb08e1d687ef62e2f641068b1953f1 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 20 Nov 2024 09:31:11 -0800 Subject: [PATCH 2/5] More class-string cleanup --- src/Craft.php | 2 +- .../utils/PruneProvisionalDraftsController.php | 2 +- .../controllers/utils/PruneRevisionsController.php | 2 +- src/controllers/AppController.php | 4 +--- src/controllers/ElementsController.php | 11 ++++++++++- src/controllers/StructuresController.php | 1 - src/elements/ElementCollection.php | 2 +- src/elements/actions/Delete.php | 13 ++++--------- src/elements/actions/DeleteForSite.php | 9 ++------- src/elements/conditions/StatusConditionRule.php | 4 +--- src/elements/db/ElementQuery.php | 2 -- src/fields/BaseRelationField.php | 2 -- src/fields/Matrix.php | 2 +- src/helpers/ElementHelper.php | 1 - src/services/Drafts.php | 2 +- src/services/ElementSources.php | 5 +---- src/services/Elements.php | 6 +----- src/services/Fields.php | 2 +- src/services/Gc.php | 2 -- src/services/Sites.php | 2 +- src/services/Utilities.php | 2 +- src/validators/UniqueValidator.php | 2 +- 22 files changed, 30 insertions(+), 50 deletions(-) diff --git a/src/Craft.php b/src/Craft.php index 4ef530b9b8d..3c03ca35a0b 100644 --- a/src/Craft.php +++ b/src/Craft.php @@ -243,7 +243,7 @@ private static function _autoloadCustomFieldBehavior(): void // Now generate it again, this time with the correct field value types $fieldHandles = []; foreach ($fields as $field) { - /** @var FieldInterface|string $fieldClass */ + /** @var class-string $fieldClass */ $fieldClass = $field['type']; if (Component::validateComponentClass($fieldClass, FieldInterface::class)) { $types = explode('|', $fieldClass::valueType()); diff --git a/src/console/controllers/utils/PruneProvisionalDraftsController.php b/src/console/controllers/utils/PruneProvisionalDraftsController.php index fee9c827e90..c8c1c45ca9f 100644 --- a/src/console/controllers/utils/PruneProvisionalDraftsController.php +++ b/src/console/controllers/utils/PruneProvisionalDraftsController.php @@ -82,7 +82,7 @@ public function actionIndex(): int continue; } - /** @var ElementInterface|string $elementType */ + /** @var class-string $elementType */ $elementType = $element['type']; $deleteCount = $element['count'] - 1; diff --git a/src/console/controllers/utils/PruneRevisionsController.php b/src/console/controllers/utils/PruneRevisionsController.php index ca8d678379e..a1448668ccc 100644 --- a/src/console/controllers/utils/PruneRevisionsController.php +++ b/src/console/controllers/utils/PruneRevisionsController.php @@ -125,7 +125,7 @@ public function actionIndex(): int continue; } - /** @var ElementInterface|string $elementType */ + /** @var class-string $elementType */ $elementType = $element['type']; $deleteCount = $element['count'] - $this->maxRevisions; diff --git a/src/controllers/AppController.php b/src/controllers/AppController.php index 04c7d775f56..30af6ba4288 100644 --- a/src/controllers/AppController.php +++ b/src/controllers/AppController.php @@ -751,11 +751,9 @@ public function actionRenderElement(): Response $this->requireCpRequest(); $this->requireAcceptsJson(); - /** @var string|ElementInterface $elementType */ + /** @var class-string $elementType */ $elementType = $this->request->getRequiredBodyParam('type'); $id = $this->request->getRequiredBodyParam('id'); - $draftId = $this->request->getBodyParam('draftId'); - $revisionId = $this->request->getBodyParam('revisionId'); $instances = $this->request->getRequiredBodyParam('instances'); if (!$id || !is_numeric($id)) { diff --git a/src/controllers/ElementsController.php b/src/controllers/ElementsController.php index 1e21e0ffe75..b219d41284c 100644 --- a/src/controllers/ElementsController.php +++ b/src/controllers/ElementsController.php @@ -1966,6 +1966,16 @@ private function _element( return $element; } + /** + * @param int|null $elementId + * @param string|null $elementUid + * @param bool $checkForProvisionalDraft + * @param class-string $elementType + * @param User $user + * @param int|array|null $siteId + * @param array|null $preferSites + * @return ElementInterface|null + */ private function _elementById( ?int $elementId, ?string $elementUid, @@ -1975,7 +1985,6 @@ private function _elementById( int|array|null $siteId, ?array $preferSites, ): ?ElementInterface { - /** @var string|ElementInterface $elementType */ if ($elementId) { // First check for a provisional draft, if we're open to it if ($checkForProvisionalDraft) { diff --git a/src/controllers/StructuresController.php b/src/controllers/StructuresController.php index 1c1b7ab57c8..46c82239bfb 100644 --- a/src/controllers/StructuresController.php +++ b/src/controllers/StructuresController.php @@ -70,7 +70,6 @@ public function beforeAction($action): bool throw new NotFoundHttpException('Element not found'); } - /** @var ElementInterface|string $elementType */ $this->_element = $elementType::find() ->drafts(null) ->provisionalDrafts(null) diff --git a/src/elements/ElementCollection.php b/src/elements/ElementCollection.php index f172b4502a8..7a8649fc69b 100644 --- a/src/elements/ElementCollection.php +++ b/src/elements/ElementCollection.php @@ -220,7 +220,7 @@ public function fresh(): static $freshElements = []; foreach ($idsByClass as $class => $ids) { - /** @var string|TElement $class */ + /** @var class-string|class-string $class */ $freshElements[$class] = $class::find() ->site('*') ->siteSettingsId($ids) diff --git a/src/elements/actions/Delete.php b/src/elements/actions/Delete.php index c739cd5cd88..7d3f58ff4bf 100644 --- a/src/elements/actions/Delete.php +++ b/src/elements/actions/Delete.php @@ -127,23 +127,20 @@ public function getConfirmationMessage(): ?string return $this->confirmationMessage; } - /** @var ElementInterface|string $elementType */ - $elementType = $this->elementType; - if ($this->hard) { return Craft::t('app', 'Are you sure you want to permanently delete the selected {type}?', [ - 'type' => $elementType::pluralLowerDisplayName(), + 'type' => $this->elementType::pluralLowerDisplayName(), ]); } if ($this->withDescendants) { return Craft::t('app', 'Are you sure you want to delete the selected {type} along with their descendants?', [ - 'type' => $elementType::pluralLowerDisplayName(), + 'type' => $this->elementType::pluralLowerDisplayName(), ]); } return Craft::t('app', 'Are you sure you want to delete the selected {type}?', [ - 'type' => $elementType::pluralLowerDisplayName(), + 'type' => $this->elementType::pluralLowerDisplayName(), ]); } @@ -196,10 +193,8 @@ public function performAction(ElementQueryInterface $query): bool if (isset($this->successMessage)) { $this->setMessage($this->successMessage); } else { - /** @var ElementInterface|string $elementType */ - $elementType = $this->elementType; $this->setMessage(Craft::t('app', '{type} deleted.', [ - 'type' => $elementType::pluralDisplayName(), + 'type' => $this->elementType::pluralDisplayName(), ])); } diff --git a/src/elements/actions/DeleteForSite.php b/src/elements/actions/DeleteForSite.php index 7c56972aeb4..0a995bb0bee 100644 --- a/src/elements/actions/DeleteForSite.php +++ b/src/elements/actions/DeleteForSite.php @@ -84,11 +84,8 @@ public function getConfirmationMessage(): ?string return $this->confirmationMessage; } - /** @var ElementInterface|string $elementType */ - $elementType = $this->elementType; - return Craft::t('app', 'Are you sure you want to delete the selected {type} for this site?', [ - 'type' => $elementType::pluralLowerDisplayName(), + 'type' => $this->elementType::pluralLowerDisplayName(), ]); } @@ -114,10 +111,8 @@ public function performAction(ElementQueryInterface $query): bool if (isset($this->successMessage)) { $this->setMessage($this->successMessage); } else { - /** @var ElementInterface|string $elementType */ - $elementType = $this->elementType; $this->setMessage(Craft::t('app', '{type} deleted for site.', [ - 'type' => $elementType::pluralDisplayName(), + 'type' => $this->elementType::pluralDisplayName(), ])); } diff --git a/src/elements/conditions/StatusConditionRule.php b/src/elements/conditions/StatusConditionRule.php index 5b5c1a9f6ca..c1cddb10fca 100644 --- a/src/elements/conditions/StatusConditionRule.php +++ b/src/elements/conditions/StatusConditionRule.php @@ -39,9 +39,7 @@ protected function options(): array { /** @var ElementCondition $condition */ $condition = $this->getCondition(); - /** @var ElementInterface|string $elementType */ - $elementType = $condition->elementType; - return array_map(fn($info) => $info['label'] ?? $info, $elementType::statuses()); + return array_map(fn($info) => $info['label'] ?? $info, $condition->elementType::statuses()); } /** diff --git a/src/elements/db/ElementQuery.php b/src/elements/db/ElementQuery.php index f043c6e5a8e..d965feddb2d 100644 --- a/src/elements/db/ElementQuery.php +++ b/src/elements/db/ElementQuery.php @@ -2882,8 +2882,6 @@ private function _normalizeStructureParamValue(string $property, string $class): throw new QueryAbortedException(); } - /** @var string|ElementInterface $class */ - /** @phpstan-var class-string|ElementInterface $class */ if ($element instanceof ElementInterface && !$element->lft) { $element = $element->getCanonicalId(); diff --git a/src/fields/BaseRelationField.php b/src/fields/BaseRelationField.php index 9794c7d6990..c8e8f1be66a 100644 --- a/src/fields/BaseRelationField.php +++ b/src/fields/BaseRelationField.php @@ -526,7 +526,6 @@ public function validateRelatedElements(ElementInterface $element): void } if ($errorCount) { - /** @var ElementInterface|string $elementType */ $elementType = static::elementType(); $element->addError($this->handle, Craft::t('app', 'Validation errors found in {attribute} {type}; please fix them.', [ 'type' => $errorCount === 1 ? $elementType::lowerDisplayName() : $elementType::pluralLowerDisplayName(), @@ -1175,7 +1174,6 @@ public function useFieldset(): bool */ protected function settingsTemplateVariables(): array { - /** @var ElementInterface|string $elementType */ $elementType = $this->elementType(); $selectionCondition = $this->getSelectionCondition() ?? $this->createSelectionCondition(); diff --git a/src/fields/Matrix.php b/src/fields/Matrix.php index 05d051f8955..d328a3a33ca 100644 --- a/src/fields/Matrix.php +++ b/src/fields/Matrix.php @@ -1202,7 +1202,7 @@ private function _getFieldOptionsForConfigurator(): array $fieldTypes = []; foreach (Craft::$app->getFields()->getAllFieldTypes() as $class) { - /** @var FieldInterface|string $class */ + /** @var class-string $class */ // No Matrix-Inception, sorry buddy. if ($class === self::class) { continue; diff --git a/src/helpers/ElementHelper.php b/src/helpers/ElementHelper.php index 01de696272e..795d680ea18 100644 --- a/src/helpers/ElementHelper.php +++ b/src/helpers/ElementHelper.php @@ -667,7 +667,6 @@ public static function findSource(string $elementType, string $sourceKey, string if (!str_starts_with($sourceKey, 'custom:')) { // Let the element get involved - /** @var string|ElementInterface $elementType */ $source = $elementType::findSource($sourceKey, $context); if ($source) { $source['type'] = ElementSources::TYPE_NATIVE; diff --git a/src/services/Drafts.php b/src/services/Drafts.php index d8fddd5ed3e..33e3b446b26 100644 --- a/src/services/Drafts.php +++ b/src/services/Drafts.php @@ -423,7 +423,7 @@ public function purgeUnsavedDrafts(): void $elementsService = Craft::$app->getElements(); foreach ($drafts as $draftInfo) { - /** @var ElementInterface|string $elementType */ + /** @var class-string $elementType */ $elementType = $draftInfo['type']; $draft = $elementType::find() ->draftId($draftInfo['draftId']) diff --git a/src/services/ElementSources.php b/src/services/ElementSources.php index b1b008eecf3..aaae7ba8678 100644 --- a/src/services/ElementSources.php +++ b/src/services/ElementSources.php @@ -74,7 +74,6 @@ public static function filterExtraHeadings(array $sources): array */ public function getSources(string $elementType, string $context = self::CONTEXT_INDEX, bool $withDisabled = false): array { - /** @var string|ElementInterface $elementType */ $nativeSources = $this->_nativeSources($elementType, $context); $sourceConfigs = $this->_sourceConfigs($elementType); @@ -188,15 +187,13 @@ public function getAvailableTableAttributes(string $elementType): array /** * Returns the attributes that should be shown for a given element type source. * - * @param string $elementType The element type class - * @phpstan-param class-string $elementType + * @param class-string $elementType The element type class * @param string $sourceKey The element type source key * @param string[]|null $customAttributes Custom attributes to show rather than the defaults * @return array[] */ public function getTableAttributes(string $elementType, string $sourceKey, ?array $customAttributes = null): array { - /** @var ElementInterface|string $elementType */ // If this is a source path, use the first segment if (($slash = strpos($sourceKey, '/')) !== false) { $sourceKey = substr($sourceKey, 0, $slash); diff --git a/src/services/Elements.php b/src/services/Elements.php index 3e17f127039..cd5933a83bf 100644 --- a/src/services/Elements.php +++ b/src/services/Elements.php @@ -946,7 +946,7 @@ public function getElementByUri(string $uri, ?int $siteId = null, bool $enabledO * Returns the class of an element with a given ID. * * @param int $elementId The element’s ID - * @return string|null The element’s class, or null if it could not be found + * @return class-string|null The element’s class, or null if it could not be found */ public function getElementTypeById(int $elementId): ?string { @@ -1474,7 +1474,6 @@ 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; - /** @var string|ElementInterface $elementType */ $elementType = get_class($element); $e = null; @@ -2009,7 +2008,6 @@ public function mergeElements(ElementInterface $mergedElement, ElementInterface } // Update any reference tags - /** @var ElementInterface|null $elementType */ $elementType = $this->getElementTypeById($prevailingElement->id); if ($elementType !== null && ($refHandle = $elementType::refHandle()) !== null) { @@ -2923,7 +2921,6 @@ public function createEagerLoadingPlans(string|array $with): array */ public function eagerLoadElements(string $elementType, array $elements, array|string $with): void { - /** @var ElementInterface|string $elementType */ // Bail if there aren't even any elements if (empty($elements)) { return; @@ -2965,7 +2962,6 @@ private function _eagerLoadElementsInternal(string $elementType, array $elements } // Get the eager-loading map from the source element type - /** @var ElementInterface|string $elementType */ $map = $elementType::eagerLoadingMap($filteredElements, $plan->handle); if ($map === null) { diff --git a/src/services/Fields.php b/src/services/Fields.php index 1148908decd..acc5936f29a 100644 --- a/src/services/Fields.php +++ b/src/services/Fields.php @@ -503,7 +503,7 @@ public function getFieldTypesWithContent(): array $fieldTypes = []; foreach ($this->getAllFieldTypes() as $fieldType) { - /** @var FieldInterface|string $fieldType */ + /** @var class-string $fieldType */ if ($fieldType::hasContentColumn()) { $fieldTypes[] = $fieldType; } diff --git a/src/services/Gc.php b/src/services/Gc.php index 0459ed9d34f..7c6fc367d84 100644 --- a/src/services/Gc.php +++ b/src/services/Gc.php @@ -291,7 +291,6 @@ public function hardDelete(array|string $tables): void */ public function deletePartialElements(string $elementType, string $table, string $fk): void { - /** @var string|ElementInterface $elementType */ $this->_stdout(sprintf(' > deleting partial %s data ... ', $elementType::lowerDisplayName())); $ids = (new Query()) @@ -536,7 +535,6 @@ private function _deleteOrphanedStructureElements(): void */ public function deleteOrphanedFieldLayouts(string $elementType, string $table, string $fk = 'fieldLayoutId'): void { - /** @var string|ElementInterface $elementType */ $this->_stdout(sprintf(' > deleting orphaned %s field layouts ... ', $elementType::lowerDisplayName())); $ids = (new Query()) diff --git a/src/services/Sites.php b/src/services/Sites.php index 7df4199ea6a..d6eb4e82180 100644 --- a/src/services/Sites.php +++ b/src/services/Sites.php @@ -1322,7 +1322,7 @@ private function _processNewPrimarySite(int $oldPrimarySiteId, int $newPrimarySi $nonLocalizedElementTypes = []; foreach (Craft::$app->getElements()->getAllElementTypes() as $elementType) { - /** @var ElementInterface|string $elementType */ + /** @var class-string $elementType */ if (!$elementType::isLocalized()) { $nonLocalizedElementTypes[] = $elementType; } diff --git a/src/services/Utilities.php b/src/services/Utilities.php index 6c2f39bd284..e78c34353bb 100644 --- a/src/services/Utilities.php +++ b/src/services/Utilities.php @@ -106,7 +106,7 @@ public function getAllUtilityTypes(): array $disabledUtilities = array_flip($generalConfig->disabledUtilities); return array_values(array_filter($event->types, function(string $class) use ($disabledUtilities) { - /** @var string|UtilityInterface $class */ + /** @var class-string $class */ return !isset($disabledUtilities[$class::id()]); })); } diff --git a/src/validators/UniqueValidator.php b/src/validators/UniqueValidator.php index 9efc74a2808..f577e5851fa 100644 --- a/src/validators/UniqueValidator.php +++ b/src/validators/UniqueValidator.php @@ -50,7 +50,7 @@ public function validateAttribute($model, $attribute): void { if ($targetClass = $this->targetClass) { // Exclude this model's row using the filter - /** @var ActiveRecord|string $targetClass */ + /** @var class-string $targetClass */ $pks = $targetClass::primaryKey(); if (isset($this->pk)) { $pkMap = is_string($this->pk) ? StringHelper::split($this->pk) : $this->pk; From 23ee6c86b3961cd32591e0468a7b7c05f2069ac3 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 20 Nov 2024 09:40:00 -0800 Subject: [PATCH 3/5] Couple more [ci skip] --- src/services/Fields.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/services/Fields.php b/src/services/Fields.php index acc5936f29a..55288473999 100644 --- a/src/services/Fields.php +++ b/src/services/Fields.php @@ -497,6 +497,7 @@ public function getAllFieldTypes(): array * Returns all field types that have a column in the content table. * * @return string[] The field type classes + * @phpstan-return class-string[] */ public function getFieldTypesWithContent(): array { @@ -518,6 +519,7 @@ public function getFieldTypesWithContent(): array * @param FieldInterface $field The current field to base compatible fields on * @param bool $includeCurrent Whether $field's class should be included * @return string[] The compatible field type classes + * @phpstan-return class-string[] */ public function getCompatibleFieldTypes(FieldInterface $field, bool $includeCurrent = true): array { From befd9c9b942f62410cce75f7c490df51bbf111a9 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 20 Nov 2024 10:12:26 -0800 Subject: [PATCH 4/5] Another class-string [ci skip] --- src/services/Gql.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/Gql.php b/src/services/Gql.php index c1f03f73d5a..06d5188d15b 100644 --- a/src/services/Gql.php +++ b/src/services/Gql.php @@ -1380,6 +1380,7 @@ private function _registerGqlMutations(): void */ private function _loadGqlDirectives(): array { + /** @var class-string[] $directiveClasses */ $directiveClasses = [ // Directives FormatDateTime::class, @@ -1403,7 +1404,7 @@ private function _loadGqlDirectives(): array $directives = GraphQL::getStandardDirectives(); foreach ($event->directives as $directive) { - /** @var Directive $directive */ + /** @var class-string $directive */ $directives[] = $directive::create(); } From 67ef51c994d73f749d45ad5fdc7829ed319a7cf5 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 20 Nov 2024 10:12:41 -0800 Subject: [PATCH 5/5] More class-string cleanup --- src/console/controllers/FieldsController.php | 5 +--- src/controllers/AppController.php | 2 +- src/controllers/ElementIndexesController.php | 9 ++---- src/controllers/ElementsController.php | 5 +++- src/controllers/FieldsController.php | 4 +-- src/controllers/NestedElementsController.php | 2 +- src/elements/NestedElementManager.php | 28 ++++++------------- src/elements/actions/MoveToSection.php | 7 +---- src/elements/actions/ShowInFolder.php | 7 +---- src/fields/Link.php | 12 +++----- src/fields/linktypes/BaseElementLinkType.php | 3 +- .../BaseContentRefactorMigration.php | 1 - src/services/Elements.php | 1 - src/services/Fields.php | 6 ++-- src/services/Gc.php | 4 +-- src/services/Gql.php | 3 +- 16 files changed, 31 insertions(+), 68 deletions(-) diff --git a/src/console/controllers/FieldsController.php b/src/console/controllers/FieldsController.php index 607cd9ed290..cb65e63fa03 100644 --- a/src/console/controllers/FieldsController.php +++ b/src/console/controllers/FieldsController.php @@ -8,7 +8,6 @@ namespace craft\console\controllers; use Craft; -use craft\base\ElementInterface; use craft\base\FieldInterface; use craft\base\MergeableFieldInterface; use craft\console\Controller; @@ -381,9 +380,7 @@ private function usagesDescriptor(array $layouts): string private function layoutDescriptor(FieldLayout $layout): string { - /** @var string|ElementInterface $elementType */ - $elementType = $layout->type; - $elementDisplayName = $elementType::lowerDisplayName(); + $elementDisplayName = $layout->type::lowerDisplayName(); $providerHandle = $layout->provider?->getHandle(); return $providerHandle ? "the `$providerHandle` $elementDisplayName layout" diff --git a/src/controllers/AppController.php b/src/controllers/AppController.php index 47da3087b46..002ca050341 100644 --- a/src/controllers/AppController.php +++ b/src/controllers/AppController.php @@ -832,7 +832,7 @@ public function actionRenderComponents(): Response $menuItemHtml = []; foreach ($components as $componentInfo) { - /** @var string|Chippable $componentType */ + /** @var class-string $componentType */ $componentType = $componentInfo['type']; $id = $componentInfo['id']; diff --git a/src/controllers/ElementIndexesController.php b/src/controllers/ElementIndexesController.php index 3413bea5776..381171778a0 100644 --- a/src/controllers/ElementIndexesController.php +++ b/src/controllers/ElementIndexesController.php @@ -507,13 +507,11 @@ public function actionSaveElements(): Response $user = static::currentUser(); // get all the elements - /** @var string|ElementInterface $elementType */ - $elementType = $this->elementType(); $elementIds = array_map( fn(string $key) => (int)StringHelper::removeLeft($key, 'element-'), array_keys($data), ); - $elements = $elementType::find() + $elements = $this->elementType()::find() ->id($elementIds) ->status(null) ->drafts(null) @@ -612,14 +610,11 @@ protected function source(): ?array } if ($this->sourceKey === '__IMP__') { - /** @var ElementInterface|string $elementType */ - $elementType = $this->elementType; - return [ 'type' => ElementSources::TYPE_NATIVE, 'key' => '__IMP__', 'label' => Craft::t('app', 'All elements'), - 'hasThumbs' => $elementType::hasThumbs(), + 'hasThumbs' => $this->elementType::hasThumbs(), ]; } diff --git a/src/controllers/ElementsController.php b/src/controllers/ElementsController.php index 220cd219ebc..a976d048c1b 100644 --- a/src/controllers/ElementsController.php +++ b/src/controllers/ElementsController.php @@ -2370,9 +2370,12 @@ private function _elementById( return null; } + /** + * @param class-string $elementType + * @return ElementQueryInterface + */ private function _elementQuery(string $elementType): ElementQueryInterface { - /** @var string|ElementInterface $elementType */ $query = $elementType::find(); if ($query instanceof NestedElementQueryInterface) { $query diff --git a/src/controllers/FieldsController.php b/src/controllers/FieldsController.php index e8eb53a450f..21c9d46434d 100644 --- a/src/controllers/FieldsController.php +++ b/src/controllers/FieldsController.php @@ -241,7 +241,7 @@ public function actionEditField(?int $fieldId = null, ?FieldInterface $field = n // re-fetch as many of these as we can from the element types, // so they have a chance to supply the layout providers foreach ($layoutsByType as $type => &$typeLayouts) { - /** @var string|ElementInterface $type */ + /** @var class-string $type */ /** @phpstan-ignore-next-line */ foreach ($type::fieldLayouts(null) as $layout) { if (isset($typeLayouts[$layout->uid]) && $layout->provider instanceof Chippable) { @@ -289,7 +289,7 @@ public function actionEditField(?int $fieldId = null, ?FieldInterface $field = n foreach ($layoutsByType as $type => $typeLayouts) { // any remaining layouts for this type? if (!empty($typeLayouts)) { - /** @var string|ElementInterface $type */ + /** @var class-string $type */ $items[] = Craft::t('app', '{total, number} {type} {total, plural, =1{field layout} other{field layouts}}', [ 'total' => count($typeLayouts), 'type' => $type::lowerDisplayName(), diff --git a/src/controllers/NestedElementsController.php b/src/controllers/NestedElementsController.php index 2b5249bb1d0..2562b84047d 100644 --- a/src/controllers/NestedElementsController.php +++ b/src/controllers/NestedElementsController.php @@ -42,7 +42,7 @@ public function beforeAction($action): bool $this->requireCpRequest(); // Get the owner element - /** @var ElementInterface|string $ownerElementType */ + /** @var class-string $ownerElementType */ $ownerElementType = $this->request->getRequiredBodyParam('ownerElementType'); $ownerId = $this->request->getRequiredBodyParam('ownerId'); $ownerSiteId = $this->request->getRequiredBodyParam('ownerSiteId'); diff --git a/src/elements/NestedElementManager.php b/src/elements/NestedElementManager.php index a26861b4651..91110fb9567 100644 --- a/src/elements/NestedElementManager.php +++ b/src/elements/NestedElementManager.php @@ -270,25 +270,22 @@ public function getTranslationDescription(?ElementInterface $owner = null): ?str return null; } - /** @var NestedElementInterface|string $elementType */ - $elementType = $this->elementType; - switch ($this->propagationMethod) { case PropagationMethod::None: return Craft::t('app', '{type} will only be saved in the {site} site.', [ - 'type' => $elementType::pluralDisplayName(), + 'type' => $this->elementType::pluralDisplayName(), 'site' => Craft::t('site', $owner->getSite()->getName()), ]); case PropagationMethod::SiteGroup: return Craft::t('app', '{type} will be saved across all sites in the {group} site group.', [ - 'type' => $elementType::pluralDisplayName(), + 'type' => $this->elementType::pluralDisplayName(), 'group' => Craft::t('site', $owner->getSite()->getGroup()->getName()), ]); case PropagationMethod::Language: $language = Craft::$app->getI18n()->getLocaleById($owner->getSite()->language) ->getDisplayName(Craft::$app->language); return Craft::t('app', '{type} will be saved across all {language}-language sites.', [ - 'type' => $elementType::pluralDisplayName(), + 'type' => $this->elementType::pluralDisplayName(), 'language' => $language, ]); default: @@ -371,15 +368,12 @@ public function getCardsHtml(?ElementInterface $owner, array $config = []): stri $config, self::VIEW_MODE_CARDS, function(string $id, array $config, $attribute, &$settings) use ($owner) { - /** @var NestedElementInterface|string $elementType */ - $elementType = $this->elementType; - $settings += [ 'deleteLabel' => Craft::t('app', 'Delete {type}', [ - 'type' => $elementType::lowerDisplayName(), + 'type' => $this->elementType::lowerDisplayName(), ]), 'deleteConfirmationMessage' => Craft::t('app', 'Are you sure you want to delete the selected {type}?', [ - 'type' => $elementType::lowerDisplayName(), + 'type' => $this->elementType::lowerDisplayName(), ]), 'showInGrid' => $config['showInGrid'], ]; @@ -491,8 +485,6 @@ public function getIndexHtml(?ElementInterface $owner, array $config = []): stri $config, self::VIEW_MODE_INDEX, function(string $id, array $config, string $attribute, array &$settings) use ($owner): string { - /** @var NestedElementInterface|string $elementType */ - $elementType = $this->elementType; $view = Craft::$app->getView(); $criteria = [ @@ -514,7 +506,7 @@ function(string $id, array $config, string $attribute, array &$settings) use ($o 'criteria' => array_merge($criteria, $this->criteria), 'batchSize' => $config['pageSize'], 'actions' => [], - 'canHaveDrafts' => $config['canHaveDrafts'] ?? $elementType::hasDrafts(), + 'canHaveDrafts' => $config['canHaveDrafts'] ?? $this->elementType::hasDrafts(), 'storageKey' => $config['storageKey'], 'static' => $config['static'], ]; @@ -544,12 +536,9 @@ function(string $id, array $config, string $attribute, array &$settings) use ($o private function createView(?ElementInterface $owner, array $config, string $mode, callable $renderHtml): string { - /** @var NestedElementInterface|string $elementType */ - $elementType = $this->elementType; - if (!$owner?->id) { $message = Craft::t('app', '{nestedType} can only be created after the {ownerType} has been saved.', [ - 'nestedType' => $elementType::pluralDisplayName(), + 'nestedType' => $this->elementType::pluralDisplayName(), 'ownerType' => $owner ? $owner::lowerDisplayName() : Craft::t('app', 'element'), ]); return Html::tag('div', $message, ['class' => 'pane no-border zilch small']); @@ -566,7 +555,7 @@ private function createView(?ElementInterface $owner, array $config, string $mod if ($config['createButtonLabel'] === null) { $config['createButtonLabel'] = Craft::t('app', 'New {type}', [ - 'type' => $elementType::lowerDisplayName(), + 'type' => $this->elementType::lowerDisplayName(), ]); } @@ -583,7 +572,6 @@ private function createView(?ElementInterface $owner, array $config, string $mod $view = Craft::$app->getView(); return $view->namespaceInputs(function() use ( $mode, - $elementType, $attribute, $view, $owner, diff --git a/src/elements/actions/MoveToSection.php b/src/elements/actions/MoveToSection.php index 07dd596c6a5..0e8dd74293c 100644 --- a/src/elements/actions/MoveToSection.php +++ b/src/elements/actions/MoveToSection.php @@ -9,7 +9,6 @@ use Craft; use craft\base\ElementAction; -use craft\base\ElementInterface; use craft\elements\Entry; use yii\base\Exception; @@ -34,11 +33,7 @@ public function getTriggerLabel(): string */ public function getTriggerHtml(): ?string { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; - - if ($elementType !== Entry::class) { + if ($this->elementType !== Entry::class) { throw new Exception("Move to section is only available for Entries."); } diff --git a/src/elements/actions/ShowInFolder.php b/src/elements/actions/ShowInFolder.php index 3efb724f8a8..4ca26c0bde2 100644 --- a/src/elements/actions/ShowInFolder.php +++ b/src/elements/actions/ShowInFolder.php @@ -9,7 +9,6 @@ use Craft; use craft\base\ElementAction; -use craft\base\ElementInterface; use craft\elements\Asset; use yii\base\Exception; @@ -34,11 +33,7 @@ public function getTriggerLabel(): string */ public function getTriggerHtml(): ?string { - /** @var string|ElementInterface $elementType */ - /** @phpstan-var class-string|ElementInterface $elementType */ - $elementType = $this->elementType; - - if ($elementType !== Asset::class) { + if ($this->elementType !== Asset::class) { throw new Exception("Show in folder is only available for Assets."); } diff --git a/src/fields/Link.php b/src/fields/Link.php index c0f9fcf1244..b1cba9894f3 100644 --- a/src/fields/Link.php +++ b/src/fields/Link.php @@ -101,14 +101,12 @@ public static function dbType(): array } /** - * @return array - * @phpstan-return array> + * @return array> */ private static function types(): array { if (!isset(self::$_types)) { - /** @var array $types */ - /** @phpstan-var class-string[] $types */ + /** @var class-string[] $types */ $types = [ Asset::class, Category::class, @@ -295,10 +293,8 @@ public function getSettingsHtml(): ?string }) // and sort them by label, with URL at the top ->sort(function(string $a, string $b) { - /** @var string|BaseLinkType $a */ - /** @var string|BaseLinkType $b */ - /** @phpstan-var class-string $a */ - /** @phpstan-var class-string $b */ + /** @var class-string $a */ + /** @var class-string $b */ if ($a === UrlType::class) { return -1; } diff --git a/src/fields/linktypes/BaseElementLinkType.php b/src/fields/linktypes/BaseElementLinkType.php index 6376222b9b3..ab1aa124a3d 100644 --- a/src/fields/linktypes/BaseElementLinkType.php +++ b/src/fields/linktypes/BaseElementLinkType.php @@ -32,8 +32,7 @@ abstract class BaseElementLinkType extends BaseLinkType /** * Returns the element type this link type is for. * - * @return ElementInterface|string - * @phpstan-return class-string + * @return class-string */ abstract protected static function elementType(): string; diff --git a/src/migrations/BaseContentRefactorMigration.php b/src/migrations/BaseContentRefactorMigration.php index 981c80086ca..5f2907a162c 100644 --- a/src/migrations/BaseContentRefactorMigration.php +++ b/src/migrations/BaseContentRefactorMigration.php @@ -209,7 +209,6 @@ private function elementLabel(array $element): string { $elementType = $element['type']; if ($elementType && class_exists($elementType) && is_subclass_of($elementType, ElementInterface::class)) { - /** @var string|ElementInterface $elementType */ $label = $elementType::lowerDisplayName(); } else { $label = 'element'; diff --git a/src/services/Elements.php b/src/services/Elements.php index 97e9c449c03..b686e142a88 100644 --- a/src/services/Elements.php +++ b/src/services/Elements.php @@ -1676,7 +1676,6 @@ 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; - /** @var string|ElementInterface $elementType */ $elementType = get_class($element); $e = null; diff --git a/src/services/Fields.php b/src/services/Fields.php index 2dfd4e0ec64..79bdf18768f 100644 --- a/src/services/Fields.php +++ b/src/services/Fields.php @@ -322,10 +322,8 @@ public function getCompatibleFieldTypes(FieldInterface $field, bool $includeCurr /** * Returns whether the two given field types are considered compatible with each other. * - * @param string|FieldInterface $fieldA - * @param string|FieldInterface $fieldB - * @phpstan-param class-string $fieldA - * @phpstan-param class-string $fieldB + * @param class-string $fieldA + * @param class-string $fieldB * @return bool * @since 5.3.0 */ diff --git a/src/services/Gc.php b/src/services/Gc.php index 9cc161e629f..5bfc7f319fb 100644 --- a/src/services/Gc.php +++ b/src/services/Gc.php @@ -490,15 +490,13 @@ private function _deleteUnsupportedSiteEntries(): void * Deletes elements which have a `fieldId` value, but it’s set to an invalid field ID, * or they're missing a row in the `elements_owners` table. * - * @param string $elementType The element type - * @phpstan-param class-string $elementType + * @param class-string $elementType The element type * @param string $table The extension table name * @param string $fieldFk The column name that contains the foreign key to `fields.id` * @since 5.4.2 */ public function deleteOrphanedNestedElements(string $elementType, string $table, string $fieldFk = 'fieldId'): void { - /** @var string|ElementInterface $elementType */ $this->_stdout(sprintf(' > deleting orphaned nested %s ... ', $elementType::pluralLowerDisplayName())); $ids1 = (new Query()) diff --git a/src/services/Gql.php b/src/services/Gql.php index 3ad3a3c3095..cb8886a3dab 100644 --- a/src/services/Gql.php +++ b/src/services/Gql.php @@ -1465,6 +1465,7 @@ private function _registerGqlMutations(): void */ private function _loadGqlDirectives(): array { + /** @var class-string[] $directiveClasses */ $directiveClasses = [ // Directives FormatDateTime::class, @@ -1489,7 +1490,7 @@ private function _loadGqlDirectives(): array $directives = GraphQL::getStandardDirectives(); foreach ($directiveClasses as $class) { - /** @var Directive|string $class */ + /** @var class-string $class */ $directives[] = $class::create(); }