Skip to content

Commit

Permalink
Merge pull request #392 from alies-dev/use-override
Browse files Browse the repository at this point in the history
Add and use `#[\Override]` attribute
  • Loading branch information
alies-dev authored Feb 23, 2025
2 parents 9e15de8 + eb50da4 commit f5288a8
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Fakes/FakeFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final class FakeFilesystem extends Filesystem
* @param string $contents
* @param bool $lock
*/
#[\Override]
public function put($path, $contents, $lock = false): bool|int
{
$destination = $this->destination ?? $path;
Expand Down
1 change: 1 addition & 0 deletions src/Fakes/FakeModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function getModels(): array
*
* @param Model $model
*/
#[\Override]
public function getPropertiesFromTable($model): void
{
$table_name = $model->getTable();
Expand Down
5 changes: 5 additions & 0 deletions src/Handlers/Application/ContainerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
final class ContainerHandler implements AfterClassLikeVisitInterface, FunctionReturnTypeProviderInterface, MethodReturnTypeProviderInterface
{
/** @inheritDoc */
#[\Override]
public static function getFunctionIds(): array
{
return ['app', 'resolve'];
}

/** @inheritDoc */
#[\Override]
public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $event): ?Union
{
$call_args = $event->getCallArgs();
Expand All @@ -51,11 +53,13 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
}

/** @inheritDoc */
#[\Override]
public static function getClassLikeNames(): array
{
return [ApplicationProvider::getAppFullyQualifiedClassName()];
}

#[\Override]
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Type\Union
{
return ContainerResolver::resolvePsalmTypeFromApplicationContainerViaArgs($event->getSource()->getNodeTypeProvider(), $event->getCallArgs());
Expand All @@ -65,6 +69,7 @@ public static function getMethodReturnType(MethodReturnTypeProviderEvent $event)
* @see https://github.com/psalm/psalm-plugin-symfony/issues/25
* psalm needs to know about any classes that could be returned before analysis begins. This is a naive first approach
*/
#[\Override]
public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void
{
if (!in_array($event->getStorage()->name, ApplicationInterfaceProvider::getApplicationInterfaceClassLikes(), true)) {
Expand Down
5 changes: 5 additions & 0 deletions src/Handlers/Application/OffsetHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ final class OffsetHandler implements
MethodParamsProviderInterface
{
/** @return list<class-string> */
#[\Override]
public static function getClassLikeNames(): array
{
return ApplicationInterfaceProvider::getApplicationInterfaceClassLikes();
}

#[\Override]
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Type\Union
{
$method_name_lowercase = $event->getMethodNameLowercase();
Expand All @@ -55,16 +57,19 @@ public static function getMethodReturnType(MethodReturnTypeProviderEvent $event)
return null;
}

#[\Override]
public static function doesMethodExist(MethodExistenceProviderEvent $event): ?bool
{
return self::isOffsetMethod($event->getMethodNameLowercase()) ? true : null;
}

#[\Override]
public static function isMethodVisible(MethodVisibilityProviderEvent $event): ?bool
{
return self::isOffsetMethod($event->getMethodNameLowercase()) ? true : null;
}

#[\Override]
public static function getMethodParams(MethodParamsProviderEvent $event): ?array
{
$source = $event->getStatementsSource();
Expand Down
2 changes: 2 additions & 0 deletions src/Handlers/Auth/GuardHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ final class GuardHandler implements MethodReturnTypeProviderInterface
use ExtractsGuardNameFromCallLike;

/** @inheritDoc */
#[\Override]
public static function getClassLikeNames(): array
{
return [\Illuminate\Contracts\Auth\Guard::class];
}

/** @inheritDoc */
#[\Override]
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Type\Union
{
$method_name_lowercase = $event->getMethodNameLowercase();
Expand Down
2 changes: 2 additions & 0 deletions src/Handlers/Auth/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ final class RequestHandler implements MethodReturnTypeProviderInterface
use ExtractsGuardNameFromCallLike;

/** @inheritDoc */
#[\Override]
public static function getClassLikeNames(): array
{
return [\Illuminate\Http\Request::class];
}

/** @inheritDoc */
#[\Override]
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Type\Union
{
if ($event->getMethodNameLowercase() !== 'user') {
Expand Down
3 changes: 3 additions & 0 deletions src/Handlers/Eloquent/ModelMethodHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
final class ModelMethodHandler implements MethodReturnTypeProviderInterface, AfterClassLikeVisitInterface
{
/** @inheritDoc */
#[\Override]
public static function getClassLikeNames(): array
{
return [Model::class];
}

/** @inheritDoc */
#[\Override]
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Type\Union
{
$source = $event->getSource();
Expand Down Expand Up @@ -85,6 +87,7 @@ public static function getMethodReturnType(MethodReturnTypeProviderEvent $event)
}

/** @inheritDoc */
#[\Override]
public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void
{
$storage = $event->getStorage();
Expand Down
4 changes: 4 additions & 0 deletions src/Handlers/Eloquent/ModelPropertyAccessorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
final class ModelPropertyAccessorHandler implements PropertyExistenceProviderInterface, PropertyVisibilityProviderInterface, PropertyTypeProviderInterface
{
/** @inheritDoc */
#[\Override]
public static function getClassLikeNames(): array
{
return ModelStubProvider::getModelClasses();
}

/** @inheritDoc */
#[\Override]
public static function doesPropertyExist(PropertyExistenceProviderEvent $event): ?bool
{
$source = $event->getSource();
Expand All @@ -46,6 +48,7 @@ public static function doesPropertyExist(PropertyExistenceProviderEvent $event):
return null;
}

#[\Override]
public static function isPropertyVisible(PropertyVisibilityProviderEvent $event): ?bool
{
if (!$event->isReadMode()) {
Expand All @@ -65,6 +68,7 @@ public static function isPropertyVisible(PropertyVisibilityProviderEvent $event)
return null;
}

#[\Override]
public static function getPropertyType(PropertyTypeProviderEvent $event): ?Type\Union
{
$source = $event->getSource();
Expand Down
4 changes: 4 additions & 0 deletions src/Handlers/Eloquent/ModelRelationshipPropertyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ final class ModelRelationshipPropertyHandler implements
PropertyTypeProviderInterface
{
/** @return list<class-string<\Illuminate\Database\Eloquent\Model>> */
#[\Override]
public static function getClassLikeNames(): array
{
return ModelStubProvider::getModelClasses();
}

/** @inheritDoc */
#[\Override]
public static function doesPropertyExist(PropertyExistenceProviderEvent $event): ?bool
{
$source = $event->getSource();
Expand All @@ -64,6 +66,7 @@ public static function doesPropertyExist(PropertyExistenceProviderEvent $event):
return null;
}

#[\Override]
public static function isPropertyVisible(PropertyVisibilityProviderEvent $event): ?bool
{
if (!$event->isReadMode()) {
Expand All @@ -87,6 +90,7 @@ public static function isPropertyVisible(PropertyVisibilityProviderEvent $event)
return null;
}

#[\Override]
public static function getPropertyType(PropertyTypeProviderEvent $event): ?Union
{
$source = $event->getSource();
Expand Down
6 changes: 3 additions & 3 deletions src/Handlers/Eloquent/RelationsMethodHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@

final class RelationsMethodHandler implements MethodReturnTypeProviderInterface
{
/**
* @return array<string>
*/
/** @return list<string> */
#[\Override]
public static function getClassLikeNames(): array
{
return [
Expand All @@ -43,6 +42,7 @@ public static function getClassLikeNames(): array
];
}

#[\Override]
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Union
{
$source = $event->getSource();
Expand Down
2 changes: 2 additions & 0 deletions src/Handlers/Helpers/CacheHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
final class CacheHandler implements FunctionReturnTypeProviderInterface
{
/** @inheritDoc */
#[\Override]
public static function getFunctionIds(): array
{
return ['cache'];
}

/** @inheritDoc */
#[\Override]
public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $event): Type\Union
{
$call_args = $event->getCallArgs();
Expand Down
4 changes: 4 additions & 0 deletions src/Handlers/Helpers/PathHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class PathHandler implements FunctionReturnTypeProviderInterface, MethodRe
* @inheritDoc
* @see https://laravel.com/docs/master/helpers#paths
*/
#[\Override]
public static function getFunctionIds(): array
{
return [
Expand All @@ -40,6 +41,7 @@ public static function getFunctionIds(): array
}

/** @inheritDoc */
#[\Override]
public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $event): ?Union
{
$function_id = $event->getFunctionId();
Expand All @@ -53,6 +55,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
}

/** @inheritDoc */
#[\Override]
public static function getClassLikeNames(): array
{
return [
Expand All @@ -61,6 +64,7 @@ public static function getClassLikeNames(): array
}

/** @inheritDoc */
#[\Override]
public static function getMethodReturnType(MethodReturnTypeProviderEvent $event): ?Union
{
$methods = [
Expand Down
2 changes: 2 additions & 0 deletions src/Handlers/Helpers/TransHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
final class TransHandler implements FunctionReturnTypeProviderInterface
{
/** @inheritDoc */
#[\Override]
public static function getFunctionIds(): array
{
return ['trans'];
}

/** @inheritDoc */
#[\Override]
public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $event): Type\Union
{
$call_args = $event->getCallArgs();
Expand Down
1 change: 1 addition & 0 deletions src/Handlers/SuppressHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ final class SuppressHandler implements AfterClassLikeVisitInterface
]
];

#[\Override]
public static function afterClassLikeVisit(AfterClassLikeVisitEvent $event): void
{
$class = $event->getStorage();
Expand Down
2 changes: 2 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
*/
final class Plugin implements PluginEntryPointInterface
{
/** @inheritDoc */
#[\Override]
public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement $config = null): void
{
try {
Expand Down
2 changes: 2 additions & 0 deletions src/Providers/FacadeStubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

final class FacadeStubProvider implements GeneratesStubs
{
#[\Override]
public static function generateStubFile(): void
{
$app = ApplicationProvider::getApp();
Expand Down Expand Up @@ -56,6 +57,7 @@ public static function generateStubFile(): void
);
}

#[\Override]
public static function getStubFileLocation(): string
{
return CacheDirectoryProvider::getCacheLocation() . '/facades.stubphp';
Expand Down
6 changes: 3 additions & 3 deletions src/Providers/ModelStubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class ModelStubProvider implements GeneratesStubs
/** @var list<class-string<\Illuminate\Database\Eloquent\Model>> */
private static array $model_classes = [];

#[\Override]
public static function generateStubFile(): void
{
$app = ApplicationProvider::getApp();
Expand Down Expand Up @@ -71,14 +72,13 @@ public static function generateStubFile(): void
self::$model_classes = $models_generator_command->getModels();
}

#[\Override]
public static function getStubFileLocation(): string
{
return CacheDirectoryProvider::getCacheLocation() . '/models.stubphp';
}

/**
* @return list<class-string<\Illuminate\Database\Eloquent\Model>>
*/
/** @return list<class-string<\Illuminate\Database\Eloquent\Model>> */
public static function getModelClasses(): array
{
return self::$model_classes;
Expand Down

0 comments on commit f5288a8

Please sign in to comment.