From a59edabbfe9daea27cbefd6d72c673d24a229880 Mon Sep 17 00:00:00 2001 From: Attila Fulop <1162360+fulopattila122@users.noreply.github.com> Date: Sun, 24 Mar 2024 22:02:20 +0200 Subject: [PATCH] Renamed the `TaxRateResolver` interface to `TaxEngineDriver` --- src/Foundation/Listeners/CalculateTaxes.php | 4 ++-- .../Tests/Examples/ExampleTaxEngine.php | 4 ++-- src/Foundation/Tests/TaxCalculationTest.php | 2 +- ...TaxRateResolver.php => TaxEngineDriver.php} | 4 ++-- .../NullTaxEngineDriver.php} | 8 ++++---- .../SimpleTaxEngineDriver.php} | 8 ++++---- .../{Resolver => Drivers}/TaxEngineManager.php | 18 +++++++++--------- src/Taxes/Facades/TaxEngine.php | 6 +++--- src/Taxes/Providers/ModuleServiceProvider.php | 6 +++--- src/Taxes/Tests/Dummies/DummyTaxDriver.php | 4 ++-- src/Taxes/Tests/TaxEngineTest.php | 6 +++--- src/Taxes/resources/config/module.php | 2 +- 12 files changed, 36 insertions(+), 36 deletions(-) rename src/Taxes/Contracts/{TaxRateResolver.php => TaxEngineDriver.php} (85%) rename src/Taxes/{Resolver/NullTaxRateResolver.php => Drivers/NullTaxEngineDriver.php} (74%) rename src/Taxes/{Resolver/SimpleTaxRateResolver.php => Drivers/SimpleTaxEngineDriver.php} (85%) rename src/Taxes/{Resolver => Drivers}/TaxEngineManager.php (86%) diff --git a/src/Foundation/Listeners/CalculateTaxes.php b/src/Foundation/Listeners/CalculateTaxes.php index 17086683f..ddf851d47 100644 --- a/src/Foundation/Listeners/CalculateTaxes.php +++ b/src/Foundation/Listeners/CalculateTaxes.php @@ -24,12 +24,12 @@ use Vanilo\Checkout\Facades\Checkout; use Vanilo\Foundation\Models\CartItem; use Vanilo\Support\Dto\DetailedAmount; -use Vanilo\Taxes\Contracts\TaxRateResolver; +use Vanilo\Taxes\Contracts\TaxEngineDriver; class CalculateTaxes { public function __construct( - protected ?TaxRateResolver $taxEngine, + protected ?TaxEngineDriver $taxEngine, ) { } diff --git a/src/Foundation/Tests/Examples/ExampleTaxEngine.php b/src/Foundation/Tests/Examples/ExampleTaxEngine.php index 750338619..87c704cf0 100644 --- a/src/Foundation/Tests/Examples/ExampleTaxEngine.php +++ b/src/Foundation/Tests/Examples/ExampleTaxEngine.php @@ -18,7 +18,7 @@ use Vanilo\Contracts\Billpayer; use Vanilo\Taxes\Contracts\Taxable; use Vanilo\Taxes\Contracts\TaxRate; -use Vanilo\Taxes\Contracts\TaxRateResolver; +use Vanilo\Taxes\Contracts\TaxEngineDriver; use Vanilo\Taxes\Models\TaxCategoryType; /** @@ -29,7 +29,7 @@ * - shipping: 7% * - everything else: 15% */ -class ExampleTaxEngine implements TaxRateResolver +class ExampleTaxEngine implements TaxEngineDriver { public const ID = 'example'; diff --git a/src/Foundation/Tests/TaxCalculationTest.php b/src/Foundation/Tests/TaxCalculationTest.php index 7474c76e1..e24440e42 100644 --- a/src/Foundation/Tests/TaxCalculationTest.php +++ b/src/Foundation/Tests/TaxCalculationTest.php @@ -24,7 +24,7 @@ use Vanilo\Taxes\Facades\TaxEngine; use Vanilo\Taxes\Models\TaxCategory; use Vanilo\Taxes\Models\TaxCategoryType; -use Vanilo\Taxes\Resolver\TaxEngineManager; +use Vanilo\Taxes\Drivers\TaxEngineManager; use Vanilo\Taxes\TaxCalculators; class TaxCalculationTest extends TestCase diff --git a/src/Taxes/Contracts/TaxRateResolver.php b/src/Taxes/Contracts/TaxEngineDriver.php similarity index 85% rename from src/Taxes/Contracts/TaxRateResolver.php rename to src/Taxes/Contracts/TaxEngineDriver.php index ee65957fc..b61fc29ae 100644 --- a/src/Taxes/Contracts/TaxRateResolver.php +++ b/src/Taxes/Contracts/TaxEngineDriver.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Contains the TaxRateResolver interface. + * Contains the TaxEngineDriver interface. * * @copyright Copyright (c) 2024 Vanilo UG * @author Attila Fulop @@ -17,7 +17,7 @@ use Vanilo\Contracts\Address; use Vanilo\Contracts\Billpayer; -interface TaxRateResolver +interface TaxEngineDriver { public function findTaxRate(Taxable $taxable, ?Billpayer $billpayer = null, ?Address $shippingAddress = null): ?TaxRate; } diff --git a/src/Taxes/Resolver/NullTaxRateResolver.php b/src/Taxes/Drivers/NullTaxEngineDriver.php similarity index 74% rename from src/Taxes/Resolver/NullTaxRateResolver.php rename to src/Taxes/Drivers/NullTaxEngineDriver.php index 5306aee38..e89825ffe 100644 --- a/src/Taxes/Resolver/NullTaxRateResolver.php +++ b/src/Taxes/Drivers/NullTaxEngineDriver.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Contains the NullTaxRateResolver class. + * Contains the NullTaxEngineDriver class. * * @copyright Copyright (c) 2024 Vanilo UG * @author Attila Fulop @@ -12,15 +12,15 @@ * */ -namespace Vanilo\Taxes\Resolver; +namespace Vanilo\Taxes\Drivers; use Vanilo\Contracts\Address; use Vanilo\Contracts\Billpayer; use Vanilo\Taxes\Contracts\Taxable; use Vanilo\Taxes\Contracts\TaxRate; -use Vanilo\Taxes\Contracts\TaxRateResolver; +use Vanilo\Taxes\Contracts\TaxEngineDriver; -class NullTaxRateResolver implements TaxRateResolver +class NullTaxEngineDriver implements TaxEngineDriver { public const ID = 'none'; diff --git a/src/Taxes/Resolver/SimpleTaxRateResolver.php b/src/Taxes/Drivers/SimpleTaxEngineDriver.php similarity index 85% rename from src/Taxes/Resolver/SimpleTaxRateResolver.php rename to src/Taxes/Drivers/SimpleTaxEngineDriver.php index 057d18a73..13192e456 100644 --- a/src/Taxes/Resolver/SimpleTaxRateResolver.php +++ b/src/Taxes/Drivers/SimpleTaxEngineDriver.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Contains the SimpleTaxRateResolver class. + * Contains the SimpleTaxEngineDriver class. * * @copyright Copyright (c) 2024 Vanilo UG * @author Attila Fulop @@ -12,17 +12,17 @@ * */ -namespace Vanilo\Taxes\Resolver; +namespace Vanilo\Taxes\Drivers; use Konekt\Address\Query\Zones; use Vanilo\Contracts\Address; use Vanilo\Contracts\Billpayer; use Vanilo\Taxes\Contracts\Taxable; use Vanilo\Taxes\Contracts\TaxRate; -use Vanilo\Taxes\Contracts\TaxRateResolver; +use Vanilo\Taxes\Contracts\TaxEngineDriver; use Vanilo\Taxes\Models\TaxRateProxy; -class SimpleTaxRateResolver implements TaxRateResolver +class SimpleTaxEngineDriver implements TaxEngineDriver { public function __construct( private readonly bool $useShippingAddress = false, diff --git a/src/Taxes/Resolver/TaxEngineManager.php b/src/Taxes/Drivers/TaxEngineManager.php similarity index 86% rename from src/Taxes/Resolver/TaxEngineManager.php rename to src/Taxes/Drivers/TaxEngineManager.php index 3e5ab115f..25a88f7cc 100644 --- a/src/Taxes/Resolver/TaxEngineManager.php +++ b/src/Taxes/Drivers/TaxEngineManager.php @@ -12,7 +12,7 @@ * */ -namespace Vanilo\Taxes\Resolver; +namespace Vanilo\Taxes\Drivers; use Illuminate\Contracts\Foundation\Application; use InvalidArgumentException; @@ -20,7 +20,7 @@ use Vanilo\Contracts\Address; use Vanilo\Taxes\Contracts\Taxable; use Vanilo\Taxes\Contracts\TaxRate; -use Vanilo\Taxes\Contracts\TaxRateResolver; +use Vanilo\Taxes\Contracts\TaxEngineDriver; use Vanilo\Taxes\Exceptions\InvalidTaxConfigurationException; class TaxEngineManager @@ -30,8 +30,8 @@ class TaxEngineManager /** The array of registered Tax Resolver drivers */ protected static array $drivers = [ - self::NULL_DRIVER => NullTaxRateResolver::class, - self::SIMPLE_DRIVER => SimpleTaxRateResolver::class + self::NULL_DRIVER => NullTaxEngineDriver::class, + self::SIMPLE_DRIVER => SimpleTaxEngineDriver::class ]; /** The array of resolved tax resolver instances.*/ @@ -52,7 +52,7 @@ public function driverExists(string $driverName): bool return isset(self::$drivers[$driverName]); } - public function driver(?string $name = null): TaxRateResolver + public function driver(?string $name = null): TaxEngineDriver { $name = $name ?: $this->getDefaultDriver(); @@ -61,7 +61,7 @@ public function driver(?string $name = null): TaxRateResolver public function extend(string $name, string|callable $driver): void { - if (is_callable($driver) || (is_string($driver) && is_subclass_of($driver, TaxRateResolver::class))) { + if (is_callable($driver) || (is_string($driver) && is_subclass_of($driver, TaxEngineDriver::class))) { self::$drivers[$name] = $driver; if (isset($this->instances[$name])) { unset($this->instances[$name]); @@ -83,12 +83,12 @@ protected function getDefaultDriver(): string return $this->app['config']['vanilo.taxes.engine.driver'] ?? self::NULL_DRIVER; } - protected function resolve(string $name): TaxRateResolver + protected function resolve(string $name): TaxEngineDriver { if (null === $driver = self::$drivers[$name]) { throw new InvalidTaxConfigurationException("The tax engine driver [{$name}] is not defined."); } elseif (self::NULL_DRIVER === $driver) { - return new NullTaxRateResolver(); + return new NullTaxEngineDriver(); } $instance = match (true) { @@ -96,7 +96,7 @@ protected function resolve(string $name): TaxRateResolver is_callable($driver) => call_user_func($driver, $this->app['config']["vanilo.taxes.engine.{$name}"] ?? []), }; - if ($instance instanceof TaxRateResolver) { + if ($instance instanceof TaxEngineDriver) { return $instance; } diff --git a/src/Taxes/Facades/TaxEngine.php b/src/Taxes/Facades/TaxEngine.php index c9e6f9c51..e9bb4855a 100644 --- a/src/Taxes/Facades/TaxEngine.php +++ b/src/Taxes/Facades/TaxEngine.php @@ -18,11 +18,11 @@ use Vanilo\Contracts\Address; use Vanilo\Taxes\Contracts\Taxable; use Vanilo\Taxes\Contracts\TaxRate; -use Vanilo\Taxes\Contracts\TaxRateResolver; -use Vanilo\Taxes\Resolver\TaxEngineManager; +use Vanilo\Taxes\Contracts\TaxEngineDriver; +use Vanilo\Taxes\Drivers\TaxEngineManager; /** - * @method static TaxRateResolver driver(string|null $name = null) + * @method static TaxEngineDriver driver(string|null $name = null) * @method static TaxRate|null findTaxRate(Taxable $taxable, Address|null $billingAddress = null, Address|null $shippingAddress = null) * @method static void extend(string $name, string|callable $driver) * @method static bool driverExists(string $driverName) diff --git a/src/Taxes/Providers/ModuleServiceProvider.php b/src/Taxes/Providers/ModuleServiceProvider.php index fff5289d5..c5ca04be5 100644 --- a/src/Taxes/Providers/ModuleServiceProvider.php +++ b/src/Taxes/Providers/ModuleServiceProvider.php @@ -17,11 +17,11 @@ use Konekt\Concord\BaseModuleServiceProvider; use Vanilo\Taxes\Calculators\DefaultTaxCalculator; use Vanilo\Taxes\Calculators\NullTaxCalculator; -use Vanilo\Taxes\Contracts\TaxRateResolver; +use Vanilo\Taxes\Contracts\TaxEngineDriver; use Vanilo\Taxes\Models\TaxCategory; use Vanilo\Taxes\Models\TaxCategoryType; use Vanilo\Taxes\Models\TaxRate; -use Vanilo\Taxes\Resolver\TaxEngineManager; +use Vanilo\Taxes\Drivers\TaxEngineManager; use Vanilo\Taxes\TaxCalculators; class ModuleServiceProvider extends BaseModuleServiceProvider @@ -40,7 +40,7 @@ public function register(): void parent::register(); $this->app->singleton(TaxEngineManager::class, fn ($app) => new TaxEngineManager($app)); - $this->app->bind(TaxRateResolver::class, fn ($app) => $app->make(TaxEngineManager::class)->driver()); + $this->app->bind(TaxEngineDriver::class, fn ($app) => $app->make(TaxEngineManager::class)->driver()); TaxCalculators::register('none', NullTaxCalculator::class); TaxCalculators::register('default', DefaultTaxCalculator::class); diff --git a/src/Taxes/Tests/Dummies/DummyTaxDriver.php b/src/Taxes/Tests/Dummies/DummyTaxDriver.php index 287bf5348..3141b4d11 100644 --- a/src/Taxes/Tests/Dummies/DummyTaxDriver.php +++ b/src/Taxes/Tests/Dummies/DummyTaxDriver.php @@ -18,9 +18,9 @@ use Vanilo\Contracts\Billpayer; use Vanilo\Taxes\Contracts\Taxable; use Vanilo\Taxes\Contracts\TaxRate; -use Vanilo\Taxes\Contracts\TaxRateResolver; +use Vanilo\Taxes\Contracts\TaxEngineDriver; -class DummyTaxDriver implements TaxRateResolver +class DummyTaxDriver implements TaxEngineDriver { public const TEST_RATE = 66; diff --git a/src/Taxes/Tests/TaxEngineTest.php b/src/Taxes/Tests/TaxEngineTest.php index edd7c0c85..8cbf94050 100644 --- a/src/Taxes/Tests/TaxEngineTest.php +++ b/src/Taxes/Tests/TaxEngineTest.php @@ -4,8 +4,8 @@ use Illuminate\Support\Facades\App; use Vanilo\Taxes\Facades\TaxEngine; -use Vanilo\Taxes\Resolver\NullTaxRateResolver; -use Vanilo\Taxes\Resolver\TaxEngineManager; +use Vanilo\Taxes\Drivers\NullTaxEngineDriver; +use Vanilo\Taxes\Drivers\TaxEngineManager; use Vanilo\Taxes\Tests\Dummies\DummyTaxDriver; use Vanilo\Taxes\Tests\Dummies\SampleTaxable; use Vanilo\Taxes\Tests\TestCase; @@ -34,7 +34,7 @@ public function the_default_driver_is_none() { $manager = App::make(TaxEngineManager::class); - $this->assertInstanceOf(NullTaxRateResolver::class, $manager->driver()); + $this->assertInstanceOf(NullTaxEngineDriver::class, $manager->driver()); } /** @test */ diff --git a/src/Taxes/resources/config/module.php b/src/Taxes/resources/config/module.php index 61cae19db..05507c0d5 100644 --- a/src/Taxes/resources/config/module.php +++ b/src/Taxes/resources/config/module.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use Vanilo\Taxes\Resolver\TaxEngineManager; +use Vanilo\Taxes\Drivers\TaxEngineManager; return [ 'engine' => [