Skip to content

Commit e03db09

Browse files
committed
Modernize
1 parent fe24ecb commit e03db09

File tree

72 files changed

+396
-824
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+396
-824
lines changed

composer.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^7.4 || ^8.0",
18-
"geocoder-php/plugin": "^1.5",
17+
"php": "^8.1",
18+
"geocoder-php/plugin": "^1.6",
1919
"php-http/curl-client": "^2.3",
20-
"php-http/discovery": "^1.14",
21-
"symfony/console": "^5.4 || ^6.4 || ^7.0",
22-
"symfony/framework-bundle": "^5.4 || ^6.4 || ^7.0",
23-
"symfony/options-resolver": "^5.4 || ^6.4 || ^7.0",
20+
"php-http/discovery": "^1.20",
21+
"symfony/console": "^6.4 || ^7.0",
22+
"symfony/framework-bundle": "^6.4 || ^7.0",
23+
"symfony/options-resolver": "^6.4 || ^7.0",
2424
"willdurand/geocoder": "^4.6|^5.0"
2525
},
2626
"require-dev": {
27-
"doctrine/annotations": "^1.11.1 || ^2.0",
28-
"doctrine/doctrine-bundle": "^2.3",
27+
"doctrine/doctrine-bundle": "^2.3 || ^3.0",
2928
"doctrine/orm": "^2.8 || ^3.0",
3029
"fakerphp/faker": "^1.20",
3130
"friendsofphp/php-cs-fixer": "^3.13",
@@ -69,6 +68,8 @@
6968
"psr/simple-cache": "^1.0 || ^2.0",
7069
"symfony/cache": "^5.4 || ^6.4 || ^7.0",
7170
"symfony/config": "^5.4 || ^6.4 || ^7.0",
71+
"symfony/dependency-injection": "^5.4 || ^6.4 || ^7.0",
72+
"symfony/doctrine-bridge": "^5.4 || ^6.4 || ^7.0",
7273
"symfony/phpunit-bridge": "^5.4 || ^6.4 || ^7.0",
7374
"symfony/validator": "^5.4 || ^6.4 || ^7.0",
7475
"symfony/var-exporter": "^5.4 || ^6.4 || ^7.0",

config/profiling.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
6+
7+
use Bazinga\GeocoderBundle\DataCollector\GeocoderDataCollector;
8+
9+
return static function (ContainerConfigurator $container) {
10+
$services = $container->services();
11+
12+
$services->set(GeocoderDataCollector::class)
13+
->tag('data_collector', ['template' => '@BazingaGeocoder/Collector/geocoder.html.twig', 'id' => 'geocoder']);
14+
};

config/profiling.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/services.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
6+
7+
use Bazinga\GeocoderBundle\Command\GeocodeCommand;
8+
use Bazinga\GeocoderBundle\Plugin\FakeIpPlugin;
9+
use Bazinga\GeocoderBundle\Validator\Constraint\AddressValidator;
10+
use Geocoder\Dumper\Dumper;
11+
use Geocoder\Dumper\GeoArray;
12+
use Geocoder\Dumper\GeoJson;
13+
use Geocoder\Dumper\Gpx;
14+
use Geocoder\Dumper\Kml;
15+
use Geocoder\Dumper\Wkb;
16+
use Geocoder\Dumper\Wkt;
17+
use Geocoder\ProviderAggregator;
18+
19+
return static function (ContainerConfigurator $container) {
20+
$services = $container->services();
21+
$services->instanceof(Dumper::class)
22+
->tag('bazinga_geocoder.dumper');
23+
24+
$services
25+
->set(GeoArray::class)
26+
->set(GeoJson::class)
27+
->set(Gpx::class)
28+
->set(Kml::class)
29+
->set(Wkb::class)
30+
->set(Wkt::class)
31+
32+
->load('Bazinga\\GeocoderBundle\\ProviderFactory\\', __DIR__ . '/../src/ProviderFactory')
33+
->autowire()
34+
->autoconfigure()
35+
->private()
36+
37+
->set(ProviderAggregator::class)
38+
39+
->set(FakeIpPlugin::class)
40+
->args([
41+
'$useFaker' => false,
42+
])
43+
44+
->set(GeocodeCommand::class)
45+
->args([
46+
service(ProviderAggregator::class),
47+
])
48+
->tag('console.command', ['command' => 'geocoder:geocode', 'description' => 'Geocode an address or a ip address'])
49+
50+
->set(AddressValidator::class)
51+
->args([
52+
service(ProviderAggregator::class),
53+
])
54+
->tag('validator.constraint_validator')
55+
;
56+
};

config/services.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

doc/doctrine.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ First of all, update your entity:
1010

1111
```php
1212

13-
use Bazinga\GeocoderBundle\Mapping\Annotations as Geocoder;
13+
use Bazinga\GeocoderBundle\Mapping\Attributes as Geocoder;
1414

1515
/**
1616
* @Geocoder\Geocodeable
@@ -38,7 +38,7 @@ Instead of annotating a property, you can also annotate a getter:
3838

3939
```php
4040

41-
use Bazinga\GeocoderBundle\Mapping\Annotations as Geocoder;
41+
use Bazinga\GeocoderBundle\Mapping\Attributes as Geocoder;
4242

4343
/**
4444
* @Geocoder\Geocodeable
@@ -103,7 +103,7 @@ If you are using PHP 8, you can use [Attributes](https://www.php.net/manual/en/l
103103

104104
```php
105105

106-
use Bazinga\GeocoderBundle\Mapping\Annotations as Geocoder;
106+
use Bazinga\GeocoderBundle\Mapping\Attributes as Geocoder;
107107

108108
#[Geocoder\Geocodeable()]
109109
class User

src/BazingaGeocoderBundle.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
/**
2222
* @author William Durand <william.durand1@gmail.com>
2323
*/
24-
class BazingaGeocoderBundle extends Bundle
24+
final class BazingaGeocoderBundle extends Bundle
2525
{
26-
/**
27-
* @return void
28-
*/
29-
public function build(ContainerBuilder $container)
26+
public function build(ContainerBuilder $container): void
3027
{
3128
parent::build($container);
3229

src/Command/GeocodeCommand.php

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,31 @@
2424
/**
2525
* @author Markus Bachmann <markus.bachmann@bachi.biz>
2626
*/
27-
#[AsCommand(name: 'geocoder:geocode', description: 'Geocode an address or a ip address')]
28-
class GeocodeCommand extends Command
29-
{
30-
private ProviderAggregator $geocoder;
27+
#[AsCommand(
28+
name: 'geocoder:geocode',
29+
description: 'Geocode an address or a ip address',
30+
help: <<<'HELP'
31+
The <info>geocoder:geocoder</info> command will fetch the latitude
32+
and longitude from the given address.
3133
32-
public function __construct(ProviderAggregator $geocoder)
33-
{
34-
$this->geocoder = $geocoder;
34+
You can force a provider with the "provider" option.
3535
36+
<info>php bin/console geocoder:geocoder "Eiffel Tower" --provider=yahoo</info>
37+
HELP
38+
)]
39+
final class GeocodeCommand extends Command
40+
{
41+
public function __construct(
42+
private readonly ProviderAggregator $geocoder
43+
) {
3644
parent::__construct();
3745
}
3846

39-
/**
40-
* @return void
41-
*/
42-
protected function configure()
47+
protected function configure(): void
4348
{
4449
$this
4550
->addArgument('address', InputArgument::REQUIRED, 'The address')
46-
->addOption('provider', null, InputOption::VALUE_OPTIONAL)
47-
->setHelp(<<<'HELP'
48-
The <info>geocoder:geocoder</info> command will fetch the latitude
49-
and longitude from the given address.
50-
51-
You can force a provider with the "provider" option.
52-
53-
<info>php bin/console geocoder:geocoder "Eiffel Tower" --provider=yahoo</info>
54-
HELP
55-
);
51+
->addOption('provider', null, InputOption::VALUE_OPTIONAL);
5652
}
5753

5854
protected function execute(InputInterface $input, OutputInterface $output): int

src/DataCollector/GeocoderDataCollector.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* @author Michal Dabrowski <dabrowski@brillante.pl>
2323
*/
24-
class GeocoderDataCollector extends DataCollector
24+
final class GeocoderDataCollector extends DataCollector
2525
{
2626
/**
2727
* @var ProfilingPlugin[]
@@ -34,22 +34,16 @@ public function __construct()
3434
$this->data['providers'] = [];
3535
}
3636

37-
/**
38-
* @return void
39-
*/
40-
public function reset()
37+
public function reset(): void
4138
{
4239
$this->instances = [];
4340
$this->data['queries'] = [];
4441
$this->data['providers'] = [];
4542
}
4643

47-
/**
48-
* @return void
49-
*/
50-
public function collect(Request $request, Response $response, ?\Throwable $exception = null)
44+
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void
5145
{
52-
if (!empty($this->data['queries'])) {
46+
if ($this->data['queries'] !== []) {
5347
// To avoid collection more that once.
5448
return;
5549
}
@@ -106,10 +100,7 @@ public function getProviderQueries(string $provider): array
106100
});
107101
}
108102

109-
/**
110-
* @return void
111-
*/
112-
public function addInstance(ProfilingPlugin $instance)
103+
public function addInstance(ProfilingPlugin $instance): void
113104
{
114105
$this->instances[] = $instance;
115106
$this->data['providers'][] = $instance->getName();

src/DependencyInjection/BazingaGeocoderExtension.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,28 @@
3131
use Symfony\Component\DependencyInjection\ContainerBuilder;
3232
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
3333
use Symfony\Component\DependencyInjection\Extension\Extension;
34-
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
34+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
3535
use Symfony\Component\DependencyInjection\Reference;
3636

3737
/**
3838
* @author William Durand <william.durand1@gmail.com>.
3939
*/
40-
class BazingaGeocoderExtension extends Extension
40+
final class BazingaGeocoderExtension extends Extension
4141
{
4242
/**
4343
* @param array<mixed, mixed> $configs
44-
*
45-
* @return void
4644
*/
47-
public function load(array $configs, ContainerBuilder $container)
45+
public function load(array $configs, ContainerBuilder $container): void
4846
{
4947
$processor = new Processor();
5048
$configuration = $this->getConfiguration($configs, $container);
5149
$config = $processor->processConfiguration($configuration, $configs);
5250

53-
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../config'));
54-
$loader->load('services.yml');
51+
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../config'));
52+
$loader->load('services.php');
5553

5654
if (true === $config['profiling']['enabled']) {
57-
$loader->load('profiling.yml');
55+
$loader->load('profiling.php');
5856
}
5957

6058
if ($config['fake_ip']['enabled']) {
@@ -78,10 +76,8 @@ public function load(array $configs, ContainerBuilder $container)
7876

7977
/**
8078
* @param array<mixed, mixed> $config
81-
*
82-
* @return void
8379
*/
84-
private function loadProviders(ContainerBuilder $container, array $config)
80+
private function loadProviders(ContainerBuilder $container, array $config): void
8581
{
8682
foreach ($config['providers'] as $providerName => $providerConfig) {
8783
try {
@@ -93,7 +89,7 @@ private function loadProviders(ContainerBuilder $container, array $config)
9389
// See if any option has a service reference
9490
$providerConfig['options'] = $this->findReferences($providerConfig['options']);
9591
$factoryClass::validate($providerConfig['options'], $providerName);
96-
} catch (ServiceNotFoundException $e) {
92+
} catch (ServiceNotFoundException) {
9793
// Assert: We are using a custom factory. If invalid config, it will be caught in FactoryValidatorPass
9894
$providerConfig['options'] = $this->findReferences($providerConfig['options']);
9995
FactoryValidatorPass::addFactoryServiceId($providerConfig['factory']);

0 commit comments

Comments
 (0)