mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-30 19:50:12 +02:00
update deps & install rector
This commit is contained in:
@@ -11,15 +11,13 @@ class Form implements Renderable
|
||||
/**
|
||||
* @var Renderable[]
|
||||
*/
|
||||
private $elements;
|
||||
private array $elements;
|
||||
|
||||
/**
|
||||
* runs through all elements and calls render() on them, then returns the complete representation
|
||||
* of the form.
|
||||
*
|
||||
* from the outside, one will not see this and the form will act like a single object instance
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render(): string
|
||||
{
|
||||
@@ -34,9 +32,6 @@ class Form implements Renderable
|
||||
return $formCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Renderable $element
|
||||
*/
|
||||
public function addElement(Renderable $element)
|
||||
{
|
||||
$this->elements[] = $element;
|
||||
|
@@ -2,19 +2,21 @@
|
||||
|
||||
namespace DesignPatterns\Structural\Composite\Tests;
|
||||
|
||||
use DesignPatterns\Structural\Composite;
|
||||
use DesignPatterns\Structural\Composite\Form;
|
||||
use DesignPatterns\Structural\Composite\TextElement;
|
||||
use DesignPatterns\Structural\Composite\InputElement;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CompositeTest extends TestCase
|
||||
{
|
||||
public function testRender()
|
||||
{
|
||||
$form = new Composite\Form();
|
||||
$form->addElement(new Composite\TextElement('Email:'));
|
||||
$form->addElement(new Composite\InputElement());
|
||||
$embed = new Composite\Form();
|
||||
$embed->addElement(new Composite\TextElement('Password:'));
|
||||
$embed->addElement(new Composite\InputElement());
|
||||
$form = new Form();
|
||||
$form->addElement(new TextElement('Email:'));
|
||||
$form->addElement(new InputElement());
|
||||
$embed = new Form();
|
||||
$embed->addElement(new TextElement('Password:'));
|
||||
$embed->addElement(new InputElement());
|
||||
$form->addElement($embed);
|
||||
|
||||
// This is just an example, in a real world scenario it is important to remember that web browsers do not
|
||||
|
@@ -4,10 +4,7 @@ namespace DesignPatterns\Structural\Composite;
|
||||
|
||||
class TextElement implements Renderable
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $text;
|
||||
private string $text;
|
||||
|
||||
public function __construct(string $text)
|
||||
{
|
||||
|
Reference in New Issue
Block a user