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 ee53cd8 commit 4e9f567
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 209 deletions.
3 changes: 0 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

final class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('gewebe_product_deposit');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

final class GewebeSyliusProductDepositExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$config = $this->processConfiguration($this->getConfiguration([], $container), $configs);
Expand Down
41 changes: 6 additions & 35 deletions src/Entity/ChannelDeposit.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,18 @@
*/
class ChannelDeposit implements ChannelDepositInterface
{
/**
* @var int
*/
/** @var mixed */
private $id;

/**
* @var int
*/
/** @var int|null */
private $price;

/**
* @var string
*/
/** @var string|null */
private $channelCode;

/**
* @var ProductVariantInterface|null
*/
/** @var ProductVariantInterface|null */
private $productVariant;

/**
* {@inheritdoc}
*/
public function __toString(): string
{
return (string) $this->getPrice();
Expand All @@ -45,50 +34,32 @@ public function getId()
return $this->id;
}

/**
* @return int
*/
public function getPrice(): ?int
{
return $this->price;
}

/**
* @param int $price
*/
public function setPrice(int $price): void
public function setPrice(?int $price): void
{
$this->price = $price;
}

/**
* @return ProductVariantInterface|null
*/
public function getProductVariant(): ?ProductVariantInterface
{
return $this->productVariant;
}

/**
* @param ProductVariantInterface|null $productVariants
*/
public function setProductVariant(?ProductVariantInterface $productVariants): void
{
$this->productVariant = $productVariants;
}

/**
* @return string|null
*/
public function getChannelCode(): ?string
{
return $this->channelCode;
}

/**
* @param string $channelCode
*/
public function setChannelCode(string $channelCode): void
public function setChannelCode(?string $channelCode): void
{
$this->channelCode = $channelCode;
}
Expand Down
18 changes: 0 additions & 18 deletions src/Entity/ChannelDepositInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,15 @@
*/
interface ChannelDepositInterface extends ResourceInterface
{
/**
* @return int
*/
public function getPrice(): ?int;

/**
* @param int $price
*/
public function setPrice(int $price): void;

/**
* @return ProductVariantInterface|null
*/
public function getProductVariant(): ?ProductVariantInterface;

/**
* @param ProductVariantInterface $productVariants
*/
public function setProductVariant(?ProductVariantInterface $productVariants): void;

/**
* @return string
*/
public function getChannelCode(): ?string;

/**
* @param string $channelCode
*/
public function setChannelCode(string $channelCode): void;
}
3 changes: 2 additions & 1 deletion src/Entity/ProductVariant.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*
* @ORM\Entity
* @ORM\Table(name="sylius_product_variant")
*
* @psalm-suppress PropertyNotSetInConstructor
*/
class ProductVariant extends BaseProductVariant implements DepositProductVariantInterface
{
Expand All @@ -24,5 +26,4 @@ public function __construct()

$this->initProductVariantDepositTrait();
}

}
35 changes: 1 addition & 34 deletions src/Entity/ProductVariantDepositTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function initProductVariantDepositTrait(): void
protected $channelDeposits;

/**
* @var TaxCategoryInterface
* @var TaxCategoryInterface|null
*
* @ORM\ManyToOne(targetEntity="\Sylius\Component\Taxation\Model\TaxCategoryInterface", cascade={"all"}, fetch="EAGER")
* @ORM\JoinColumn(name="deposit_tax_category_id", referencedColumnName="id", onDelete="SET NULL")
Expand All @@ -46,20 +46,13 @@ public function initProductVariantDepositTrait(): void

/**
* Returns all deposit elements for all channels
* @return Collection|ChannelDepositInterface[]
*
* @psalm-return Collection<array-key, ChannelDepositInterface>
*/
public function getChannelDeposits(): Collection
{
return $this->channelDeposits;
}

/**
* Returns the deposit element for one channel
* @param ChannelInterface $channel
* @return ChannelDepositInterface|null
*/
public function getChannelDepositForChannel(ChannelInterface $channel): ?ChannelDepositInterface
{
$channelCode = $channel->getCode();
Expand All @@ -71,31 +64,16 @@ public function getChannelDepositForChannel(ChannelInterface $channel): ?Channel
return null;
}

/**
* Check if channel has deposit element
* @param ChannelInterface $channel
* @return bool
*/
public function hasChannelDepositForChannel(ChannelInterface $channel): bool
{
return null !== $this->getChannelDepositForChannel($channel);
}

/**
* Check if has deposit element
* @param ChannelDepositInterface $channelDeposit
* @return bool
*/
public function hasChannelDeposit(ChannelDepositInterface $channelDeposit): bool
{
return $this->channelDeposits->contains($channelDeposit);
}

