Skip to content

Commit

Permalink
Renamed the TaxRateResolver interface to TaxEngineDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed Mar 24, 2024
1 parent 8bec71e commit a59edab
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/Foundation/Listeners/CalculateTaxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Foundation/Tests/Examples/ExampleTaxEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -29,7 +29,7 @@
* - shipping: 7%
* - everything else: 15%
*/
class ExampleTaxEngine implements TaxRateResolver
class ExampleTaxEngine implements TaxEngineDriver
{
public const ID = 'example';

Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Tests/TaxCalculationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
*
*/

namespace Vanilo\Taxes\Resolver;
namespace Vanilo\Taxes\Drivers;

use Illuminate\Contracts\Foundation\Application;
use InvalidArgumentException;
use LogicException;
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
Expand All @@ -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.*/
Expand All @@ -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();

Expand All @@ -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]);
Expand All @@ -83,20 +83,20 @@ 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) {
is_string($driver) && class_exists($driver) => $this->app->make($driver),
is_callable($driver) => call_user_func($driver, $this->app['config']["vanilo.taxes.engine.{$name}"] ?? []),
};

if ($instance instanceof TaxRateResolver) {
if ($instance instanceof TaxEngineDriver) {
return $instance;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Taxes/Facades/TaxEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/Taxes/Providers/ModuleServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/Taxes/Tests/Dummies/DummyTaxDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/Taxes/Tests/TaxEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/Taxes/resources/config/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use Vanilo\Taxes\Resolver\TaxEngineManager;
use Vanilo\Taxes\Drivers\TaxEngineManager;

return [
'engine' => [
Expand Down

0 comments on commit a59edab

Please sign in to comment.