From 2324fa93d5720bebb8027d9ebb9d88b21389c8d1 Mon Sep 17 00:00:00 2001 From: Maxime Fabre Date: Sun, 3 Aug 2014 12:53:57 +0200 Subject: [PATCH] Code cleanup --- src/Former/Facades/Former.php | 24 +- src/Former/Form/Actions.php | 211 ++-- src/Former/Form/Elements.php | 156 +-- src/Former/Form/Fields/Button.php | 179 +-- src/Former/Form/Fields/Checkbox.php | 42 +- src/Former/Form/Fields/File.php | 249 ++--- src/Former/Form/Fields/Hidden.php | 52 +- src/Former/Form/Fields/Input.php | 278 ++--- src/Former/Form/Fields/Radio.php | 33 +- src/Former/Form/Fields/Select.php | 565 +++++----- src/Former/Form/Fields/Textarea.php | 24 +- src/Former/Form/Fields/Uneditable.php | 29 +- src/Former/Form/Form.php | 781 ++++++------- src/Former/Form/Group.php | 904 +++++++-------- src/Former/Former.php | 870 +++++++-------- src/Former/FormerServiceProvider.php | 312 +++--- src/Former/Framework/Nude.php | 319 +++--- src/Former/Framework/TwitterBootstrap.php | 689 ++++++------ src/Former/Framework/TwitterBootstrap3.php | 803 +++++++------- src/Former/Framework/ZurbFoundation.php | 510 ++++----- src/Former/Framework/ZurbFoundation4.php | 515 ++++----- src/Former/Helpers.php | 285 ++--- src/Former/Interfaces/FieldInterface.php | 12 +- src/Former/Interfaces/FrameworkInterface.php | 232 ++-- src/Former/LiveValidation.php | 663 +++++------ src/Former/MethodDispatcher.php | 455 ++++---- src/Former/Populator.php | 304 +++--- src/Former/Traits/Checkable.php | 973 +++++++++-------- src/Former/Traits/Field.php | 730 ++++++------- src/Former/Traits/FormerObject.php | 293 ++--- src/Former/Traits/Framework.php | 596 +++++----- src/Laravel/File.php | 231 ++-- src/config/ZurbFoundation.php | 2 +- tests/ActionsTest.php | 183 ++-- tests/Dummy/DummyButton.php | 16 +- tests/Dummy/DummyEloquent.php | 46 +- tests/Dummy/DummyToArray.php | 18 +- tests/Fields/ButtonTest.php | 181 ++-- tests/Fields/CheckboxTest.php | 1025 +++++++++--------- tests/Fields/FileTest.php | 238 ++-- tests/Fields/HiddenTest.php | 34 +- tests/Fields/InputTest.php | 576 +++++----- tests/Fields/RadioTest.php | 534 ++++----- tests/Fields/SelectTest.php | 858 +++++++-------- tests/Fields/TextareaTest.php | 110 +- tests/Fields/UneditableTest.php | 139 ++- tests/FormTest.php | 631 +++++------ tests/FormerTest.php | 202 ++-- tests/Framework/FrameworkTest.php | 36 +- tests/Framework/NudeFrameworkTest.php | 51 +- tests/Framework/TwitterBootstrap3Test.php | 398 +++---- tests/Framework/TwitterBootstrapTest.php | 102 +- tests/Framework/ZurbFramework4Test.php | 270 +++-- tests/Framework/ZurbFrameworkTest.php | 197 ++-- tests/GroupTest.php | 686 ++++++------ tests/HelpersTest.php | 78 +- tests/LiveValidationTest.php | 806 +++++++------- tests/PopulatorTest.php | 209 ++-- tests/TestCases/ContainerTestCase.php | 522 ++++----- tests/TestCases/FormerTests.php | 563 +++++----- tests/Traits/FieldTest.php | 374 +++---- 61 files changed, 10817 insertions(+), 10587 deletions(-) diff --git a/src/Former/Facades/Former.php b/src/Former/Facades/Former.php index 5b6dfa8c..17cb2b2a 100644 --- a/src/Former/Facades/Former.php +++ b/src/Former/Facades/Former.php @@ -9,17 +9,17 @@ */ class Former extends Facade { - /** - * Get the registered component. - * - * @return object - */ - protected static function getFacadeAccessor() - { - if (!static::$app) { - static::$app = FormerServiceProvider::make(); - } + /** + * Get the registered component. + * + * @return object + */ + protected static function getFacadeAccessor() + { + if (!static::$app) { + static::$app = FormerServiceProvider::make(); + } - return 'former'; - } + return 'former'; + } } diff --git a/src/Former/Form/Actions.php b/src/Former/Form/Actions.php index 76aa8669..c5d1a695 100644 --- a/src/Former/Form/Actions.php +++ b/src/Former/Form/Actions.php @@ -1,7 +1,6 @@ app = $app; - $this->value = $value; - - // Add specific actions classes to the actions block - $this->addClass($this->app['former.framework']->getActionClasses()); - } - - /** - * Get the content of the Actions block - * - * @return string - */ - public function getContent() - { - $content = array_map(function ($content) { - return method_exists($content, '__toString') ? (string) $content : $content; - }, $this->value); - - return $this->app['former.framework']->wrapActions( implode(' ', $content) ); - } - - /** - * Dynamically append actions to the block - * - * @param string $method The method - * @param array $parameters Its parameters - * - * @return Actions - */ - public function __call($method, $parameters) - { - // Dynamically add buttons to an actions block - if ($this->isButtonMethod($method)) { - $text = array_get($parameters, 0); - $link = array_get($parameters, 1); - $attributes = array_get($parameters, 2); - if (!$attributes and is_array($link)) $attributes = $link; - return $this->createButtonOfType($method, $text, $link, $attributes); - } - - return parent::__call($method, $parameters); - } - - //////////////////////////////////////////////////////////////////// - ////////////////////////////// HELPERS ///////////////////////////// - //////////////////////////////////////////////////////////////////// - - /** - * Create a new Button and add it to the actions - * - * @param string $type The button type - * @param string $name Its name - * @param string $link A link to point to - * @param array $attributes Its attributes - * - * @return Actions - */ - private function createButtonOfType($type, $name, $link, $attributes) - { - $this->value[] = $this->app['former']->$type($name, $link, $attributes)->__toString(); - - return $this; - } - - /** - * Check if a given method calls a button or not - * - * @param string $method The method to check - * - * @return boolean - */ - private function isButtonMethod($method) - { - $buttons = array('button', 'submit', 'link', 'reset'); - - return (bool) Str::contains($method, $buttons); - } - + /** + * The Container + * + * @var Container + */ + protected $app; + + /** + * The Actions element + * + * @var string + */ + protected $element = 'div'; + + //////////////////////////////////////////////////////////////////// + /////////////////////////// CORE METHODS /////////////////////////// + //////////////////////////////////////////////////////////////////// + + /** + * Constructs a new Actions block + * + * @param Container $app + * @param array $value The block content + */ + public function __construct(Container $app, $value) + { + $this->app = $app; + $this->value = $value; + + // Add specific actions classes to the actions block + $this->addClass($this->app['former.framework']->getActionClasses()); + } + + /** + * Get the content of the Actions block + * + * @return string + */ + public function getContent() + { + $content = array_map(function ($content) { + return method_exists($content, '__toString') ? (string) $content : $content; + }, $this->value); + + return $this->app['former.framework']->wrapActions(implode(' ', $content)); + } + + /** + * Dynamically append actions to the block + * + * @param string $method The method + * @param array $parameters Its parameters + * + * @return Actions + */ + public function __call($method, $parameters) + { + // Dynamically add buttons to an actions block + if ($this->isButtonMethod($method)) { + $text = array_get($parameters, 0); + $link = array_get($parameters, 1); + $attributes = array_get($parameters, 2); + if (!$attributes and is_array($link)) { + $attributes = $link; + } + + return $this->createButtonOfType($method, $text, $link, $attributes); + } + + return parent::__call($method, $parameters); + } + + //////////////////////////////////////////////////////////////////// + ////////////////////////////// HELPERS ///////////////////////////// + //////////////////////////////////////////////////////////////////// + + /** + * Create a new Button and add it to the actions + * + * @param string $type The button type + * @param string $name Its name + * @param string $link A link to point to + * @param array $attributes Its attributes + * + * @return Actions + */ + private function createButtonOfType($type, $name, $link, $attributes) + { + $this->value[] = $this->app['former']->$type($name, $link, $attributes)->__toString(); + + return $this; + } + + /** + * Check if a given method calls a button or not + * + * @param string $method The method to check + * + * @return boolean + */ + private function isButtonMethod($method) + { + $buttons = array('button', 'submit', 'link', 'reset'); + + return (bool) Str::contains($method, $buttons); + } } diff --git a/src/Former/Form/Elements.php b/src/Former/Form/Elements.php index 0b3cf122..51154b60 100644 --- a/src/Former/Form/Elements.php +++ b/src/Former/Form/Elements.php @@ -1,7 +1,6 @@ app = $app; - $this->session = $session; - } + /** + * Build a new Element + * + * @param Container $app + */ + public function __construct(Container $app, $session) + { + $this->app = $app; + $this->session = $session; + } - /** - * Generate a hidden field containing the current CSRF token. - * - * @return string - */ - public function token() - { - $csrf = $this->session->getToken(); + /** + * Generate a hidden field containing the current CSRF token. + * + * @return string + */ + public function token() + { + $csrf = $this->session->getToken(); - return (string) $this->app['former']->hidden('_token', $csrf); - } + return (string) $this->app['former']->hidden('_token', $csrf); + } - /** - * Creates a label tag - * - * @param string $label The label content - * @param string $for The field the label's for - * @param array $attributes The label's attributes - * @return string A