Skip to content

Commit 29ec02a

Browse files
authored
Merge pull request #330 from leszczuu/fix/silent-assigners
making assigners break with incorrect data
2 parents 7b7acb0 + 06df9c0 commit 29ec02a

7 files changed

Lines changed: 16 additions & 13 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ before_install:
3838

3939
install:
4040
- composer require ${DEPENDENCY_VERSIONS} --no-update
41+
- composer require stefandoorn/sitemap-plugin --no-update
4142
- composer update --no-interaction --prefer-dist
4243
- (cd tests/Application && yarn install)
4344

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
"suggest": {
4545
"stefandoorn/sitemap-plugin": "^2.0@alpha"
4646
},
47+
"suggest": {
48+
"stefandoorn/sitemap-plugin": "Adds CMS pages & sections support to the Sylius sitemap plugin"
49+
},
4750
"conflict": {
4851
"symfony/symfony": "4.1.8",
4952
"symfony/browser-kit": "4.1.8",

doc/installation.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ Import routing in your `config/routes.yaml` file:
5252
bitbag_sylius_cms_plugin:
5353
resource: "@BitBagSyliusCmsPlugin/Resources/config/routing.yml"
5454
```
55-
5655
If You have installed https://github.com/stefandoorn/sitemap-plugin according to its installation instructions
5756
import optional sitemap providers:
5857
```yaml

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\Core\Model\TaxonInterface;
1717
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
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)