Skip to content

Commit 9b92f90

Browse files
committed
Added verbose errors to assigners
1 parent 1b3d418 commit 9b92f90

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/Assigner/ChannelsAssigner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Sylius\Component\Channel\Model\ChannelsAwareInterface;
1616
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
1717
use Sylius\Component\Core\Model\ChannelInterface;
18+
use Webmozart\Assert\Assert;
1819

1920
final class ChannelsAssigner implements ChannelsAssignerInterface
2021
{
@@ -32,9 +33,8 @@ public function assign(ChannelsAwareInterface $channelsAware, array $channelsCod
3233
/** @var ChannelInterface $channel|null */
3334
$channel = $this->channelRepository->findOneBy(['code' => $channelCode]);
3435

35-
if (null !== $channel) {
36-
$channelsAware->addChannel($channel);
37-
}
36+
Assert::notNull($channel, sprintf('Channel with %s code not found.', $channelCode));
37+
$channelsAware->addChannel($channel);
3838
}
3939
}
4040
}

src/Assigner/ProductsAssigner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use BitBag\SyliusCmsPlugin\Entity\ProductsAwareInterface;
1616
use Sylius\Component\Core\Model\ProductInterface;
1717
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
18+
use Webmozart\Assert\Assert;
1819

1920
final class ProductsAssigner implements ProductsAssignerInterface
2021
{
@@ -32,9 +33,8 @@ public function assign(ProductsAwareInterface $productsAware, array $productsCod
3233
/** @var ProductInterface $product */
3334
$product = $this->productRepository->findOneBy(['code' => $productCode]);
3435

35-
if (null !== $product) {
36-
$productsAware->addProduct($product);
37-
}
36+
Assert::notNull($product, sprintf('Product with %s code not found.', $productCode));
37+
$productsAware->addProduct($product);
3838
}
3939
}
4040
}

src/Assigner/SectionsAssigner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use BitBag\SyliusCmsPlugin\Entity\SectionableInterface;
1616
use BitBag\SyliusCmsPlugin\Entity\SectionInterface;
1717
use BitBag\SyliusCmsPlugin\Repository\SectionRepositoryInterface;
18+
use Webmozart\Assert\Assert;
1819

1920
final class SectionsAssigner implements SectionsAssignerInterface
2021
{
@@ -32,9 +33,8 @@ public function assign(SectionableInterface $sectionsAware, array $sectionsCodes
3233
/** @var SectionInterface $section */
3334
$section = $this->sectionRepository->findOneBy(['code' => $sectionCode]);
3435

35-
if (null !== $section) {
36-
$sectionsAware->addSection($section);
37-
}
36+
Assert::notNull($section, sprintf('Section with %s code not found.', $sectionCode));
37+
$sectionsAware->addSection($section);
3838
}
3939
}
4040
}

src/Assigner/TaxonsAssigner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use BitBag\SyliusCmsPlugin\Entity\TaxonAwareInterface;
1616
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
1717
use Sylius\Component\Core\Model\TaxonInterface;
18+
use Webmozart\Assert\Assert;
1819

1920
final class TaxonsAssigner implements TaxonsAssignerInterface
2021
{
@@ -32,9 +33,8 @@ public function assign(TaxonAwareInterface $taxonAware, array $taxonCodes): void
3233
/** @var TaxonInterface $taxon */
3334
$taxon = $this->taxonRepository->findOneBy(['code' => $taxonCode]);
3435

35-
if (null !== $taxon) {
36-
$taxonAware->addTaxon($taxon);
37-
}
36+
Assert::notNull($taxon, sprintf('Taxon with %s code not found.', $taxonCode));
37+
$taxonAware->addTaxon($taxon);
3838
}
3939
}
4040
}

0 commit comments

Comments
 (0)