wnx/faker-swiss-locations

Provider to generate valid Swiss location data for Faker PHP.

v1.1.0 2023-10-16 12:17 UTC

This package is auto-updated.

Last update: 2024-04-29 18:03:53 UTC


README

Latest Version on Packagist Tests Total Downloads

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() or canton() always returns a new random location. If you need the same location for postcode, city and canton use the location()-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.