Download the PHP package interaction-design-foundation/psalm-laravel-nova without Composer

On this page you can find all versions of the php package interaction-design-foundation/psalm-laravel-nova. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package psalm-laravel-nova

Psalm plugin for Laravel Nova

Latest Version on Packagist Total Downloads

A Psalm plugin that resolves Laravel Nova's magic: the reflective dispatch and @method annotations that static analysis cannot follow on its own. Works with Laravel apps and Nova packages.

This plugin covers Nova only. Install it in addition to psalm/plugin-laravel, which covers the Laravel framework itself. It is not a replacement.

Nova dispatches resources, actions, filters, lenses, cards, tools, dashboards and metrics through reflection and naming conventions that live entirely inside laravel/nova. Psalm cannot see those call sites, and several Nova base classes carry @method annotations whose signatures do not describe what their subclasses actually accept. The result is a stream of false positives on an otherwise clean Nova codebase.

This plugin removes them. Its guiding principle is silence over false positives: when a type cannot be resolved with confidence, the plugin declines and lets Psalm fall back to its own inference rather than guessing.

Installation

Then enable it:

Keep psalm/plugin-laravel installed and enabled alongside it: this plugin handles Nova-specific conventions and relies on the Laravel plugin for everything else (Eloquent models, facades, container bindings).

What it does

make() calls are checked against the right constructor

Laravel\Nova\Element declares @method static static make(string|null $component = null) and Laravel\Nova\Panel declares its own differently-shaped @method make(...). Psalm stores @method annotations as pseudo methods and, during static-call resolution, gives an ancestor's pseudo method priority over the class's own real (variadic) make(). Because almost no concrete Nova field or panel declares its own @method make(...) override, every Text::make('Label', 'column') resolves against Element's single-optional-parameter signature and reports TooManyArguments.

NovaMakeSignatureHandler gives each class a make() signature derived from its own constructor.

Resource query methods are narrowed to the resource's model

Nova's Resource::indexQuery(), relatableQuery() and friends receive a Builder that Psalm sees as Builder<Model>. NovaResourceQueryMethodHandler narrows it to the resource's concrete model, resolved in two steps:

  1. the @extends \Laravel\Nova\Resource<ConcreteModel> template binding, including when inherited transitively through intermediate base classes;
  2. the public static $model = SomeModel::class convention property, read from the AST when no template binding resolves.

The property value is validated (it must exist and be a genuine Model subclass) before narrowing, so a typo never produces a confidently wrong type.

$this->when(...) no longer poisons fields()

