Skip to content

Commit

Permalink
Fix PHP Stan
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Jul 4, 2024
1 parent b19c78b commit bad4a91
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ parameters:
# Test dependencies
- 'tests/Application/**/*'

# Menu Provider
- 'src/Menu/PageUrlProvider.php'

ignoreErrors:
- identifier: missingType.generics
- identifier: missingType.iterableValue
5 changes: 4 additions & 1 deletion src/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public function previewAction(Request $request, SwitchAdminLocaleInterface $swit
$this->isGrantedOr403($configuration, ResourceActions::SHOW);
$resource = $this->findOr404($configuration);

return $this->render($configuration->getRequest()->get('template'), [
/** @var string $template */
$template = $configuration->getRequest()->get('template');

return $this->render($template, [
'configuration' => $configuration,
'metadata' => $this->metadata,
'resource' => $resource,
Expand Down
12 changes: 1 addition & 11 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ final class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('monsieurbiz_sylius_cms_page');
if (method_exists($treeBuilder, 'getRootNode')) {
$treeBuilder->getRootNode();

return $treeBuilder;
}

// BC layer for symfony/config 4.1 and older
$treeBuilder->root('monsieurbiz_sylius_cms_page');

return $treeBuilder;
return new TreeBuilder('monsieurbiz_sylius_cms_page');
}
}
3 changes: 3 additions & 0 deletions src/Repository/PageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function existsOneByChannelAndSlug(ChannelInterface $channel, ?string $lo
;
}

/** @phpstan-ignore-next-line */
$count = (int) $queryBuilder
->getQuery()
->getSingleScalarResult()
Expand All @@ -55,6 +56,7 @@ public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?str
->andWhere('p.enabled = true')
;

/** @phpstan-ignore-next-line */
$count = (int) $queryBuilder
->getQuery()
->getSingleScalarResult()
Expand All @@ -68,6 +70,7 @@ public function existsOneEnabledByChannelAndSlug(ChannelInterface $channel, ?str
*/
public function findOneEnabledBySlugAndChannelCode(string $slug, string $localeCode, string $channelCode): ?PageInterface
{
/** @phpstan-ignore-next-line */
return $this->createQueryBuilder('p')
->leftJoin('p.translations', 'translation')
->innerJoin('p.channels', 'channels')
Expand Down
4 changes: 3 additions & 1 deletion src/Validator/Constraints/UniqueSlugByChannelValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace MonsieurBiz\SyliusCmsPagePlugin\Validator\Constraints;

use MonsieurBiz\SyliusCmsPagePlugin\Entity\PageInterface;
use MonsieurBiz\SyliusCmsPagePlugin\Entity\PageTranslationInterface;
use MonsieurBiz\SyliusCmsPagePlugin\Repository\PageRepositoryInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
Expand Down Expand Up @@ -41,12 +42,13 @@ public function validate($value, Constraint $constraint): void
Assert::isInstanceOf($constraint, UniqueSlugByChannel::class);

// Check if the slug is unique for each channel and locale
/** @var PageTranslationInterface $translation */
foreach ($value->getTranslations() as $translation) {
foreach ($value->getChannels() as $channel) {
if ($this->pageRepository->existsOneByChannelAndSlug(
$channel,
$translation->getLocale(),
$translation->getSlug(),
(string) $translation->getSlug(),
$value->getId() ? [$value] : []
)) {
$this->context->buildViolation($constraint->message, [
Expand Down

0 comments on commit bad4a91

Please sign in to comment.