Skip to content

Commit 024d1ce

Browse files
committed
PHP CS Fixer
1 parent dc0aa66 commit 024d1ce

21 files changed

+75
-72
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ composer.lock
88
*/.iws
99
npm-debug.log
1010
.phpunit.result.cache
11+
.php-cs-fixer.cache

.php-cs-fixer.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
'no_empty_comment' => true,
3535
'no_empty_phpdoc' => true,
3636
'no_extra_blank_lines' => [
37-
'extra',
38-
'use',
39-
'use_trait',
40-
'return',
37+
'tokens' => [
38+
'extra',
39+
'use',
40+
'use_trait',
41+
'return',
42+
],
4143
],
4244
'no_leading_import_slash' => true,
4345
'no_leading_namespace_whitespace' => true,
@@ -48,7 +50,7 @@
4850
'no_useless_else' => true,
4951
'no_useless_return' => true,
5052
'single_trait_insert_per_statement' => true,
51-
'psr4' => true,
53+
'psr_autoloading' => true,
5254
'dir_constant' => true,
5355
'single_line_comment_style' => [
5456
'comment_types' => ['hash'],
@@ -97,7 +99,7 @@
9799
'standardize_not_equals' => true,
98100
'ternary_operator_spaces' => true,
99101
'whitespace_after_comma_in_array' => true,
100-
'trailing_comma_in_multiline_array' => true,
102+
'trailing_comma_in_multiline' => true,
101103
'trim_array_spaces' => true,
102104
'binary_operator_spaces' => true,
103105
'unary_operator_spaces' => true,

config/addressing.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
return [
44
/*
5-
|--------------------------------------------------------------------------
6-
| Route Configuration
7-
|--------------------------------------------------------------------------
8-
*/
5+
|--------------------------------------------------------------------------
6+
| Route Configuration
7+
|--------------------------------------------------------------------------
8+
*/
99
'routes' => [
1010
'enabled' => true,
1111
'prefix' => 'galahad/addressing',

src/Collection/CountryCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function toArray(): array
7474

7575
public function toSelectArray(): array
7676
{
77-
return $this->mapWithKeys(static function (Country $country) {
77+
return $this->mapWithKeys(static function(Country $country) {
7878
return [$country->getCountryCode() => $country->getName()];
7979
})->toArray();
8080
}

src/Collection/SubdivisionCollection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function toArray(): array
109109

110110
public function toSelectArray(): array
111111
{
112-
return $this->mapWithKeys(static function (Subdivision $subdivision) {
112+
return $this->mapWithKeys(static function(Subdivision $subdivision) {
113113
return [$subdivision->getCode() => $subdivision->getName()];
114114
})->toArray();
115115
}

src/Entity/AdministrativeArea.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public function is(Subdivision $subdivision = null): bool
2525
}
2626

2727
return $this->getCountry()->is($subdivision->getCountry())
28-
&& $this->getCode() === $subdivision->getCode();
28+
&& $this->getCode() === $subdivision->getCode();
2929
}
3030
}

src/Entity/Country.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ public function administrativeArea(string $code): ?AdministrativeArea
8282
// If that doesn't work, do a case-insensitive lookup.
8383

8484
return $this->administrativeAreas()->get(strtoupper($code))
85-
?? $this->administrativeAreas()->first(fn(AdministrativeArea $subdivision) => 0 === strcasecmp($subdivision->getCode(), $code));
85+
?? $this->administrativeAreas()->first(fn(AdministrativeArea $subdivision) => 0 === strcasecmp($subdivision->getCode(), $code));
8686
}
8787

8888
public function administrativeAreaByName(string $name): ?AdministrativeArea
8989
{
9090
return $this->administrativeAreas()
91-
->first(fn(AdministrativeArea $subdivision) => 0 === strcasecmp($subdivision->getName(), $name));
91+
->first(fn(AdministrativeArea $subdivision) => 0 === strcasecmp($subdivision->getName(), $name));
9292
}
9393

9494
/**

src/Entity/Subdivision.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getParent(): ?self
5959
public function getPostalCodePattern(): ?string
6060
{
6161
return $this->subdivision->getPostalCodePattern()
62-
?? $this->country->addressFormat()->getPostalCodePattern();
62+
?? $this->country->addressFormat()->getPostalCodePattern();
6363
}
6464

6565
public function getPostalCodePatternType(): string

src/LaravelAddressing.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function country($country_code, $locale = null): ?Country
9393
$this->address_format_repository
9494
));
9595
} catch (UnknownCountryException $exception) {
96-
//
96+
9797
}
9898
}
9999

@@ -135,9 +135,9 @@ public function countries($locale = null): CountryCollection
135135
public function countryByName($name): ?Country
136136
{
137137
return $this->countries()
138-
->first(static function (Country $country) use ($name) {
139-
return 0 === strcasecmp($country->getName(), $name);
140-
});
138+
->first(static function(Country $country) use ($name) {
139+
return 0 === strcasecmp($country->getName(), $name);
140+
});
141141
}
142142

143143
/**

src/Support/AddressingServiceProvider.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function register(): void
3636
{
3737
$this->mergeConfigFrom(__DIR__.'/../../config/addressing.php', 'addressing');
3838

39-
$this->app->singleton(LaravelAddressing::class, static function (Application $app) {
39+
$this->app->singleton(LaravelAddressing::class, static function(Application $app) {
4040
$locale = $app['config']->get('app.locale', 'en');
4141
$fallback_locale = $app['config']->get('app.fallback_locale', 'en');
4242

@@ -79,12 +79,12 @@ protected function bootRoutes(): void
7979

8080
$prefix = $config->get('addressing.routes.prefix', 'galahad/addressing');
8181

82-
$router->group(compact('prefix'), static function (Registrar $route) {
82+
$router->group(compact('prefix'), static function(Registrar $route) {
8383
$route->get('/countries', CountriesController::class)
84-
->name('galahad.addressing.countries');
84+
->name('galahad.addressing.countries');
8585

8686
$route->get('/countries/{country_code}/administrative-areas', AdministrativeAreasController::class)
87-
->name('galahad.addressing.administrative-areas');
87+
->name('galahad.addressing.administrative-areas');
8888
});
8989
} catch (BindingResolutionException $exception) {
9090
// Skip routes if no router exists
@@ -96,7 +96,7 @@ protected function bootRoutes(): void
9696
*/
9797
protected function registerValidators(): void
9898
{
99-
$this->app->resolving(Factory::class, static function (Factory $validation_factory, Container $app) {
99+
$this->app->resolving(Factory::class, static function(Factory $validation_factory, Container $app) {
100100
$validator = new Validator($app->make(LaravelAddressing::class));
101101

102102
$validation_factory->extend('country', Closure::fromCallable([$validator, 'looseCountry']));

src/Support/Http/AdministrativeAreasController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public function __invoke(LaravelAddressing $addressing, Repository $config, Requ
2929
'label' => ucwords(Str::plural($address_format->getAdministrativeAreaType() ?? 'state', $administrative_areas->count())),
3030
'country_code' => $country_code,
3131
'options' => $administrative_areas
32-
->map(static function (Subdivision $admin_area) {
33-
return $admin_area->getName();
34-
})
35-
->toArray(),
32+
->map(static function(Subdivision $admin_area) {
33+
return $admin_area->getName();
34+
})
35+
->toArray(),
3636
], 200);
3737
}
3838
}

src/Support/Http/CountriesController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __invoke(LaravelAddressing $addressing, Repository $config, Requ
1717

1818
return new JsonResponse([
1919
'label' => 'Countries',
20-
'options' => $countries->map(static function (Country $country) {
20+
'options' => $countries->map(static function(Country $country) {
2121
return $country->getName();
2222
})->toArray(),
2323
], 200);

src/Support/Validation/Rules/LooseAdministrativeAreaRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(Country $country)
2828
public function passes($attribute, $value): bool
2929
{
3030
return (new AdministrativeAreaCodeRule($this->country))->passes($attribute, $value)
31-
?: (new AdministrativeAreaNameRule($this->country))->passes($attribute, $value);
31+
?: (new AdministrativeAreaNameRule($this->country))->passes($attribute, $value);
3232
}
3333

3434
/**

src/Support/Validation/Rules/LooseCountryRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(LaravelAddressing $addressing)
3333
public function passes($attribute, $value): bool
3434
{
3535
return (new CountryCodeRule($this->addressing))->passes($attribute, $value)
36-
?: (new CountryNameRule($this->addressing))->passes($attribute, $value);
36+
?: (new CountryNameRule($this->addressing))->passes($attribute, $value);
3737
}
3838

3939
/**

src/Support/Validation/Rules/PostalCodeRule.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ protected function isRequired(): bool
7474
protected function pattern(): ?string
7575
{
7676
$pattern = $this->administrative_area
77-
? $this->administrative_area->getPostalCodePattern()
78-
: $this->country->addressFormat()->getPostalCodePattern();
77+
? $this->administrative_area->getPostalCodePattern()
78+
: $this->country->addressFormat()->getPostalCodePattern();
7979

8080
$pattern_type = $this->administrative_area
81-
? $this->administrative_area->getPostalCodePatternType()
82-
: PatternType::FULL;
81+
? $this->administrative_area->getPostalCodePatternType()
82+
: PatternType::FULL;
8383

8484
if (PatternType::START === $pattern_type) {
8585
return '/^'.$pattern.'/i';

src/Support/Validation/Validator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ protected function loadAdministrativeAreaValueFromValidationData(array $paramete
185185
{
186186
// Either use the explicitly set name, or try all common names
187187
$possible_input_names = isset($parameters[1])
188-
? [$parameters[1]]
189-
: ['administrative_area', 'state', 'province'];
188+
? [$parameters[1]]
189+
: ['administrative_area', 'state', 'province'];
190190

191191
$data = $validator->getData();
192192
foreach ($possible_input_names as $input_name) {

tests/RoutesTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class RoutesTest extends TestCase
77
public function test_a_list_of_countries_can_be_loaded_via_http(): void
88
{
99
$response = $this->get(route('galahad.addressing.countries'))
10-
->assertOk()
11-
->assertJsonStructure(['label', 'options']);
10+
->assertOk()
11+
->assertJsonStructure(['label', 'options']);
1212

1313
$this->assertEquals('Countries', $response->json('label'));
1414

@@ -22,8 +22,8 @@ public function test_a_list_of_countries_can_be_loaded_via_http(): void
2222
public function test_a_list_of_us_states_can_be_loaded_via_http(): void
2323
{
2424
$response = $this->get(route('galahad.addressing.administrative-areas', 'us'))
25-
->assertOk()
26-
->assertJsonStructure(['label', 'country_code', 'options']);
25+
->assertOk()
26+
->assertJsonStructure(['label', 'country_code', 'options']);
2727

2828
$this->assertEquals('States', $response->json('label'));
2929

tests/TestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected function setUp(): void
1818
$config->set('app.key', 'base64:tfsezwCu4ZRixRLA/+yL/qoouX++Q3lPAPOAbtnBCG8=');
1919

2020
// Add feature stubs to view
21-
// $this->app['view']->addLocation(__DIR__.'/Feature/stubs');
21+
// $this->app['view']->addLocation(__DIR__.'/Feature/stubs');
2222
}
2323

2424
protected function getPackageProviders($app): array

tests/Validator/AdministrativeAreaValidatorTest.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -9,71 +9,71 @@
99
*/
1010
class AdministrativeAreaValidatorTest extends BaseValidatorTestCase
1111
{
12-
public function testMGStateInBrazil()
12+
public function test_mg_state_in_brazil()
1313
{
1414
$this->assertTrue($this->performValidation([
1515
'rules' => ['state' => 'administrative_area_code:country'],
1616
'data' => ['state' => 'MG', 'country' => 'BR'],
1717
]));
1818
}
1919

20-
public function testInvalidStateInBrazil()
20+
public function test_invalid_state_in_brazil()
2121
{
2222
$this->assertFalse($this->performValidation([
2323
'data' => ['country' => 'BR', 'state' => 'ZZ'],
2424
'rules' => ['state' => 'administrative_area_code:country'],
2525
]));
2626
}
2727

28-
public function testCOStateInUnitedStates()
28+
public function test_co_state_in_united_states()
2929
{
3030
$this->assertTrue($this->performValidation([
3131
'data' => ['country' => 'US', 'state' => 'CO'],
3232
'rules' => ['state' => 'administrative_area_code:country'],
3333
]));
3434
}
3535

36-
public function testCountryAndStateAreLowerCase()
36+
public function test_country_and_state_are_lower_case()
3737
{
3838
$this->assertTrue($this->performValidation([
3939
'data' => ['country' => 'us', 'state' => 'co'],
4040
'rules' => ['state' => 'administrative_area_code:country'],
4141
]));
4242
}
4343

44-
public function testPassesIfCountryHasNoAdminAreas()
44+
public function test_passes_if_country_has_no_admin_areas()
4545
{
4646
$this->assertTrue($this->performValidation([
4747
'data' => ['country' => 'GB', 'state' => ''],
4848
'rules' => ['state' => 'administrative_area_code:country'],
4949
]));
5050
}
5151

52-
public function testAdminAreaCodeArrayIsInvalid()
52+
public function test_admin_area_code_array_is_invalid()
5353
{
5454
$this->assertFalse($this->performValidation([
5555
'data' => ['country' => 'US', 'state' => ['CO']],
5656
'rules' => ['state' => 'administrative_area_code:country'],
5757
]));
5858
}
5959

60-
public function testAdminAreaNameArrayIsInvalid()
60+
public function test_admin_area_name_array_is_invalid()
6161
{
6262
$this->assertFalse($this->performValidation([
6363
'data' => ['country' => 'US', 'state' => ['Colorado']],
6464
'rules' => ['state' => 'administrative_area_name:country'],
6565
]));
6666
}
6767

68-
public function testGeneralAdminAreaArrayIsInvalid()
68+
public function test_general_admin_area_array_is_invalid()
6969
{
7070
$this->assertFalse($this->performValidation([
7171
'data' => ['country' => 'US', 'state' => ['CO']],
7272
'rules' => ['state' => 'administrative_area:country'],
7373
]));
7474
}
7575

76-
public function testUSStateByName()
76+
public function test_us_state_by_name()
7777
{
7878
// Valid state in US
7979
$this->assertTrue($this->performValidation([
@@ -87,7 +87,7 @@ public function testUSStateByName()
8787
]));
8888
}
8989

90-
public function testStateUsingCountryName()
90+
public function test_state_using_country_name()
9191
{
9292
// Valid US state
9393
$this->assertTrue($this->performValidation([
@@ -101,7 +101,7 @@ public function testStateUsingCountryName()
101101
]));
102102
}
103103

104-
public function testGeneralAdministrativeAreaValidation()
104+
public function test_general_administrative_area_validation()
105105
{
106106
// Valid US state
107107
$this->assertTrue($this->performValidation([
@@ -125,7 +125,7 @@ public function testGeneralAdministrativeAreaValidation()
125125
]));
126126
}
127127

128-
public function testUsesDefaultFieldNames()
128+
public function test_uses_default_field_names()
129129
{
130130
$this->assertTrue($this->performValidation([
131131
'data' => ['country' => 'US', 'state' => 'CO'],
@@ -148,7 +148,7 @@ public function testUsesDefaultFieldNames()
148148
]));
149149
}
150150

151-
public function testAllowsEmptyAdministrativeAreasInCountriesWhereItIsOptional()
151+
public function test_allows_empty_administrative_areas_in_countries_where_it_is_optional()
152152
{
153153
// Empty county should be allowed in Ireland
154154
$this->assertTrue($this->performValidation([
@@ -169,7 +169,7 @@ public function testAllowsEmptyAdministrativeAreasInCountriesWhereItIsOptional()
169169
]));
170170
}
171171

172-
public function testAllowsAnyAdminAreaInCountriesWeDontHaveDataFor()
172+
public function test_allows_any_admin_area_in_countries_we_dont_have_data_for()
173173
{
174174
// As of right now, addressing doesn't have an admin area list for South Africa
175175
$this->assertTrue($this->performValidation([

0 commit comments

Comments
 (0)