Skip to content

Commit

Permalink
!!! TASK: Add strict types to ViewInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Mar 17, 2024
1 parent 664f240 commit aa7a41e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
12 changes: 6 additions & 6 deletions Neos.Flow/Classes/Mvc/View/AbstractView.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ abstract class AbstractView implements ViewInterface
* Factory method to create an instance with given options.
*
* @param array $options
* @return ViewInterface
* @return static
*/
public static function createWithOptions(array $options)
public static function createWithOptions(array $options): self
{
return new static($options);
}
Expand Down Expand Up @@ -143,10 +143,10 @@ public function setOption($optionName, $value)
*
* @param string $key Key of variable
* @param mixed $value Value of object
* @return AbstractView an instance of $this, to enable chaining
* @return $this for chaining
* @api
*/
public function assign($key, $value)
public function assign(string $key, mixed $value): self
{
$this->variables[$key] = $value;
return $this;
Expand All @@ -156,10 +156,10 @@ public function assign($key, $value)
* Add multiple variables to $this->variables.
*
* @param array $values array in the format array(key1 => value1, key2 => value2)
* @return AbstractView an instance of $this, to enable chaining
* @return $this for chaining
* @api
*/
public function assignMultiple(array $values)
public function assignMultiple(array $values): self
{
foreach ($values as $key => $value) {
$this->assign($key, $value);
Expand Down
20 changes: 10 additions & 10 deletions Neos.Flow/Classes/Mvc/View/ViewInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ interface ViewInterface
* @param ControllerContext $controllerContext Context of the controller associated with this view
* @return void
*/
// public function setControllerContext(ControllerContext $controllerContext);
// public function setControllerContext(ControllerContext $controllerContext): void;

/**
* Add a variable to the view data collection.
* Can be chained, so $this->view->assign(..., ...)->assign(..., ...); is possible
* Can be chained: $this->view->assign(..., ...)->assign(..., ...);
*
* @param string $key Key of variable
* @param mixed $value Value of object
* @return ViewInterface an instance of $this, to enable chaining
* @return $this for chaining
* @api
*/
public function assign($key, $value);
public function assign(string $key, mixed $value): self;

/**
* Add multiple variables to the view data collection
*
* @param array $values array in the format array(key1 => value1, key2 => value2)
* @return ViewInterface an instance of $this, to enable chaining
* @param array<string,mixed> $values associative array with the key being its name
* @return $this for chaining
* @api
*/
public function assignMultiple(array $values);
public function assignMultiple(array $values): self;

/**
* Renders the view
Expand All @@ -62,8 +62,8 @@ public function render(): ResponseInterface|StreamInterface;
/**
* Factory method to create an instance with given options.
*
* @param array $options
* @return ViewInterface
* @param array<string,mixed> $options
* @return static
*/
public static function createWithOptions(array $options);
public static function createWithOptions(array $options): self;
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class TemplateView extends AbstractView
* @return self instance of $this to allow chaining
* @api
*/
public function assign($key, $value)
public function assign(string $key, mixed $value): self
{
return $this;
}
Expand All @@ -62,7 +62,7 @@ public function assign($key, $value)
* @return self instance of $this to allow chaining
* @api
*/
public function assignMultiple(array $values)
public function assignMultiple(array $values): self
{
return $this;
}
Expand Down
16 changes: 14 additions & 2 deletions Neos.FluidAdaptor/Classes/View/AbstractTemplateView.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,25 @@ public function render($actionName = null): StreamInterface
return $this->createStream(parent::render($actionName));
}

public function assign($key, $value): self
{
// layer to fix incompatibility error with typo3 fluid interface
return parent::assign($key, $value);
}

public function assignMultiple(array $values): self
{
// layer to fix incompatibility error with typo3 fluid interface
return parent::assignMultiple($values);
}

/**
* Factory method to create an instance with given options.
*
* @param array $options
* @return AbstractTemplateView
* @return static
*/
public static function createWithOptions(array $options)
public static function createWithOptions(array $options): self
{
return new static($options);
}
Expand Down
4 changes: 2 additions & 2 deletions Neos.FluidAdaptor/Classes/View/StandaloneView.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class StandaloneView extends AbstractTemplateView
* Factory method to create an instance with given options.
*
* @param array $options
* @return StandaloneView
* @return static
*/
public static function createWithOptions(array $options)
public static function createWithOptions(array $options): self
{
return new static(null, $options);
}
Expand Down

0 comments on commit aa7a41e

Please sign in to comment.