Skip to content

Commit

Permalink
fix code style and psalm errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gewebe committed Jan 13, 2021
1 parent e6dc787 commit dedeced
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 49 deletions.
3 changes: 3 additions & 0 deletions src/Command/EuInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ private function getArgumentCountry(InputInterface $input): string
return strtolower($country);
}

/**
* @return string[]
*/
private function getOptionCategories(InputInterface $input): array
{
$categories = $input->getOption('categories');
Expand Down
7 changes: 5 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

final class Configuration implements ConfigurationInterface
{
/** {@inheritdoc} */
/**
* @psalm-suppress MixedMethodCall
* @psalm-suppress PossiblyUndefinedMethod
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('gewebe_sylius_vat');
Expand All @@ -33,7 +36,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->booleanNode('on_login')->defaultValue(true)->end()
->integerNode('expiration_days')->defaultValue(30)->end()
->end()
->end() // revalidiate
->end() // revalidate
;

return $treeBuilder;
Expand Down
23 changes: 14 additions & 9 deletions src/DependencyInjection/GewebeSyliusVATExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,29 @@

final class GewebeSyliusVATExtension extends Extension
{
/** {@inheritdoc} */
public function load(array $config, ContainerBuilder $container): void
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');

$config = $this->processConfiguration($this->getConfiguration([], $container), $config);
$configuration = $this->getConfiguration([], $container);
if ($configuration === null) {
return;
}

/** @var string[][] $configs */
$configs = $this->processConfiguration($configuration, $configs);

$definition = $container->getDefinition('gewebe_sylius_vat_plugin.order_processor');
$definition->replaceArgument(0, $config['order']['recalculate']);
$definition->replaceArgument(0, $configs['order']['recalculate']);

$definition = $container->getDefinition('gewebe_sylius_vat_plugin.validator');
$definition->replaceArgument(1, $config['validate']['format']);
$definition->replaceArgument(2, $config['validate']['country']);
$definition->replaceArgument(3, $config['validate']['existence']);
$definition->replaceArgument(1, $configs['validate']['format']);
$definition->replaceArgument(2, $configs['validate']['country']);
$definition->replaceArgument(3, $configs['validate']['existence']);

$definition = $container->getDefinition('Gewebe\SyliusVATPlugin\EventListener\LoginListener');
$definition->replaceArgument(1, $config['revalidate']['on_login']);
$definition->replaceArgument(2, $config['revalidate']['expiration_days']);
$definition->replaceArgument(1, $configs['revalidate']['on_login']);
$definition->replaceArgument(2, $configs['revalidate']['expiration_days']);
}
}
6 changes: 0 additions & 6 deletions src/Entity/VatNumberAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,32 @@ trait VatNumberAwareTrait
*/
protected $vatValidatedAt;

/** {@inheritdoc} */
public function getVatNumber(): ?string
{
return $this->vatNumber;
}

/** {@inheritdoc} */
public function setVatNumber(?string $vatNumber): void
{
$this->vatNumber = $vatNumber;
}

/** {@inheritdoc} */
public function hasVatNumber(): bool
{
return is_string($this->vatNumber) && strlen($this->vatNumber) > 0;
}

/** {@inheritdoc} */
public function hasValidVatNumber(): bool
{
return ($this->hasVatNumber() && $this->vatValid === true);
}

/** {@inheritdoc} */
public function setVatValid(bool $valid, ?DateTime $validatedAt = null): void
{
$this->vatValid = $valid;
$this->vatValidatedAt = $validatedAt ?? new DateTime();
}

