Skip to content

Commit

Permalink
Fix PHPStan "Call to an undefined method Eccube\Controller\AbstractCo…
Browse files Browse the repository at this point in the history
…ntroller::get()"
  • Loading branch information
chihiro-adachi committed Dec 19, 2023
1 parent 81820e6 commit a01389f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
18 changes: 17 additions & 1 deletion src/Eccube/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class AbstractController extends Controller
Expand Down Expand Up @@ -57,6 +58,11 @@ class AbstractController extends Controller
*/
protected $session;

/**
* @var RouterInterface
*/
protected $router;

/**
* @param EccubeConfig $eccubeConfig
* @required
Expand Down Expand Up @@ -111,6 +117,16 @@ public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
$this->eventDispatcher = $eventDispatcher;
}

/**
* @param RouterInterface $router
* @return void
* @required
*/
public function setRouter(RouterInterface $router)
{
$this->router = $router;
}

public function addSuccess($message, $namespace = 'front')
{
$this->addFlash('eccube.'.$namespace.'.success', $message);
Expand Down Expand Up @@ -230,7 +246,7 @@ public function setLoginTargetPath($targetPath, $namespace = null)
*/
public function forwardToRoute($route, array $path = [], array $query = [])
{
$Route = $this->get('router')->getRouteCollection()->get($route);
$Route = $this->router->getRouteCollection()->get($route);
if (!$Route) {
throw new RouteNotFoundException(sprintf('The named route "%s" as such route does not exist.', $route));
}
Expand Down
7 changes: 0 additions & 7 deletions src/Eccube/Controller/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ class SitemapController extends AbstractController
*/
private $productRepository;

/**
* @var RouterInterface
*/
private $router;

/**
* @var BaseInfo
*/
Expand All @@ -68,14 +63,12 @@ public function __construct(
PageRepository $pageRepository,
ProductListOrderByRepository $productListOrderByRepository,
ProductRepository $productRepository,
RouterInterface $router,
BaseInfoRepository $baseInfoRepository
) {
$this->categoryRepository = $categoryRepository;
$this->pageRepository = $pageRepository;
$this->productListOrderByRepository = $productListOrderByRepository;
$this->productRepository = $productRepository;
$this->router = $router;
$this->BaseInfo = $baseInfoRepository->get();
}

Expand Down

0 comments on commit a01389f

Please sign in to comment.