Skip to content

Commit

Permalink
Small code quality tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
victorwelling committed Dec 8, 2017
1 parent 6c4ac70 commit c9493eb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Middleware/PresenterMiddleware.php
Expand Up @@ -42,7 +42,7 @@ public function process(View $view, Context $context, callable $next): View
{
$presentationModel = $view->getPresentationModel();

if (!$this->hasData($presentationModel) && $presentationModel instanceof HasPresenterInterface) {
if ($presentationModel instanceof HasPresenterInterface && !$this->hasData($presentationModel)) {
$presenter = $this->loadPresenter($presentationModel);
$presentationModel = $presenter->present($context, $presentationModel);
$view = $view->withPresentationModel($presentationModel);
Expand Down
16 changes: 5 additions & 11 deletions src/PresentationModel.php
Expand Up @@ -52,17 +52,11 @@ final public function withVariables(array $variables): self
*/
private function setVariables(array $variables)
{
if (static::class === self::class) {
foreach ($variables as $variable => $value) {
if (is_string($variable)) {
$this->$variable = $value;
}
}
} else {
foreach ($variables as $variable => $value) {
if (property_exists($this, $variable)) {
$this->$variable = $value;
}
$isGeneric = static::class === self::class;

foreach ($variables as $variable => $value) {
if (is_string($variable) && ($isGeneric || property_exists($this, $variable))) {
$this->$variable = $value;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/View.php
Expand Up @@ -5,6 +5,9 @@

use InvalidArgumentException;

/**
* A view is the visual representation of a model.
*/
final class View
{
/** @var callable */
Expand Down
2 changes: 2 additions & 0 deletions tests/Fixtures/ProductPresentationModel.php
Expand Up @@ -10,8 +10,10 @@ final class ProductPresentationModel extends PresentationModel implements HasPre
{
/** @var bool */
protected $on_stock = false;

/** @var string */
protected $product_name = '';

/** @var int */
protected $stock_quantity = 0;

Expand Down

0 comments on commit c9493eb

Please sign in to comment.