Skip to content

Commit 61b6563

Browse files
committed
Fix no commerce trait with new routes index
1 parent 1ca4068 commit 61b6563

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/Kernel/SyliusNoCommerceKernelTrait.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function loadRoutes(LoaderInterface $loader): RouteCollection
5252
private function getConfig(): ConfigInterface
5353
{
5454
return new Config(
55-
(array) $this->container->getParameter('monsieurbiz_sylius_nocommerce.config') ?? []
55+
(array) ($this->container->getParameter('monsieurbiz_sylius_nocommerce.config') ?? [])
5656
);
5757
}
5858

@@ -65,21 +65,21 @@ public function getRoutesToRemove(): array
6565
{
6666
$config = $this->getConfig();
6767
$routesToRemove = [];
68-
$this->routesToRemove = ConfigInterface::ROUTES_BY_GROUP;
68+
$routesByGroup = ConfigInterface::ROUTES_BY_GROUP;
6969

7070
/** @deprecated */
7171
if ($config->areCustomersAllowed()) {
72-
unset($this->routesToRemove['customer']);
72+
unset($routesByGroup['customer_shop'], $routesByGroup['customer_api'], $routesByGroup['customer_admin']);
7373
}
7474

7575
/** @deprecated */
7676
if ($config->areZonesAllowed()) {
77-
unset($this->routesToRemove['zone']);
77+
unset($routesByGroup['zone_admin'], $routesByGroup['zone_api']);
7878
}
7979

8080
/** @deprecated */
8181
if ($config->areZonesAllowed() || $config->areCountriesAllowed()) {
82-
unset($this->routesToRemove['country']);
82+
unset($routesByGroup['country_admin'], $routesByGroup['country_api']);
8383
}
8484

8585
// Loop on settings to add routes
@@ -93,25 +93,30 @@ public function getRoutesToRemove(): array
9393
}
9494

9595
foreach ($routesToEnable as $route) {
96-
$this->enableRoute($route);
96+
$this->enableRoute($route, $routesByGroup);
9797
}
9898

99-
foreach ($this->routesToRemove as $routes) {
99+
foreach ($routesByGroup as $routes) {
100100
$routesToRemove = array_merge($routesToRemove, $routes);
101101
}
102102

103103
return $routesToRemove;
104104
}
105105

106-
private function enableRoute(string $route): void
106+
/**
107+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
108+
*/
109+
private function enableRoute(string $route, array &$routesByGroup): void
107110
{
108-
foreach ($this->routesToRemove as $group => $routes) {
109-
if (false !== ($key = array_search($route, $routes, true))) {
110-
unset($this->routesToRemove[$group][$key]);
111+
foreach ($routesByGroup as $group => $routes) {
112+
// Remove route from group
113+
if (false !== ($key = array_search($route, $routes, true)) && isset($routesByGroup[$group][$key])) {
114+
unset($routesByGroup[$group][$key]);
111115
}
112116

113-
if (empty($this->routesToRemove[$group])) {
114-
unset($this->routesToRemove[$group]);
117+
// Remove group if empty
118+
if (empty($routesByGroup[$group])) {
119+
unset($routesByGroup[$group]);
115120
}
116121
}
117122
}

0 commit comments

Comments
 (0)