Illuminate\Http\Resources\ConditionallyLoadsAttributes::when() returns mixed, which degrades the inferred element type of every array literal built with it, including Nova's fields() and actions(). NovaWhenReturnTypeHandler introspects the argument and returns the closure's return type (or the value's type) unioned with MissingValue. A literal true/false condition drops the dead branch. When the type cannot be resolved, the provider declines rather than leaking a raw Closure into the union.

Reflectively dispatched code is not reported as unused

Under findUnusedCode="true", the classes and members Nova reaches by reflection have no visible call site. NovaConventionsHandler marks the ones that stubs cannot express as entry points, the same signal an @api docblock carries, so Psalm treats them as reachable and keeps alive whatever they call:

Marking rather than suppressing matters since psalm/psalm-plugin-api 0.2.0, where suppressing an unused-code issue silences the report for that one symbol only: a private helper called from nothing but a hook would still be reported UnusedMethod. A hook shared through a trait is marked on the trait, which is where Psalm reads the flag from. Hook methods that override a base declaration (fields(), apply(), calculate(), …) already inherit the parent's "used" status from the stubs and need nothing here.

Marking the resource class is the one broad step, so it applies only when findUnusedCode is on. It also stops Psalm checking that resource's public surface (an unread public property or an uncalled public method goes unreported) and silences ClassMustBeFinal for it. The one remaining suppression is NonInvariantPropertyType on $policy, and only for declarations compatible with the stub's string. public static int $policy still raises.

Nova stubs

The plugin ships stubs for Action, ActionEvent, ActionResponse, Field, FieldElement, Element, PartitionResult, Panel, Resource, ResolvedFields, Filterable, Stack and SupportsDependentFields that fix vendor signatures Psalm cannot resolve. Resource is templated, so a resource can declare its model with @extends:

The stubs are registered by the plugin itself; no <stubs> entry is needed in psalm.xml.

FieldElement's visibility callbacks (showOnIndex(), showOnDetail(), hideFromIndex(), …) are narrowed through a bounded template rather than a fixed union, so a closure typed against the resource's own model (fn(NovaRequest $request, Post $post): bool) is accepted instead of being rejected as too narrow. This is a deliberate trade-off, and it is wider than just wrong-model confusion: any type consistent with the bound (Model|Fluent|array<array-key, mixed>|object) is accepted for the resource parameter, so a closure typed against the wrong model (fn(NovaRequest $request, Comment $comment) on a field that only ever appears on Post) still type-checks, and so does one typed stdClass, DateTimeImmutable, or an unrelated array shape. Wrong request classes, wrong return types and wrong arity are still reported. This also makes the plugin stricter than Nova's own docblocks for the setters Nova types with a bare mixed second parameter (Nova only narrows some of them itself, via @phpstan-param): the bound now catches a resource parameter typed as something unrelated (e.g. int) that Nova's own bare mixed wouldn't have flagged.

The field resolve/display callbacks are narrowed the same way. Nova documents the resolve callback (3rd argument of Field::make(), DateTime::make(), Email::make(), ID::make(), …, and resolveUsing()) as callable(mixed, mixed, ?string), and displayUsing() as callable(mixed, mixed, string), yet it always invokes them as ($value, $resource, $attribute) with a non-null string attribute ($attribute ?? $this->attribute) and the field's model, pivot or repeater row as resource. A closure typed fn(mixed $value, Post $resource, string $attribute) is therefore sound, but was rejected on both counts. The plugin retypes these as callable(mixed, TResource, string) with the same bounded TResource template and the same trade-off as above (resolveUsing()/displayUsing() through a Field stub, make() through NovaMakeSignatureHandler, which swaps the constructor's callable(mixed, mixed, ?string) param on the synthesized make() signature of every field class that declares one). A non-string $attribute, a resource param outside the bound, or a callback requiring a 4th argument are still reported. The constructor itself (new Text(...)) keeps Nova's wide signature, and BelongsTo-style fields whose constructor has no resolve callback are unaffected.

canSee() is narrowed to NovaRequest for every Field-, Action-, Filter- and Lens-derived class, but not through a stub: it's declared only on the AuthorizedToSee trait, which these classes merely inherit, and a stub cannot override a method the stubbed class only inherits from a used trait. The plugin rewrites it programmatically post-populate instead. Scope is deliberate: in Nova 5.11 every path that calls authorizedToSee() on a field, action, filter or lens hands it a NovaRequest (ResolvesActions/ResolvesFilters/ResolvesLenses and ActionRequest/LensRequest are all typed or built on NovaRequest, and the menu items built by MenuItem::lens()/MenuSection::lens() are only ever evaluated with app(NovaRequest::class)). Tool, Dashboard and Menu\* share the same trait but are resolved with a plain Illuminate\Http\Request by BootTools, so their canSee() stays wide. The narrowing describes what Nova itself passes: authorizedToSee(Request $request) is still a public method typed Request, so your own code (for instance a Nova::mainMenu() callback) can call it on an action, filter or lens with a plain request, and that call is not checked against the closure's parameter type. A class that overrides canSee() itself is never touched.

The action, action-event and dependent-field stubs fix the same kind of vendor mismatch: Nova hints a bare Collection or FormData, which Psalm reads as <array-key, mixed> and, both being invariant, will not match a typed one.

The ActionEvent and ActionResponse stubs declare only the members they change and are merged with Nova's classes, so everything else (ActionEvent::forResourceUpdate(), its relations and properties, ActionResponse::message(), danger(), …) stays as Nova declares it.

Filterable::filterable()'s query parameter accepts either a concrete Illuminate\Database\Eloquent\Builder or a Relation, since Nova passes a Relation for relationship-index requests. Typing a closure against only one of the two type-checks even for a field that's reachable through both request kinds — type against the shared Illuminate\Contracts\Database\Eloquent\Builder contract instead if a field needs to be safe against both.

Requirements

laravel/nova is not a dependency: the plugin relies on its own stubs and resolves everything else from the analysed codebase.

Contributing

Pull requests are welcome. Run the checks before opening one:

License

MIT. Copyright © The Interaction Design Foundation.


All versions of psalm-laravel-nova with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
psalm/psalm-plugin-api Version ^0.4.0 || ^0.5.0
vimeo/psalm Version ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package interaction-design-foundation/psalm-laravel-nova contains the following files

Loading the files please wait ...