Skip to content

Commit

Permalink
Move logic to setPath method
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenoh committed Nov 24, 2023
1 parent 7c6ca01 commit 729e34a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 32 deletions.
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,6 @@ parameters:
count: 1
path: src/ParamConverter/PageArgumentsConverter.php

-
message: "#^Cannot access offset 'path' on mixed\\.$#"
count: 1
path: src/Path/CurrentPathStack.php

-
message: "#^Cannot call method getPathInfo\\(\\) on Symfony\\\\Component\\\\HttpFoundation\\\\Request\\|null\\.$#"
count: 1
path: src/Path/CurrentPathStack.php

-
message: "#^Method Retrofit\\\\Drupal\\\\Path\\\\CurrentPathStack\\:\\:getPath\\(\\) should return string but returns mixed\\.$#"
count: 1
path: src/Path/CurrentPathStack.php

-
message: "#^Method Retrofit\\\\Drupal\\\\Plugin\\\\Block\\\\Block\\:\\:blockForm\\(\\) has parameter \\$form with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
24 changes: 7 additions & 17 deletions src/Path/CurrentPathStack.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,23 @@

class CurrentPathStack extends CoreCurrentPathStack
{
public function __construct(RequestStack $request_stack)
{
parent::__construct($request_stack);
if ($request = $request_stack->getCurrentRequest()) {
$_GET['q'] = $request->getPathInfo();
$this->paths[$request] = ['path' => &$_GET['q']];
}
}

public function getPath(?Request $request = null): string
{
if (!isset($request)) {
$request = $this->requestStack->getCurrentRequest();
}
$request ??= $this->requestStack->getCurrentRequest();
if (!isset($this->paths[$request])) {
assert($request instanceof Request);
$this->paths[$request] = ['path' => $request->getPathInfo()];
}
assert(is_array($this->paths[$request]) && is_string($this->paths[$request]['path']));
return $this->paths[$request]['path'];
}

public function setPath($path, ?Request $request = null): static
{
if (!isset($request)) {
$request = $this->requestStack->getCurrentRequest();
}
$this->paths[$request] = ['path' => $path];

$request ??= $this->requestStack->getCurrentRequest();
assert($request instanceof Request);
$_GET['q'] = $request->getPathInfo();
$this->paths[$request] = ['path' => &$_GET['q']];
return $this;
}
}

0 comments on commit 729e34a

Please sign in to comment.