Download the PHP package calebdw/fakerstan without Composer
On this page you can find all versions of the php package calebdw/fakerstan. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download calebdw/fakerstan
More information about calebdw/fakerstan
Files in calebdw/fakerstan
Package fakerstan
Short Description PHPStan extension for Faker
License MIT
Homepage https://github.com/calebdw/fakerstan
Informations about the package fakerstan
Install
If you have the PHPStan extension installer installed then nothing more is needed, otherwise you will need to manually include the extension in the phpstan.neon(.dist)
configuration file:
Features
Custom Providers
FakerStan will automatically look for unknown methods on the custom providers on the Faker instance and infer the return type based on the method signature, even generics are supported:
Configuration
In order for FakerStan to correctly detect the custom providers, it needs the actual Faker instance used in the project (or at least an instance with the custom providers added to it).
If using Laravel, FakerStan will automatically resolve the faker instance from
the container using the fake()
helper function.
If not using Laravel, but you are using a framework or environment that has a PSR-11 compliant DI container (and assuming this container is configured via a PHP file), you can use the PsrContainerFakerProviderFactory.
The parameters that can be set are:
phpContainerPath
: the path to the PHP file that configures the container.setsVariable
: if the file that configures the container assigns it to a global variable, this parameter is used to indicate the name of that variable. If the container file returns the container itself, set this parameter is null (which is the default).containerFakerId
: the ID that the container uses for retrieving the Faker Generator. By default, this parameter is the Generator's class name (ie.Faker\Generator
).
If using Symfony, for example, you could use something like:
to use the PsrContainerFakerProviderFactory and set the path to the Symfony container. The default values for the additional parameters are correct for Symfony.
If not using Laravel or some other PSR-11 compliant container, you can specify a custom
factory class in the phpstan.neon(.dist)
configuration file:
where App\CustomFakerProviderFactory
is a class that creates an implementation of
the CalebDW\FakerStan\FakerProvider
interface:
Contributing
Thank you for considering contributing! You can read the contribution guide here.
License
FakerStan is open-sourced software licensed under the MIT license.