Skip to content

Commit

Permalink
Use type hints and return types in ResourceOwnerMapInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
XWB committed Aug 3, 2021
1 parent 4bedd44 commit b2de48d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
14 changes: 6 additions & 8 deletions Security/Http/ResourceOwnerMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ class ResourceOwnerMap implements ContainerAwareInterface, ResourceOwnerMapInter
protected $container;

/**
* Constructor.
*
* @param HttpUtils $httpUtils HttpUtils
* @param array $possibleResourceOwners array with possible resource owners names
* @param array $resourceOwners array with configured resource owners
*/
public function __construct(HttpUtils $httpUtils, array $possibleResourceOwners, $resourceOwners)
public function __construct(HttpUtils $httpUtils, array $possibleResourceOwners, array $resourceOwners)
{
$this->httpUtils = $httpUtils;
$this->possibleResourceOwners = $possibleResourceOwners;
Expand All @@ -73,15 +71,15 @@ public function setContainer(ContainerInterface $container = null)
/**
* {@inheritdoc}
*/
public function hasResourceOwnerByName($name)
public function hasResourceOwnerByName(string $name): bool
{
return isset($this->resourceOwners[$name], $this->possibleResourceOwners[$name]);
}

/**
* {@inheritdoc}
*/
public function getResourceOwnerByName($name)
public function getResourceOwnerByName(string $name): ?ResourceOwnerInterface
{
if (!$this->hasResourceOwnerByName($name)) {
return null;
Expand All @@ -96,7 +94,7 @@ public function getResourceOwnerByName($name)
/**
* {@inheritdoc}
*/
public function getResourceOwnerByRequest(Request $request)
public function getResourceOwnerByRequest(Request $request): ?array
{
foreach ($this->resourceOwners as $name => $checkPath) {
if ($this->httpUtils->checkRequestPath($request, $checkPath)) {
Expand All @@ -117,7 +115,7 @@ public function getResourceOwnerByRequest(Request $request)
/**
* {@inheritdoc}
*/
public function getResourceOwnerCheckPath($name)
public function getResourceOwnerCheckPath(string $name): ?string
{
if (isset($this->resourceOwners[$name])) {
return $this->resourceOwners[$name];
Expand All @@ -129,7 +127,7 @@ public function getResourceOwnerCheckPath($name)
/**
* {@inheritdoc}
*/
public function getResourceOwners()
public function getResourceOwners(): array
{
return $this->resourceOwners;
}
Expand Down
24 changes: 5 additions & 19 deletions Security/Http/ResourceOwnerMapInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,28 @@ interface ResourceOwnerMapInterface
{
/**
* Check that resource owner with given name exists.
*
* @param string $name
*
* @return bool
*/
public function hasResourceOwnerByName($name);
public function hasResourceOwnerByName(string $name): bool;

/**
* Gets the appropriate resource owner given the name.
*
* @param string $name
*
* @return ResourceOwnerInterface|null
*/
public function getResourceOwnerByName($name);
public function getResourceOwnerByName(string $name): ?ResourceOwnerInterface;

/**
* Gets the appropriate resource owner for a request.
*
* @return array|null
*/
public function getResourceOwnerByRequest(Request $request);
public function getResourceOwnerByRequest(Request $request): ?array;

/**
* Gets the check path for given resource name.
*
* @param string $name
*
* @return string|null
*/
public function getResourceOwnerCheckPath($name);
public function getResourceOwnerCheckPath(string $name): ?string;

/**
* Get all the resource owners.
*
* @return ResourceOwnerInterface[]
*/
public function getResourceOwners();
public function getResourceOwners(): array;
}

0 comments on commit b2de48d

Please sign in to comment.