Skip to content

Commit 310a1b2

Browse files
committed
Add Faker provider
1 parent 8a49fa1 commit 310a1b2

File tree

15 files changed

+342
-4
lines changed

15 files changed

+342
-4
lines changed

.github/workflows/provider.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- BingMaps
2222
- Cache
2323
- Chain
24+
- Faker
2425
- FreeGeoIp
2526
- GeoIP2
2627
# - GeoIPs

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ and are highly configurable.
112112

113113
### Special providers
114114

115-
Provider | Package | Features | Stats
116-
:------------- |:------- |:-------- |:-------
117-
[Cache](https://github.com/geocoder-php/cache-provider) | `geocoder-php/cache-provider` | Wraps a provider and cached the results | [![Latest Stable Version](https://poser.pugx.org/geocoder-php/cache-provider/v/stable)](https://packagist.org/packages/geocoder-php/cache-provider) <br>[![Total Downloads](https://poser.pugx.org/geocoder-php/cache-provider/downloads)](https://packagist.org/packages/geocoder-php/cache-provider)
118-
[Chain](https://github.com/geocoder-php/chain-provider) | `geocoder-php/chain-provider` | Iterates over multiple providers | [![Latest Stable Version](https://poser.pugx.org/geocoder-php/chain-provider/v/stable)](https://packagist.org/packages/geocoder-php/chain-provider) <br>[![Total Downloads](https://poser.pugx.org/geocoder-php/chain-provider/downloads)](https://packagist.org/packages/geocoder-php/chain-provider)
115+
Provider | Package | Features | Stats
116+
:------------- |:------------------------------|:----------------------------------------------------------------|:-------
117+
[Cache](https://github.com/geocoder-php/cache-provider) | `geocoder-php/cache-provider` | Wraps a provider and cached the results | [![Latest Stable Version](https://poser.pugx.org/geocoder-php/cache-provider/v/stable)](https://packagist.org/packages/geocoder-php/cache-provider) <br>[![Total Downloads](https://poser.pugx.org/geocoder-php/cache-provider/downloads)](https://packagist.org/packages/geocoder-php/cache-provider)
118+
[Chain](https://github.com/geocoder-php/chain-provider) | `geocoder-php/chain-provider` | Iterates over multiple providers | [![Latest Stable Version](https://poser.pugx.org/geocoder-php/chain-provider/v/stable)](https://packagist.org/packages/geocoder-php/chain-provider) <br>[![Total Downloads](https://poser.pugx.org/geocoder-php/chain-provider/downloads)](https://packagist.org/packages/geocoder-php/chain-provider)
119+
[Faker](https://github.com/geocoder-php/faker-provider) | `geocoder-php/faker-provider` | Provide fake data using [FakerPHP](https://fakerphp.github.io/) | [![Latest Stable Version](https://poser.pugx.org/geocoder-php/faker-provider/v/stable)](https://packagist.org/packages/geocoder-php/faker-provider) <br>[![Total Downloads](https://poser.pugx.org/geocoder-php/faker-provider/downloads)](https://packagist.org/packages/geocoder-php/faker-provider)
119120

120121
### Address
121122

@@ -218,6 +219,11 @@ var_export($result);
218219

219220
Everything is ok, enjoy!
220221

222+
### The Faker Provider
223+
224+
The `Faker` provider is a special provider that return fake data using [FakerPHP](https://fakerphp.github.io/).
225+
It's main purpose is to provide fake data during tests, avoiding unnecessary http requests.
226+
221227
### The ProviderAggregator
222228

223229
The `ProviderAggregator` is used to register several providers so that you can

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"cache/array-adapter": "^1.0",
3131
"cache/simple-cache-bridge": "^1.0",
3232
"cache/void-adapter": "^1.0",
33+
"fakerphp/faker": "^1.23",
3334
"geocoder-php/provider-integration-tests": "^1.6.3",
3435
"geoip2/geoip2": "^2.0|^3.0",
3536
"nyholm/nsa": "^1.1",

src/Provider/Faker/.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.gitattributes export-ignore
2+
phpunit.xml.dist export-ignore
3+
Tests/ export-ignore
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Provider
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
name: PHP ${{ matrix.php-version }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php-version: ['8.0', '8.1', '8.2']
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Use PHP ${{ matrix.php-version }}
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ matrix.php-version }}
23+
extensions: curl
24+
- name: Validate composer.json and composer.lock
25+
run: composer validate --strict
26+
- name: Install dependencies
27+
run: composer update --prefer-stable --prefer-dist --no-progress
28+
- name: Run test suite
29+
run: composer run-script test-ci
30+
- name: Upload Coverage report
31+
run: |
32+
wget https://scrutinizer-ci.com/ocular.phar
33+
php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml

src/Provider/Faker/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor/
2+
composer.lock
3+
.phpunit.result.cache

src/Provider/Faker/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Change Log
2+
3+
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
4+
5+
## 5.0.0
6+
7+
First release of this library.

src/Provider/Faker/Faker.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Geocoder\Provider\Faker;
6+
7+
use Faker\Factory;
8+
use Geocoder\Collection;
9+
use Geocoder\Model\AddressBuilder;
10+
use Geocoder\Model\AddressCollection;
11+
use Geocoder\Provider\Provider;
12+
use Geocoder\Query\GeocodeQuery;
13+
use Geocoder\Query\Query;
14+
use Geocoder\Query\ReverseQuery;
15+
16+
/**
17+
* @author Romain Monteil <[email protected]>
18+
*/
19+
final class Faker implements Provider
20+
{
21+
public const PROVIDER_NAME = 'faker';
22+
23+
public function geocodeQuery(GeocodeQuery $query): Collection
24+
{
25+
return $this->generateFakeLocations($query);
26+
}
27+
28+
public function reverseQuery(ReverseQuery $query): Collection
29+
{
30+
return $this->generateFakeLocations($query);
31+
}
32+
33+
public function getName(): string
34+
{
35+
return self::PROVIDER_NAME;
36+
}
37+
38+
private function generateFakeLocations(Query $query): Collection
39+
{
40+
$faker = Factory::create($query->getLocale() ?? Factory::DEFAULT_LOCALE);
41+
42+
$results = [];
43+
44+
$i = 0;
45+
while ($i < $query->getLimit()) {
46+
$builder = new AddressBuilder($this->getName());
47+
$builder
48+
->setCoordinates($faker->latitude(), $faker->longitude())
49+
->setStreetNumber($faker->buildingNumber())
50+
->setStreetName($faker->streetName())
51+
->setPostalCode($faker->postcode())
52+
->setLocality($faker->city())
53+
->setCountry($faker->country())
54+
->setCountryCode($faker->countryCode())
55+
->setTimezone($faker->timezone())
56+
;
57+
58+
$results[] = $builder->build();
59+
++$i;
60+
}
61+
62+
return new AddressCollection($results);
63+
}
64+
}

src/Provider/Faker/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2011 — William Durand <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

src/Provider/Faker/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Nominatim Geocoder provider
2+
[![Build Status](https://img.shields.io/github/actions/workflow/status/geocoder-php/Geocoder/provider.yml?style=flat-square)](https://github.com/geocoder-php/faker-provider/actions)
3+
[![Latest Stable Version](https://img.shields.io/packagist/v/geocoder-php/faker-provider?style=flat-square)](https://packagist.org/packages/geocoder-php/faker-provider)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/geocoder-php/faker-provider?style=flat-square)](https://packagist.org/packages/geocoder-php/faker-provider)
5+
[![Monthly Downloads](https://img.shields.io/packagist/dm/geocoder-php/faker-provider?style=flat-square)](https://packagist.org/packages/geocoder-php/faker-provider)
6+
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/geocoder-php/faker-provider.svg?style=flat-square)](https://scrutinizer-ci.com/g/geocoder-php/faker-provider)
7+
[![Quality Score](https://img.shields.io/scrutinizer/g/geocoder-php/faker-provider.svg?style=flat-square)](https://scrutinizer-ci.com/g/geocoder-php/faker-provider)
8+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
9+
10+
This is the Faker provider from the PHP Geocoder. This is a **READ ONLY** repository. See the
11+
[main repo](https://github.com/geocoder-php/Geocoder) for information and documentation.
12+
13+
## Install
14+
15+
```bash
16+
composer require geocoder-php/faker-provider
17+
```
18+
19+
## Contribute
20+
21+
Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or
22+
report any issues you find on the [issue tracker](https://github.com/geocoder-php/Geocoder/issues).

0 commit comments

Comments
 (0)