Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Laravel Pint

on:
pull_request:
types: [ opened, synchronize, reopened ]

jobs:
pint:
runs-on: ubuntu-latest

steps:
- name: Check out repository code
uses: actions/checkout@v6
with:
fetch-depth: 0
ref: ${{ github.head_ref }}

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'

- name: Install Dependencies
run: composer install --prefer-dist --no-interaction --no-scripts --no-progress

- name: Run Pint
run: ./vendor/bin/pint

- name: Create Pull Request
uses: peter-evans/create-pull-request@v8
id: cpr
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore(linter): Laravel pint has beautified your code'
title: Pint
branch: pint-fixes-${{ github.head_ref }}
base: ${{ github.head_ref }}
delete-branch: true
branch-suffix: short-commit-hash

- name: Exit if ECS made Changes
if: (steps.cpr.outputs.pull-request-operation == 'created') || (steps.cpr.outputs.pull-request-operation == 'updated')
run: exit 1
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
},
"require-dev": {
"larastan/larastan": "^3.0",
"laravel/pint": "^1.0",
"orchestra/testbench": "^10.0|^11.0",
"pestphp/pest": "^3.0|^4.0",
"pestphp/pest-plugin-laravel": "^3.0|^4.0"
Expand All @@ -58,6 +59,8 @@
},
"scripts": {
"test": "pest",
"stan": "phpstan analyse"
"stan": "phpstan analyse",
"lint": "pint",
"lint:test": "pint --test"
}
}
2 changes: 1 addition & 1 deletion config/addressable.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Byte5\Addressable\App\Models\Address;
use Byte5\Addressable\App\Enums\AddressType;
use Byte5\Addressable\App\Models\Address;

return [

Expand Down
2 changes: 1 addition & 1 deletion database/factories/AddressFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Byte5\Addressable\Database\Factories;

use Byte5\Addressable\App\Models\Address;
use Byte5\Addressable\App\Enums\AddressType;
use Byte5\Addressable\App\Models\Address;
use Byte5\Addressable\App\Support\Config;
use Illuminate\Database\Eloquent\Factories\Factory;

Expand Down
3 changes: 3 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"preset": "laravel"
}
4 changes: 2 additions & 2 deletions src/AddressableServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Byte5\Addressable;

use Byte5\Addressable\App\Contracts as Contracts;
use Byte5\Addressable\App\Services as Services;
use Byte5\Addressable\App\Contracts;
use Byte5\Addressable\App\Services;
use Illuminate\Support\ServiceProvider;

class AddressableServiceProvider extends ServiceProvider
Expand Down
1 change: 1 addition & 0 deletions src/App/Concerns/HasAddresses.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/**
* @phpstan-require-extends Model
*
* @phpstan-require-implements Addressable
*/
trait HasAddresses
Expand Down
3 changes: 2 additions & 1 deletion src/App/Contracts/ValidatesAddresses.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Byte5\Addressable\App\Data\AddressInput;
use Byte5\Addressable\App\Data\AddressValidation;
use Byte5\Addressable\App\Exceptions\AddressLookupException;

interface ValidatesAddresses
{
Expand All @@ -12,7 +13,7 @@ interface ValidatesAddresses
*
* @param array<string, mixed> $options
*
* @throws \Byte5\Addressable\App\Exceptions\AddressLookupException When the provider is misconfigured (e.g. missing API key), cannot be reached, or responds with an error status.
* @throws AddressLookupException When the provider is misconfigured (e.g. missing API key), cannot be reached, or responds with an error status.
*/
public function validate(AddressInput $address, array $options = []): AddressValidation;
}
6 changes: 3 additions & 3 deletions src/App/Data/AddressData.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public function __construct(
public ?string $postal = null,
public ?string $city = null,
public ?string $region = null,
public ?float $latitude = null,
public ?float $longitude = null,
public ?float $latitude = null,
public ?float $longitude = null,
public ?string $country = null,
) {}