/**
* Adds an deposit element to the list
* @param ChannelDepositInterface $channelDeposit
* @return void
*/
public function addChannelDeposit(ChannelDepositInterface $channelDeposit): void
{
$channelCode = $channelDeposit->getChannelCode();
Expand All @@ -106,11 +84,6 @@ public function addChannelDeposit(ChannelDepositInterface $channelDeposit): void
}
}

/**
* Removes a deposit element from the list
* @param ChannelDepositInterface $channelDeposit
* @return void
*/
public function removeChannelDeposit(ChannelDepositInterface $channelDeposit): void
{
$channelCode = $channelDeposit->getChannelCode();
Expand All @@ -121,17 +94,11 @@ public function removeChannelDeposit(ChannelDepositInterface $channelDeposit): v
}
}

/**
* @return TaxCategoryInterface
*/
public function getDepositTaxCategory(): ?TaxCategoryInterface
{
return $this->depositTaxCategory;
}

/**
* @param TaxCategoryInterface $depositTaxCategory
*/
public function setDepositTaxCategory(TaxCategoryInterface $depositTaxCategory): void
{
$this->depositTaxCategory = $depositTaxCategory;
Expand Down
33 changes: 0 additions & 33 deletions src/Entity/ProductVariantInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,21 @@ interface ProductVariantInterface extends BaseProductVariantInterface
{
/**
* Returns all deposit elements for all channels
* @return Collection|ChannelDepositInterface[]
*
* @psalm-return Collection<array-key, ChannelDepositInterface>
*/
public function getChannelDeposits(): Collection;

/**
* Returns the deposit element for one channel
* @param ChannelInterface $channel
* @return ChannelDepositInterface|null
*/
public function getChannelDepositForChannel(ChannelInterface $channel): ?ChannelDepositInterface;

/**
* Check if channel has deposit element
* @param ChannelInterface $channel
* @return bool
*/
public function hasChannelDepositForChannel(ChannelInterface $channel): bool;

/**
* Check if has deposit element
* @param ChannelDepositInterface $channelDeposit
* @return bool
*/
public function hasChannelDeposit(ChannelDepositInterface $channelDeposit): bool;

/**
* Adds an deposit element to the list
* @param ChannelDepositInterface $channelDeposit
* @return void
*/
public function addChannelDeposit(ChannelDepositInterface $channelDeposit): void;

/**
* Removes a deposit element from the list
* @param ChannelDepositInterface $channelDeposit
* @return void
*/
public function removeChannelDeposit(ChannelDepositInterface $channelDeposit): void;

/**
* @return TaxCategoryInterface
*/
public function getDepositTaxCategory(): ?TaxCategoryInterface;

/**
* @param TaxCategoryInterface $depositTaxCategory
*/
public function setDepositTaxCategory(TaxCategoryInterface $depositTaxCategory): void;
}
40 changes: 26 additions & 14 deletions src/Form/ChannelDepositType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Gewebe\SyliusProductDepositPlugin\Form;

use Gewebe\SyliusProductDepositPlugin\Entity\ChannelDepositInterface;
use Gewebe\SyliusProductDepositPlugin\Entity\ProductVariantInterface;
use Sylius\Bundle\MoneyBundle\Form\Type\MoneyType;
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
Expand All @@ -20,18 +20,22 @@
*/
final class ChannelDepositType extends AbstractResourceType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
/** @var ChannelInterface $channel */
$channel = $options['channel'];
$baseCurrency = $channel->getBaseCurrency();
if ($baseCurrency === null) {
return;
}

$builder->add(
'price',
MoneyType::class,
[
'label' => 'gewebe_product_deposit_plugin.admin.product_variant.price',
'required' => false,
'currency' => $options['channel']->getBaseCurrency()->getCode(),
'currency' => $baseCurrency->getCode(),
]
);

Expand All @@ -47,17 +51,26 @@ function(FormEvent $event) use ($options): void {
return;
}

$channelDeposit->setChannelCode($options['channel']->getCode());
$channelDeposit->setProductVariant($options['product_variant']);
/** @var ChannelInterface $channel */
$channel = $options['channel'];
$channelCode = $channel->getCode();
if ($channelCode === null) {
$event->setData(null);

return;
}

/** @var ProductVariantInterface $productVariant */
$productVariant = $options['product_variant'];

$channelDeposit->setChannelCode($channelCode);
$channelDeposit->setProductVariant($productVariant);

$event->setData($channelDeposit);
}
);
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver): void
{
parent::configureOptions($resolver);
Expand All @@ -70,15 +83,14 @@ public function configureOptions(OptionsResolver $resolver): void
->setDefaults(
[
'label' => function(Options $options): string {
return $options['channel']->getName();
/** @var ChannelInterface $channel */
$channel = $options['channel'];
return $channel->getName() ?? '';
},
]
);
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix(): string
{
return 'gewebe_channel_deposit';
Expand Down
Loading

0 comments on commit 4e9f567

Please sign in to comment.