wnx / faker-swiss-locations
Provider to generate valid Swiss location data for Faker PHP.
Fund package maintenance!
stefanzweifel
Requires
- php: ^8.2
- fakerphp/faker: ^1.20
- wnx/php-swiss-cantons: ^4.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- pestphp/pest: ^2.6
README
Faker provider to generate random valid Swiss locations.
Installation
You can install the package via composer:
composer require wnx/faker-swiss-locations
Usage
You first need to add the Location
provider to Faker.
// Add Location Provider to Faker $faker = Factory::create(); $faker->addProvider(new Wnx\FakerSwissLocations\Provider\Location($faker));
You can now call the postcode()
, city()
or canton()
method on faker to get a random valid Swiss location.
Note Calling
postcode()
,city()
orcanton()
always returns a new random location. If you need the same location forpostcode
,city
andcanton
use thelocation()
-method and access the properties from the instance.
// 8000 $faker->postcode(); // Zürich $faker->city(); // Instance of Wnx\SwissCantons\Canton $faker->canton(); $faker->canton()->getName(); // Zürich $faker->canton()->getAbbreviation(); // ZH
Or you can call the location()
method to get a \Wnx\FakerSwissLocations\Location
-instance. You can access postcode, city and canton from this object too.
// Instance of \Wnx\FakerSwissLocations\Location $location = $faker->location(); $location->postcode; // 8000 $location->city; // Zürich $location->canton; // Instance of Wnx\SwissCantons\Canton
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.