diff --git a/Composite/Form.php b/Composite/Form.php index 0cc16e1..decc599 100644 --- a/Composite/Form.php +++ b/Composite/Form.php @@ -3,7 +3,7 @@ namespace DesignPatterns\Composite; /** - * composite pattern + * Composite pattern * * Purpose: * to treat a group of objects the same way as a single instance of the object @@ -18,7 +18,10 @@ namespace DesignPatterns\Composite; */ class Form extends FormElement { - protected $_elements; + /** + * @var array|FormElement[] + */ + protected $elements; /** * runs through all elements and calls render() on them, then returns the complete representation @@ -26,20 +29,26 @@ class Form extends FormElement * * from the outside, one will not see this and the form will act like a single object instance * + * @param int $indent + * * @return string */ public function render($indent = 0) { $formCode = ''; - foreach ($this->_elements as $element) { + + foreach ($this->elements as $element) { $formCode .= $element->render($indent + 1) . PHP_EOL; } return $formCode; } + /** + * @param FormElement $element + */ public function addElement(FormElement $element) { - $this->_elements[] = $element; + $this->elements[] = $element; } } diff --git a/Composite/FormElement.php b/Composite/FormElement.php index 3e3de93..ab95c67 100644 --- a/Composite/FormElement.php +++ b/Composite/FormElement.php @@ -2,7 +2,17 @@ namespace DesignPatterns\Composite; +/** + * Class FormElement + */ abstract class FormElement { + /** + * renders the elements' code + * + * @param int $indent + * + * @return mixed + */ abstract public function render($indent = 0); } diff --git a/Composite/InputElement.php b/Composite/InputElement.php index 786df45..7a65241 100644 --- a/Composite/InputElement.php +++ b/Composite/InputElement.php @@ -2,8 +2,18 @@ namespace DesignPatterns\Composite; +/** + * Class InputElement + */ class InputElement extends FormElement { + /** + * renders the input element HTML + * + * @param int $indent + * + * @return mixed|string + */ public function render($indent = 0) { return str_repeat(' ', $indent) . ''; diff --git a/Composite/TextElement.php b/Composite/TextElement.php index c8214ca..9ea4a4e 100644 --- a/Composite/TextElement.php +++ b/Composite/TextElement.php @@ -2,8 +2,18 @@ namespace DesignPatterns\Composite; +/** + * Class TextElement + */ class TextElement extends FormElement { + /** + * renders the text element + * + * @param int $indent + * + * @return mixed|string + */ public function render($indent = 0) { return str_repeat(' ', $indent) . 'this is a text element';