/** {@inheritdoc} */
public function getVatValidatedAt(): ?DateTime
{
return $this->vatValidatedAt;
Expand Down
9 changes: 4 additions & 5 deletions src/OrderProcessing/VatNumberOrderProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

use Gewebe\SyliusVATPlugin\Entity\VatNumberAddressInterface;
use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ShopBillingDataInterface;
use Sylius\Component\Order\Model\OrderInterface;
use Sylius\Component\Order\Processor\OrderProcessorInterface;

Expand Down Expand Up @@ -44,12 +42,13 @@ public function process(OrderInterface $order): void
*/
private function isValidForZeroTax(OrderInterface $order): bool
{
/** @var ChannelInterface $channel */
$channel = $order->getChannel();
if ($channel === null) {
return false;
}

/** @var ShopBillingDataInterface $shopBillingData */
$shopBillingData = $channel->getShopBillingData();
if ($shopBillingData == null) {
if ($shopBillingData === null) {
return false;
}

Expand Down
1 change: 0 additions & 1 deletion src/Validator/Constraints/VatNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class VatNumber extends Constraint
/** @var string */
public $vatNumberPath = 'vatNumber';

/** {@inheritdoc} */
public function getTargets()
{
return [self::CLASS_CONSTRAINT, self::PROPERTY_CONSTRAINT];
Expand Down
21 changes: 7 additions & 14 deletions src/Validator/Constraints/VatNumberValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
class VatNumberValidator extends ConstraintValidator
{
/** @var ValidatorInterface */
Expand All @@ -38,20 +41,19 @@ public function __construct(
$this->validateExistence = $validateExistence;
}

public function validate($address, Constraint $constraint): void
public function validate($value, Constraint $constraint): void
{
// need value only as address entity with vat
if (!$address instanceof VatNumberAddressInterface) {
if (!$value instanceof VatNumberAddressInterface) {
#throw new UnexpectedValueException($address, VatNumberAddressInterface::class);
return;
}

$address = $value;

if (!$constraint instanceof VatNumber) {
throw new UnexpectedTypeException($constraint, VatNumber::class);
}

// custom constraints should ignore null and empty values to allow
// other constraints (NotBlank, NotNull, etc.) take care of that
if (null === $address->getVatNumber() || '' === $address->getVatNumber()) {
return;
}
Expand All @@ -71,9 +73,6 @@ public function validate($address, Constraint $constraint): void

/**
* check vat number format
* @param VatNumberAddressInterface $address
* @param VatNumber $constraint
* @return bool
*/
private function validateFormat(VatNumberAddressInterface $address, VatNumber $constraint): bool
{
Expand All @@ -90,9 +89,6 @@ private function validateFormat(VatNumberAddressInterface $address, VatNumber $c

/**
* check vat number country is same as address country
* @param VatNumberAddressInterface $address
* @param VatNumber $constraint
* @return bool
*/
private function validateCountry(VatNumberAddressInterface $address, VatNumber $constraint): bool
{
Expand All @@ -112,9 +108,6 @@ private function validateCountry(VatNumberAddressInterface $address, VatNumber $

/**
* check vat number existence
* @param VatNumberAddressInterface $address
* @param VatNumber $constraint
* @return bool
*/
private function validateExistence(VatNumberAddressInterface $address, VatNumber $constraint): bool
{
Expand Down
5 changes: 1 addition & 4 deletions src/Vat/Number/EuValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function __construct(Validator $validator)
$this->validator = $validator;
}

/** @inheritDoc */
public function validateCountry(string $vatNumber, string $countryCode): bool
{
$country = substr($vatNumber, 0, 2);
Expand All @@ -31,19 +30,17 @@ public function validateCountry(string $vatNumber, string $countryCode): bool
return false;
}

/** @inheritDoc */
public function validateFormat(string $vatNumber): bool
{
return $this->validator->validateVatNumberFormat($vatNumber);
}

/** @inheritDoc */
public function validate(string $vatNumber): bool
{
try {
return $this->validator->validateVatNumber($vatNumber);
} catch (ViesException $e) {
throw new ClientException($e->getMessage(), $e->getCode());
throw new ClientException($e->getMessage(), (int) $e->getCode());
}
}
}
10 changes: 5 additions & 5 deletions src/Vat/Rates/EuRates.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ public function __construct(
$this->countries = new Countries();
}

/** @inheritDoc */
public function getCountries(): array
{
$euCountries = [];

/**
* @var string $countryCode
* @var string $countryName
*/
foreach ($this->countries as $countryCode => $countryName) {
if (!$this->countries->isCountryCodeInEU($countryCode)) {
continue;
Expand All @@ -40,10 +44,6 @@ public function getCountries(): array
return $euCountries;
}

/**
* @inheritDoc
* @throws \Exception
*/
public function getCountryRate(string $countryCode, string $level = self::RATE_STANDARD): float
{
return $this->rates->getRateForCountry($countryCode, $level);
Expand Down
4 changes: 1 addition & 3 deletions src/Vat/Rates/RatesInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ interface RatesInterface
public const RATE_STANDARD = 'standard';
public const RATE_REDUCED = 'reduced';

/**
* @return array
*/
/** @return array<string, string> */
public function getCountries(): array;

/**
Expand Down

0 comments on commit dedeced

Please sign in to comment.