Optimized draft for RequestedRight

This commit is contained in:
Kevin Frantz
2019-01-13 21:52:09 +01:00
parent 2b63e0e447
commit 7af1b3e58c
2 changed files with 83 additions and 4 deletions

View File

@@ -50,7 +50,7 @@ class RequestedRight implements RequestedRightInterface
*/
private function isIdEquals(): bool
{
if ($this->requestedSource->hasId() && $this->source->hasId()) {
if (!$this->requestedSource->hasId() || !$this->source->hasId()) {
return false;
}
@@ -62,19 +62,27 @@ class RequestedRight implements RequestedRightInterface
*/
private function isSlugEquals(): bool
{
if ($this->requestedSource->hasSlug() && $this->source->hasSlug()) {
if (!$this->requestedSource->hasSlug() || !$this->source->hasSlug()) {
return false;
}
return $this->requestedSource->getSlug() === $this->source->getSlug();
}
/**
* @return bool Returns true if the source is not set!
*/
private function isSourceNotSet(): bool
{
return !isset($this->source);
}
/**
* @return bool Tells if a reload of the source is neccessary
*/
private function isReloadNeccessary(): bool
{
return $this->isIdEquals() && $this->isSlugEquals();
return $this->isSourceNotSet() || $this->isIdEquals() || $this->isSlugEquals();
}
/**
@@ -88,11 +96,19 @@ class RequestedRight implements RequestedRightInterface
{
if ($this->isReloadNeccessary()) {
$this->loadSource();
$this->setSourceIfNotSet();
}
return $this->source;
}
private function setSourceIfNotSet(): void
{
if (!isset($this->source)) {
$this->source = $this->requestedSource;
}
}
/**
* {@inheritdoc}
*
@@ -101,6 +117,5 @@ class RequestedRight implements RequestedRightInterface
final public function setRequestedSource(RequestedSourceInterface $requestedSource)
{
$this->requestedSource = $requestedSource;
$this->loadSource();
}
}