/**
* Build from a loose attribute array (unknown keys ignored).
*
* @param array<string, mixed> $attributes
* @param array<string, mixed> $attributes
*/
public static function fromArray(array $attributes): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/App/Data/AddressValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @param string $provider The driver that produced this result, e.g. `google`.
* @param string|null $formattedAddress The provider's corrected/standardised address.
* @param array<string, mixed> $raw The provider's full response payload. Provider-specific fields
* (e.g. Google's `verdict`/`geocode`) live here.
* (e.g. Google's `verdict`/`geocode`) live here.
*/
public function __construct(
public bool $valid,
Expand Down
6 changes: 3 additions & 3 deletions src/App/Enums/AddressType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

enum AddressType: string
{
case Billing = 'billing';
case Billing = 'billing';
case Shipping = 'shipping';
case Home = 'home';
case Work = 'work';
case Home = 'home';
case Work = 'work';
}
2 changes: 1 addition & 1 deletion src/App/Facades/AddressRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @method static PostalFormat postalFormat(?string $country)
* @method static Country country()
*
* @see \Byte5\Addressable\App\Contracts\AddressRules
* @see AddressRulesContract
*/
class AddressRules extends Facade
{
Expand Down
2 changes: 1 addition & 1 deletion src/App/Facades/Countries.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Byte5\Addressable\App\Facades;

use Illuminate\Support\Facades\Facade;
use Byte5\Addressable\App\Contracts\Countries as CountryContract;
use Illuminate\Support\Facades\Facade;

/**
* @method static array<string, string> list(?string $locale = null)
Expand Down
4 changes: 2 additions & 2 deletions src/App/Models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Byte5\Addressable\App\Models;

use Byte5\Addressable\Database\Factories\AddressFactory;
use Byte5\Addressable\App\Data\PostalAddress;
use Byte5\Addressable\App\Support\Config;
use Byte5\Addressable\Database\Factories\AddressFactory;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand Down Expand Up @@ -53,7 +53,7 @@ protected static function newFactory(): AddressFactory
protected function country(): Attribute
{
return Attribute::make(
set: fn(?string $value) => $value === null ? null : strtoupper($value),
set: fn (?string $value) => $value === null ? null : strtoupper($value),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/App/Rules/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function validate(string $attribute, mixed $value, Closure $fail): void

private static function iso3166(): ISO3166
{
return self::$iso3166 ??= new ISO3166();
return self::$iso3166 ??= new ISO3166;
}
}
4 changes: 2 additions & 2 deletions src/App/Rules/PostalFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
// Mirror commerceguys/addressing: the pattern must match the value completely.
preg_match('/'.$pattern.'/i', $value, $matches);

if (!isset($matches[0]) || $matches[0] !== $value) {
if (! isset($matches[0]) || $matches[0] !== $value) {
$fail('byte5-addressable::validation.postal_format')->translate(['attribute' => $attribute]);
}
}

private static function repository(): AddressFormatRepository
{
return self::$repository ??= new AddressFormatRepository();
return self::$repository ??= new AddressFormatRepository;
}
}
2 changes: 1 addition & 1 deletion src/App/Services/AddressRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function postalFormat(?string $country): PostalFormat

public function country(): Country
{
return new Country();
return new Country;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/App/Services/Countries.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function list(?string $locale = null): array
// Iterate the commerceguys list to keep its locale-specific ordering.
return array_filter(
$names,
fn(string $code): bool => isset(self::isoCodes()[$code]),
fn (string $code): bool => isset(self::isoCodes()[$code]),
ARRAY_FILTER_USE_KEY,
);
}
Expand All @@ -51,11 +51,11 @@ private static function isoCodes(): array

private static function repository(): CountryRepository
{
return self::$repository ??= new CountryRepository();
return self::$repository ??= new CountryRepository;
}

private static function iso3166(): ISO3166
{
return self::$iso3166 ??= new ISO3166();
return self::$iso3166 ??= new ISO3166;
}
}
2 changes: 1 addition & 1 deletion src/lang/en/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
'country' => 'The :attribute is not a valid country.',
'postal_format' => 'The :attribute is not a valid postal code for the selected country.',
'address_exists' => 'The :attribute could not be verified as a deliverable address.',
];
];
7 changes: 4 additions & 3 deletions tests/Feature/AddressCreationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

$address = $model->addAddress([
'street' => 'Unter den Linden 1',
'city' => 'Berlin',
'city' => 'Berlin',
'postal' => '10117',
'country' => 'DE',
]);
Expand Down Expand Up @@ -84,10 +84,11 @@
$model = TestModel::create(['name' => 'Acme']);

$sentinel = $model->addresses()->create(['city' => 'Sentinel']);
$spy = (object) ['called' => false];
$spy = (object) ['called' => false];

app()->bind(CreatesAddresses::class, function () use ($sentinel, $spy): CreatesAddresses {
return new class ($sentinel, $spy) implements CreatesAddresses {
return new class($sentinel, $spy) implements CreatesAddresses
{
public function __construct(
private readonly Address $sentinel,
private readonly object $spy,
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/AddressLookupPersistenceTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Byte5\Addressable\App\Models\Address;
use Byte5\Addressable\App\Facades\AddressLookup;
use Byte5\Addressable\App\Models\Address;
use Byte5\Addressable\Tests\Fixtures\TestModel;
use Saloon\Http\Faking\MockClient;
use Saloon\Http\Faking\MockResponse;
Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/AddressRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
use Byte5\Addressable\App\Rules\PostalFormat;
use Illuminate\Translation\PotentiallyTranslatedString;

it('builds a PostalFormat rule through the facade', function() {
it('builds a PostalFormat rule through the facade', function () {
expect(AddressRules::postalFormat('DE'))->toBeInstanceOf(PostalFormat::class);
});

it('builds a Country rule through the facade', function() {
it('builds a Country rule through the facade', function () {
expect(AddressRules::country())->toBeInstanceOf(Country::class);
});

it('the facade-built rule validates the same as a new instance', function() {
$collect = function($rule) {
it('the facade-built rule validates the same as a new instance', function () {
$collect = function ($rule) {
$failures = [];
$rule->validate('postal', '123', function(string $message) use (&$failures) {
$rule->validate('postal', '123', function (string $message) use (&$failures) {
$failures[] = $string = new PotentiallyTranslatedString($message, app('translator'));

return $string;
Expand Down
Loading