yivoff / spanish-nif
Tool to verify and generate Spanish NIFs / Herramienta para verificar y generar NIFs de España
Installs: 90
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: >=8.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.4
- fakerphp/faker: ^1.17
- nyholm/symfony-bundle-test: dev-master
- roave/security-advisories: dev-master
- symfony/framework-bundle: ^5.3 || ^6.0.2
- symfony/validator: ^5.3 || ^6.0.2
README
Simple library to check that fiscal identifiers are valid according to Spanish legislation, and to generate valid fiscal identifiers.
Installation
composer require yivoff/nif-check
Usage
$checker = new \Yivoff\NifCheck\NifChecker(); // returns true if valid $checker->verify($anyNif);
NIF Generator
An utility is provided to generate valid NIFs, which could be useful for testing purposes or similar scenarios.
$generator = new \Yivoff\NifCheck\Generator\RandomNif(); // Generates a valid DNI $validDni = $generator->generateDni(); // Generates a valid NIE $validNie = $generator->generateNie(); // Generates a valid CIF $validCif = $generator->generateCif(); // Generates a valid NIF (randomly DNI, NIF, or CIF) $validNif = $generator->generate();
Symfony Validator integration
The package provides a Symfony Validator attribute, which can simply be used like this:
use Yivoff\NifCheck\Validator\ValidNif; class User { #[ValidNif] public string $nif; }
fakerphp/faker Integration
The package also includes a Faker Provider.
$faker = Faker\Factory::create(); $faker->addProvider(new \Yivoff\NifCheck\FakerProvider\NifProvider($faker, new \Yivoff\NifCheck\Generator\RandomNif())); // now you can fake NIFs $faker->spanishDni(); $faker->spanishNie(); $faker->spanishCif(); $faker->spanishNif();
See: