### Install Project Dependencies Source: https://github.com/calebdw/fakerstan/blob/master/CONTRIBUTING.md Run this command after cloning your fork to install all necessary project dependencies. ```bash composer update ``` -------------------------------- ### Install FakerStan with Composer Source: https://github.com/calebdw/fakerstan/blob/master/README.md Install the FakerStan package as a development dependency using Composer. ```bash composer require calebdw/fakerstan --dev ``` -------------------------------- ### PSR Container Bootstrap for Faker Source: https://context7.com/calebdw/fakerstan/llms.txt Example bootstrap file for a PSR-11 container, demonstrating how to bind a Faker instance. ```php bind('faker', fn() => \Faker\Factory::create('en_US')); // FakerStan reads $container via setsVariable: "container" ``` -------------------------------- ### Implement Custom FakerProviderFactory and FakerProvider Source: https://github.com/calebdw/fakerstan/blob/master/README.md Example implementation of a custom factory class and the FakerProvider interface for integrating FakerStan with custom Faker generator instances. ```php addProvider(new CustomProvider($faker)); return $faker; } } ``` -------------------------------- ### Configure FakerStan with Custom Factory Source: https://github.com/calebdw/fakerstan/blob/master/README.md Example of configuring FakerStan to use a custom factory class for creating the FakerProvider implementation in phpstan.neon(.dist). ```neon parameters: fakerstan: fakerProviderFactory: App\CustomFakerProviderFactory services: - class: App\CustomFakerProviderFactory ``` -------------------------------- ### Define and Use Custom Faker Providers Source: https://github.com/calebdw/fakerstan/blob/master/README.md Example of defining a custom Faker provider with a simple method and a generic method, and then adding it to the Faker generator. This demonstrates how FakerStan infers return types. ```php */ public function classFromObject(object $object): string { return $object::class; } } $faker = new Generator(); $faker->addProvider(new CustomProvider($faker)); $faker->customMethod(); // string $faker->classFromObject(new User); // class-string ``` -------------------------------- ### Implement Custom FakerProvider Interface Source: https://context7.com/calebdw/fakerstan/llms.txt Implement the FakerProvider interface to teach FakerStan about your project's Faker instance and custom providers. This example shows a custom ProductProvider and an AppFakerProvider implementation. ```php bothify('??-####')); } /** * @template T of object * @param class-string $class * @return T */ public function make(string $class): object { return new $class(); } } // Custom FakerProvider implementation class AppFakerProvider implements FakerProvider { public function getFaker(): Generator { $faker = new Generator(); $faker->addProvider(new \Faker\Provider\en_US\Person($faker)); $faker->addProvider(new ProductProvider($faker)); return $faker; } } ``` -------------------------------- ### Configure FakerStan with PSR-11 Container Source: https://github.com/calebdw/fakerstan/blob/master/README.md Example of configuring FakerStan to use a PSR-11 compliant DI container by specifying the factory and container path in phpstan.neon(.dist). ```neon parameters: fakerstan: fakerProviderFactory: CalebDW\Fakerstan\PsrContainerFakerProviderFactory psrProvider: phpContainerPath: /path/to/container.php ... ``` -------------------------------- ### Include FakerStan Extension in PHPStan Configuration Source: https://github.com/calebdw/fakerstan/blob/master/README.md Manually include the FakerStan extension in your phpstan.neon(.dist) configuration file if the extension installer is not used. ```neon includes: - ./vendor/calebdw/fakerstan/extension.neon ``` -------------------------------- ### Run All Project Tests Source: https://github.com/calebdw/fakerstan/blob/master/CONTRIBUTING.md Execute this command to run all automated tests for the project. ```bash composer test ``` -------------------------------- ### Run PHPUnit Tests Source: https://github.com/calebdw/fakerstan/blob/master/CONTRIBUTING.md Execute this command to run the PHPUnit tests specifically. ```bash composer test:phpunit ``` -------------------------------- ### Perform Static Analysis Source: https://github.com/calebdw/fakerstan/blob/master/CONTRIBUTING.md Use this command to run static analysis checks on the project code. ```bash composer test:phpstan ``` -------------------------------- ### FakerStan Extension Configuration Reference Source: https://context7.com/calebdw/fakerstan/llms.txt Default configuration parameters for FakerStan as defined in the bundled extension.neon file. These can be overridden in your project's phpstan.neon.dist. ```neon # extension.neon (bundled defaults — override in your phpstan.neon.dist) parameters: fakerstan: fakerProviderFactory: CalebDW\Fakerstan\FakerProviderFactory # default factory psrProvider: phpContainerPath: null # required when using PsrContainerFakerProviderFactory setsVariable: null # null = container file returns container containerFakerId: Faker\Generator # PSR-11 container ID for the Faker instance # To override in your project: # phpstan.neon.dist includes: - ./vendor/calebdw/fakerstan/extension.neon parameters: level: max paths: - src fakerstan: fakerProviderFactory: App\MyFakerProviderFactory ``` -------------------------------- ### Configure FakerStan with Symfony Container Path Source: https://github.com/calebdw/fakerstan/blob/master/README.md Specific configuration for Symfony projects, setting the phpContainerPath for the PsrContainerFakerProviderFactory. ```neon parameters: fakerstan: fakerProviderFactory: CalebDW\Fakerstan\PsrContainerFakerProviderFactory psrProvider: phpContainerPath: /opt/project/var/cache/dev/App_KernelDevDebugContainer.php ``` -------------------------------- ### Create Custom FakerProviderFactory Source: https://context7.com/calebdw/fakerstan/llms.txt Implement the AppFakerProviderFactory class to return your custom FakerProvider implementation. This factory is used when a custom factory is configured in phpstan.neon.dist. ```php bothify('??-####')); } } // PHPStan type assertions (verified by FakerStan's test suite): /** @param array{bar: string} $data */ function analyse(Generator $faker, array $data): void { $faker->passthrough($data); // inferred: array{bar: string} $faker->unique()->passthrough($data); // inferred: array{bar: string} $faker->optional()->passthrough($data); // inferred: array{bar: string} $faker->valid()->passthrough($data); // inferred: array{bar: string} $faker->sku(); // inferred: string $faker->unique()->sku(); // inferred: string // Non-public methods are NOT surfaced — PHPStan reports *ERROR* // $faker->protectedMethod(); // *ERROR* } ``` -------------------------------- ### Non-Base Providers Registration Source: https://context7.com/calebdw/fakerstan/llms.txt Register providers that do not extend Faker\Provider\Base. FakerStan detects public methods on such providers if they are registered on the generator. ```php addProvider(new SizeProvider()); // PHPStan (with FakerStan) correctly infers: $faker->size(); // string ✓ — no "Call to an undefined method" error ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.