From 975b5682c850fa7b6d43b4a6f5723583e2ca96c5 Mon Sep 17 00:00:00 2001 From: Ashley Kitson Date: Mon, 21 May 2018 17:51:09 +0100 Subject: [PATCH 1/5] refactor file locations --- composer.json | 5 ++-- docs/.gitkeep | 0 phpunit.xml | 17 ++++++++---- DataForm.php => src/DataForm.php | 0 Error.php => src/Error.php | 0 Factory.php => src/Factory.php | 0 {Fields => src/Fields}/ButtonField.php | 0 {Fields => src/Fields}/CaptchaField.php | 0 {Fields => src/Fields}/CheckboxField.php | 0 {Fields => src/Fields}/DateField.php | 0 {Fields => src/Fields}/EmailField.php | 0 {Fields => src/Fields}/Field.php | 0 {Fields => src/Fields}/FileField.php | 0 {Fields => src/Fields}/Group.php | 0 {Fields => src/Fields}/HiddenField.php | 0 {Fields => src/Fields}/IntField.php | 0 {Fields => src/Fields}/MulticheckboxField.php | 0 {Fields => src/Fields}/Multiple.php | 0 {Fields => src/Fields}/MultiradioField.php | 0 {Fields => src/Fields}/NumberField.php | 0 {Fields => src/Fields}/Option.php | 0 {Fields => src/Fields}/Options.php | 0 {Fields => src/Fields}/PasswordField.php | 0 {Fields => src/Fields}/RadioField.php | 0 {Fields => src/Fields}/Radios.php | 0 {Fields => src/Fields}/Select.php | 0 {Fields => src/Fields}/TextField.php | 0 {Fields => src/Fields}/Textarea.php | 0 Form.php => src/Form.php | 0 Formidable.php => src/Formidable.php | 0 Head.php => src/Head.php | 0 {Js => src/Js}/formidable.js | 0 {Language => src/Language}/English.php | 0 {Language => src/Language}/French.php | 0 {Language => src/Language}/German.php | 0 {Language => src/Language}/Language.php | 0 {Language => src/Language}/LanguageAware.php | 0 {Language => src/Language}/Spanish.php | 0 {Language => src/Language}/Turkish.php | 0 Parser.php => src/Parser.php | 0 ParserData.php => src/ParserData.php | 0 .../ParserException.php | 0 Placeholder.php => src/Placeholder.php | 0 PostIndicator.php => src/PostIndicator.php | 2 +- .../ConstraintsTest.php | 26 ++++++++++++------ .../FactoryTests.php => test/FactoryTest.php | 6 ++-- tests/FormTests.php => test/FormTest.php | 4 +-- tests/ParserTests.php => test/ParserTest.php | 4 +-- {tests => test}/bootstrap.php | 0 .../files => test/fixtures}/context/form.html | 0 .../fixtures}/context/testing.html | 0 .../files => test/fixtures}/form/array.html | 0 .../fixtures}/form/attributes.html | 0 .../fixtures}/form/bad_type.html | 0 .../files => test/fixtures}/form/basic.html | 0 .../files => test/fixtures}/form/button.html | 0 .../files => test/fixtures}/form/captcha.html | 0 .../fixtures}/form/chk_array.html | 0 .../fixtures}/form/custom-constraint.html | 0 .../files => test/fixtures}/form/custom.php | 0 {tests/files => test/fixtures}/form/date.html | 0 .../files => test/fixtures}/form/empty.html | 0 .../files => test/fixtures}/form/empty2.html | 0 .../fixtures}/form/enctype_file.html | 0 .../fixtures}/form/enctype_normal.html | 0 .../files => test/fixtures}/form/escape.html | 0 .../files => test/fixtures}/form/hidden.html | 0 .../fixtures}/form/maxlength.html | 0 .../fixtures}/form/minlength.html | 0 .../files => test/fixtures}/form/minmax.html | 0 .../fixtures}/form/multicheckbox.html | 0 .../fixtures}/form/multiple.html | 0 .../fixtures}/form/multiple_file.html | 0 .../fixtures}/form/multiple_fixed.html | 0 .../fixtures}/form/multiradio.html | 0 .../fixtures}/form/multiradio_optional.html | 0 .../fixtures}/form/optional.html | 0 .../files => test/fixtures}/form/options.html | 0 .../files => test/fixtures}/form/out_in.html | 0 .../fixtures}/form/passwords.html | 0 .../fixtures}/form/placeholder.html | 0 .../fixtures}/form/placeholder_multiline.html | 0 .../fixtures}/form/post-indicator.html | 0 .../fixtures}/form/post-values.html | 0 .../files => test/fixtures}/form/radios.html | 0 .../fixtures}/form/readonly.html | 0 .../files => test/fixtures}/form/regex.html | 0 .../fixtures}/form/required.html | 0 .../files => test/fixtures}/form/reset.html | 0 .../fixtures}/form/select-multiple.html | 0 .../fixtures}/form/select-required.html | 0 .../files => test/fixtures}/form/select.html | 0 .../files => test/fixtures}/form/source.html | 0 {tests/files => test/fixtures}/form/step.html | 0 .../fixtures}/form/step_default.html | 0 .../fixtures}/form/step_default_int.html | 0 {tests/files => test/fixtures}/form/test.html | 0 .../files => test/fixtures}/form/upload.html | 0 .../fixtures}/form/upload_image.html | 0 .../files => test/fixtures}/form/values.html | 0 .../fixtures}/parser/attributes.html | 0 .../files => test/fixtures}/parser/basic.html | 0 .../fixtures}/parser/form_presence.html | 0 .../files => test/fixtures}/parser/head.html | 0 .../parser/option_out_of_select.html | 0 .../files => test/fixtures}/parser/types.html | 0 .../fixtures}/parser/untyped_input.html | 0 .../fixtures}/parser/values.html | 0 .../files => test/fixtures}/upload/image.jpg | Bin .../files => test/fixtures}/upload/long.txt | 0 .../files => test/fixtures}/upload/test.txt | 0 111 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 docs/.gitkeep rename DataForm.php => src/DataForm.php (100%) rename Error.php => src/Error.php (100%) rename Factory.php => src/Factory.php (100%) rename {Fields => src/Fields}/ButtonField.php (100%) rename {Fields => src/Fields}/CaptchaField.php (100%) rename {Fields => src/Fields}/CheckboxField.php (100%) rename {Fields => src/Fields}/DateField.php (100%) rename {Fields => src/Fields}/EmailField.php (100%) rename {Fields => src/Fields}/Field.php (100%) rename {Fields => src/Fields}/FileField.php (100%) rename {Fields => src/Fields}/Group.php (100%) rename {Fields => src/Fields}/HiddenField.php (100%) rename {Fields => src/Fields}/IntField.php (100%) rename {Fields => src/Fields}/MulticheckboxField.php (100%) rename {Fields => src/Fields}/Multiple.php (100%) rename {Fields => src/Fields}/MultiradioField.php (100%) rename {Fields => src/Fields}/NumberField.php (100%) rename {Fields => src/Fields}/Option.php (100%) rename {Fields => src/Fields}/Options.php (100%) rename {Fields => src/Fields}/PasswordField.php (100%) rename {Fields => src/Fields}/RadioField.php (100%) rename {Fields => src/Fields}/Radios.php (100%) rename {Fields => src/Fields}/Select.php (100%) rename {Fields => src/Fields}/TextField.php (100%) rename {Fields => src/Fields}/Textarea.php (100%) rename Form.php => src/Form.php (100%) rename Formidable.php => src/Formidable.php (100%) rename Head.php => src/Head.php (100%) rename {Js => src/Js}/formidable.js (100%) rename {Language => src/Language}/English.php (100%) rename {Language => src/Language}/French.php (100%) rename {Language => src/Language}/German.php (100%) rename {Language => src/Language}/Language.php (100%) rename {Language => src/Language}/LanguageAware.php (100%) rename {Language => src/Language}/Spanish.php (100%) rename {Language => src/Language}/Turkish.php (100%) rename Parser.php => src/Parser.php (100%) rename ParserData.php => src/ParserData.php (100%) rename ParserException.php => src/ParserException.php (100%) rename Placeholder.php => src/Placeholder.php (100%) rename PostIndicator.php => src/PostIndicator.php (96%) rename tests/ConstraintsTests.php => test/ConstraintsTest.php (96%) rename tests/FactoryTests.php => test/FactoryTest.php (78%) rename tests/FormTests.php => test/FormTest.php (98%) rename tests/ParserTests.php => test/ParserTest.php (97%) rename {tests => test}/bootstrap.php (100%) rename {tests/files => test/fixtures}/context/form.html (100%) rename {tests/files => test/fixtures}/context/testing.html (100%) rename {tests/files => test/fixtures}/form/array.html (100%) rename {tests/files => test/fixtures}/form/attributes.html (100%) rename {tests/files => test/fixtures}/form/bad_type.html (100%) rename {tests/files => test/fixtures}/form/basic.html (100%) rename {tests/files => test/fixtures}/form/button.html (100%) rename {tests/files => test/fixtures}/form/captcha.html (100%) rename {tests/files => test/fixtures}/form/chk_array.html (100%) rename {tests/files => test/fixtures}/form/custom-constraint.html (100%) rename {tests/files => test/fixtures}/form/custom.php (100%) rename {tests/files => test/fixtures}/form/date.html (100%) rename {tests/files => test/fixtures}/form/empty.html (100%) rename {tests/files => test/fixtures}/form/empty2.html (100%) rename {tests/files => test/fixtures}/form/enctype_file.html (100%) rename {tests/files => test/fixtures}/form/enctype_normal.html (100%) rename {tests/files => test/fixtures}/form/escape.html (100%) rename {tests/files => test/fixtures}/form/hidden.html (100%) rename {tests/files => test/fixtures}/form/maxlength.html (100%) rename {tests/files => test/fixtures}/form/minlength.html (100%) rename {tests/files => test/fixtures}/form/minmax.html (100%) rename {tests/files => test/fixtures}/form/multicheckbox.html (100%) rename {tests/files => test/fixtures}/form/multiple.html (100%) rename {tests/files => test/fixtures}/form/multiple_file.html (100%) rename {tests/files => test/fixtures}/form/multiple_fixed.html (100%) rename {tests/files => test/fixtures}/form/multiradio.html (100%) rename {tests/files => test/fixtures}/form/multiradio_optional.html (100%) rename {tests/files => test/fixtures}/form/optional.html (100%) rename {tests/files => test/fixtures}/form/options.html (100%) rename {tests/files => test/fixtures}/form/out_in.html (100%) rename {tests/files => test/fixtures}/form/passwords.html (100%) rename {tests/files => test/fixtures}/form/placeholder.html (100%) rename {tests/files => test/fixtures}/form/placeholder_multiline.html (100%) rename {tests/files => test/fixtures}/form/post-indicator.html (100%) rename {tests/files => test/fixtures}/form/post-values.html (100%) rename {tests/files => test/fixtures}/form/radios.html (100%) rename {tests/files => test/fixtures}/form/readonly.html (100%) rename {tests/files => test/fixtures}/form/regex.html (100%) rename {tests/files => test/fixtures}/form/required.html (100%) rename {tests/files => test/fixtures}/form/reset.html (100%) rename {tests/files => test/fixtures}/form/select-multiple.html (100%) rename {tests/files => test/fixtures}/form/select-required.html (100%) rename {tests/files => test/fixtures}/form/select.html (100%) rename {tests/files => test/fixtures}/form/source.html (100%) rename {tests/files => test/fixtures}/form/step.html (100%) rename {tests/files => test/fixtures}/form/step_default.html (100%) rename {tests/files => test/fixtures}/form/step_default_int.html (100%) rename {tests/files => test/fixtures}/form/test.html (100%) rename {tests/files => test/fixtures}/form/upload.html (100%) rename {tests/files => test/fixtures}/form/upload_image.html (100%) rename {tests/files => test/fixtures}/form/values.html (100%) rename {tests/files => test/fixtures}/parser/attributes.html (100%) rename {tests/files => test/fixtures}/parser/basic.html (100%) rename {tests/files => test/fixtures}/parser/form_presence.html (100%) rename {tests/files => test/fixtures}/parser/head.html (100%) rename {tests/files => test/fixtures}/parser/option_out_of_select.html (100%) rename {tests/files => test/fixtures}/parser/types.html (100%) rename {tests/files => test/fixtures}/parser/untyped_input.html (100%) rename {tests/files => test/fixtures}/parser/values.html (100%) rename {tests/files => test/fixtures}/upload/image.jpg (100%) rename {tests/files => test/fixtures}/upload/long.txt (100%) rename {tests/files => test/fixtures}/upload/test.txt (100%) diff --git a/composer.json b/composer.json index 4aaa947..115d4d6 100644 --- a/composer.json +++ b/composer.json @@ -33,10 +33,9 @@ "suggest": { "gregwar/captcha": "To implement Captcha capability into forms" }, - "target-dir": "Gregwar/Formidable", "autoload": { - "psr-0": { - "Gregwar\\Formidable": "" + "psr-4": { + "Gregwar\\Formidable\\": "src" } } } diff --git a/docs/.gitkeep b/docs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/phpunit.xml b/phpunit.xml index 8ec678f..b26d4fb 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -9,15 +9,20 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false" - bootstrap="tests/bootstrap.php" + bootstrap="test/bootstrap.php" > - - ./tests/ParserTests.php - ./tests/FormTests.php - ./tests/ContextTests.php - ./tests/ConstraintsTests.php + + ./test + + + ./src + + + + + diff --git a/DataForm.php b/src/DataForm.php similarity index 100% rename from DataForm.php rename to src/DataForm.php diff --git a/Error.php b/src/Error.php similarity index 100% rename from Error.php rename to src/Error.php diff --git a/Factory.php b/src/Factory.php similarity index 100% rename from Factory.php rename to src/Factory.php diff --git a/Fields/ButtonField.php b/src/Fields/ButtonField.php similarity index 100% rename from Fields/ButtonField.php rename to src/Fields/ButtonField.php diff --git a/Fields/CaptchaField.php b/src/Fields/CaptchaField.php similarity index 100% rename from Fields/CaptchaField.php rename to src/Fields/CaptchaField.php diff --git a/Fields/CheckboxField.php b/src/Fields/CheckboxField.php similarity index 100% rename from Fields/CheckboxField.php rename to src/Fields/CheckboxField.php diff --git a/Fields/DateField.php b/src/Fields/DateField.php similarity index 100% rename from Fields/DateField.php rename to src/Fields/DateField.php diff --git a/Fields/EmailField.php b/src/Fields/EmailField.php similarity index 100% rename from Fields/EmailField.php rename to src/Fields/EmailField.php diff --git a/Fields/Field.php b/src/Fields/Field.php similarity index 100% rename from Fields/Field.php rename to src/Fields/Field.php diff --git a/Fields/FileField.php b/src/Fields/FileField.php similarity index 100% rename from Fields/FileField.php rename to src/Fields/FileField.php diff --git a/Fields/Group.php b/src/Fields/Group.php similarity index 100% rename from Fields/Group.php rename to src/Fields/Group.php diff --git a/Fields/HiddenField.php b/src/Fields/HiddenField.php similarity index 100% rename from Fields/HiddenField.php rename to src/Fields/HiddenField.php diff --git a/Fields/IntField.php b/src/Fields/IntField.php similarity index 100% rename from Fields/IntField.php rename to src/Fields/IntField.php diff --git a/Fields/MulticheckboxField.php b/src/Fields/MulticheckboxField.php similarity index 100% rename from Fields/MulticheckboxField.php rename to src/Fields/MulticheckboxField.php diff --git a/Fields/Multiple.php b/src/Fields/Multiple.php similarity index 100% rename from Fields/Multiple.php rename to src/Fields/Multiple.php diff --git a/Fields/MultiradioField.php b/src/Fields/MultiradioField.php similarity index 100% rename from Fields/MultiradioField.php rename to src/Fields/MultiradioField.php diff --git a/Fields/NumberField.php b/src/Fields/NumberField.php similarity index 100% rename from Fields/NumberField.php rename to src/Fields/NumberField.php diff --git a/Fields/Option.php b/src/Fields/Option.php similarity index 100% rename from Fields/Option.php rename to src/Fields/Option.php diff --git a/Fields/Options.php b/src/Fields/Options.php similarity index 100% rename from Fields/Options.php rename to src/Fields/Options.php diff --git a/Fields/PasswordField.php b/src/Fields/PasswordField.php similarity index 100% rename from Fields/PasswordField.php rename to src/Fields/PasswordField.php diff --git a/Fields/RadioField.php b/src/Fields/RadioField.php similarity index 100% rename from Fields/RadioField.php rename to src/Fields/RadioField.php diff --git a/Fields/Radios.php b/src/Fields/Radios.php similarity index 100% rename from Fields/Radios.php rename to src/Fields/Radios.php diff --git a/Fields/Select.php b/src/Fields/Select.php similarity index 100% rename from Fields/Select.php rename to src/Fields/Select.php diff --git a/Fields/TextField.php b/src/Fields/TextField.php similarity index 100% rename from Fields/TextField.php rename to src/Fields/TextField.php diff --git a/Fields/Textarea.php b/src/Fields/Textarea.php similarity index 100% rename from Fields/Textarea.php rename to src/Fields/Textarea.php diff --git a/Form.php b/src/Form.php similarity index 100% rename from Form.php rename to src/Form.php diff --git a/Formidable.php b/src/Formidable.php similarity index 100% rename from Formidable.php rename to src/Formidable.php diff --git a/Head.php b/src/Head.php similarity index 100% rename from Head.php rename to src/Head.php diff --git a/Js/formidable.js b/src/Js/formidable.js similarity index 100% rename from Js/formidable.js rename to src/Js/formidable.js diff --git a/Language/English.php b/src/Language/English.php similarity index 100% rename from Language/English.php rename to src/Language/English.php diff --git a/Language/French.php b/src/Language/French.php similarity index 100% rename from Language/French.php rename to src/Language/French.php diff --git a/Language/German.php b/src/Language/German.php similarity index 100% rename from Language/German.php rename to src/Language/German.php diff --git a/Language/Language.php b/src/Language/Language.php similarity index 100% rename from Language/Language.php rename to src/Language/Language.php diff --git a/Language/LanguageAware.php b/src/Language/LanguageAware.php similarity index 100% rename from Language/LanguageAware.php rename to src/Language/LanguageAware.php diff --git a/Language/Spanish.php b/src/Language/Spanish.php similarity index 100% rename from Language/Spanish.php rename to src/Language/Spanish.php diff --git a/Language/Turkish.php b/src/Language/Turkish.php similarity index 100% rename from Language/Turkish.php rename to src/Language/Turkish.php diff --git a/Parser.php b/src/Parser.php similarity index 100% rename from Parser.php rename to src/Parser.php diff --git a/ParserData.php b/src/ParserData.php similarity index 100% rename from ParserData.php rename to src/ParserData.php diff --git a/ParserException.php b/src/ParserException.php similarity index 100% rename from ParserException.php rename to src/ParserException.php diff --git a/Placeholder.php b/src/Placeholder.php similarity index 100% rename from Placeholder.php rename to src/Placeholder.php diff --git a/PostIndicator.php b/src/PostIndicator.php similarity index 96% rename from PostIndicator.php rename to src/PostIndicator.php index a534e06..ce62a28 100644 --- a/PostIndicator.php +++ b/src/PostIndicator.php @@ -50,7 +50,7 @@ protected function generateToken() ); if (isset($_SESSION)) { - $key = sha1(__DIR__ . '/' . 'formidable_secret'); + $key = sha1(__DIR__ . 'PostIndicator.php/' . 'formidable_secret'); if (isset($_SESSION[$key])) { $secret['csrf'] = $_SESSION[$key]; diff --git a/tests/ConstraintsTests.php b/test/ConstraintsTest.php similarity index 96% rename from tests/ConstraintsTests.php rename to test/ConstraintsTest.php index 73ee7d1..3322c64 100644 --- a/tests/ConstraintsTests.php +++ b/test/ConstraintsTest.php @@ -20,7 +20,7 @@ public function save($filename) * * @author Grégoire Passault */ -class ConstraintsTests extends \PHPUnit\Framework\TestCase +class ConstraintsTest extends \PHPUnit\Framework\TestCase { /** * Testing rendering a required field @@ -213,6 +213,10 @@ public function testCustomConstraintType() */ public function testCaptcha() { + if (!function_exists('imagettfbbox')) { + $this->markTestSkipped('No TrueType support'); + return; + } $form = $this->getForm('captcha.html'); $html = "$form"; @@ -241,6 +245,10 @@ public function testCaptcha() */ public function testCaptchaNotReusable() { + if (!function_exists('imagettfbbox')) { + $this->markTestSkipped('No TrueType support'); + return; + } $form = $this->getForm('captcha.html'); $html = "$form"; @@ -559,8 +567,8 @@ public function testFile() { $factory = new Factory; $factory->registerType('file', '\FileField_NoSave'); - $form = $factory->getForm(__DIR__.'/files/form/upload.html'); - $file = __DIR__.'/files/upload/test.txt'; + $form = $factory->getForm(__DIR__.'/fixtures/form/upload.html'); + $file = __DIR__.'/fixtures/upload/test.txt'; $hash = sha1(file_get_contents($file)); $this->assertContains('file', "$form"); @@ -577,7 +585,7 @@ public function testFile() $this->assertEquals($hash, $form->attachement->save(null)); $this->assertEquals('test.txt', $form->getField('attachement')->fileName()); - $file = __DIR__.'/files/upload/long.txt'; + $file = __DIR__.'/fixtures/upload/long.txt'; $this->assertRefuse($form, array(), array( 'attachement' => array( 'size' => filesize($file), @@ -594,8 +602,8 @@ public function testMultipleFiles() { $factory = new Factory; $factory->registerType('file', '\FileField_NoSave'); - $form = $factory->getForm(__DIR__.'/files/form/multiple_file.html'); - $file = __DIR__.'/files/upload/test.txt'; + $form = $factory->getForm(__DIR__.'/fixtures/form/multiple_file.html'); + $file = __DIR__.'/fixtures/upload/test.txt'; $this->assertAccept($form, array(), array( 'files' => array( @@ -636,7 +644,7 @@ public function testFileImage() { $form = $this->getForm('upload_image.html'); - $file = __DIR__.'/files/upload/image.jpg'; + $file = __DIR__.'/fixtures/upload/image.jpg'; $this->assertAccept($form, array(), array( 'photo' => array( 'size' => filesize($file), @@ -645,7 +653,7 @@ public function testFileImage() ) )); - $file = __DIR__.'/files/upload/test.txt'; + $file = __DIR__.'/fixtures/upload/test.txt'; $this->assertRefuse($form, array(), array( 'photo' => array( 'size' => filesize($file), @@ -934,7 +942,7 @@ private function assertRefuse($form, $data, $files = array()) { private function getForm($file) { - return new Form(__DIR__.'/files/form/'.$file); + return new Form(__DIR__.'/fixtures/form/'.$file); } public function setup() diff --git a/tests/FactoryTests.php b/test/FactoryTest.php similarity index 78% rename from tests/FactoryTests.php rename to test/FactoryTest.php index 9347b29..9d54e20 100644 --- a/tests/FactoryTests.php +++ b/test/FactoryTest.php @@ -7,7 +7,7 @@ * * @author Grégoire Passault */ -class FactoryTests extends \PHPUnit\Framework\TestCase +class FactoryTest extends \PHPUnit\Framework\TestCase { /** * Testing creating forms using the factory @@ -15,7 +15,7 @@ class FactoryTests extends \PHPUnit\Framework\TestCase public function testFactoryCreation() { $factory = new Factory; - $form = $factory->getForm(__DIR__.'/files/factory/form.html'); + $form = $factory->getForm(__DIR__.'/fixtures/context/form.html'); $html = "$form"; $this->assertContains('test', $html); @@ -30,7 +30,7 @@ public function testFactoryCustomType() $factory = new Factory; $factory->registerType('testing', '\Gregwar\Formidable\Fields\TextField'); - $form = $factory->getForm(__DIR__.'/files/factory/testing.html'); + $form = $factory->getForm(__DIR__.'/fixtures/context/testing.html'); $html = "$form"; $this->assertContains('text', $html); $this->assertEquals('Hello', $form->test); diff --git a/tests/FormTests.php b/test/FormTest.php similarity index 98% rename from tests/FormTests.php rename to test/FormTest.php index 1b90c4d..3437327 100644 --- a/tests/FormTests.php +++ b/test/FormTest.php @@ -8,7 +8,7 @@ * * @author Grégoire Passault */ -class FormTests extends \PHPUnit\Framework\TestCase +class FormTest extends \PHPUnit\Framework\TestCase { /** * Testing that toString() give the same thing as getHtml() @@ -323,7 +323,7 @@ public function testSourceOrder() private function getForm($file, $vars = array(), $cache = false) { - return new Form(__DIR__.'/files/form/'.$file, $vars, $cache); + return new Form(__DIR__.'/fixtures/form/'.$file, $vars, $cache); } public function setup() diff --git a/tests/ParserTests.php b/test/ParserTest.php similarity index 97% rename from tests/ParserTests.php rename to test/ParserTest.php index d067be5..2878031 100644 --- a/tests/ParserTests.php +++ b/test/ParserTest.php @@ -8,7 +8,7 @@ * * @author Grégoire Passault */ -class ParserTests extends \PHPUnit\Framework\TestCase +class ParserTest extends \PHPUnit\Framework\TestCase { /** * Testing the returns of a basic parse @@ -145,6 +145,6 @@ public function testOptionOutOfSelectException() private function getParser($file) { - return new Parser(file_get_contents(__DIR__.'/files/parser/'.$file)); + return new Parser(file_get_contents(__DIR__.'/fixtures/parser/'.$file)); } } diff --git a/tests/bootstrap.php b/test/bootstrap.php similarity index 100% rename from tests/bootstrap.php rename to test/bootstrap.php diff --git a/tests/files/context/form.html b/test/fixtures/context/form.html similarity index 100% rename from tests/files/context/form.html rename to test/fixtures/context/form.html diff --git a/tests/files/context/testing.html b/test/fixtures/context/testing.html similarity index 100% rename from tests/files/context/testing.html rename to test/fixtures/context/testing.html diff --git a/tests/files/form/array.html b/test/fixtures/form/array.html similarity index 100% rename from tests/files/form/array.html rename to test/fixtures/form/array.html diff --git a/tests/files/form/attributes.html b/test/fixtures/form/attributes.html similarity index 100% rename from tests/files/form/attributes.html rename to test/fixtures/form/attributes.html diff --git a/tests/files/form/bad_type.html b/test/fixtures/form/bad_type.html similarity index 100% rename from tests/files/form/bad_type.html rename to test/fixtures/form/bad_type.html diff --git a/tests/files/form/basic.html b/test/fixtures/form/basic.html similarity index 100% rename from tests/files/form/basic.html rename to test/fixtures/form/basic.html diff --git a/tests/files/form/button.html b/test/fixtures/form/button.html similarity index 100% rename from tests/files/form/button.html rename to test/fixtures/form/button.html diff --git a/tests/files/form/captcha.html b/test/fixtures/form/captcha.html similarity index 100% rename from tests/files/form/captcha.html rename to test/fixtures/form/captcha.html diff --git a/tests/files/form/chk_array.html b/test/fixtures/form/chk_array.html similarity index 100% rename from tests/files/form/chk_array.html rename to test/fixtures/form/chk_array.html diff --git a/tests/files/form/custom-constraint.html b/test/fixtures/form/custom-constraint.html similarity index 100% rename from tests/files/form/custom-constraint.html rename to test/fixtures/form/custom-constraint.html diff --git a/tests/files/form/custom.php b/test/fixtures/form/custom.php similarity index 100% rename from tests/files/form/custom.php rename to test/fixtures/form/custom.php diff --git a/tests/files/form/date.html b/test/fixtures/form/date.html similarity index 100% rename from tests/files/form/date.html rename to test/fixtures/form/date.html diff --git a/tests/files/form/empty.html b/test/fixtures/form/empty.html similarity index 100% rename from tests/files/form/empty.html rename to test/fixtures/form/empty.html diff --git a/tests/files/form/empty2.html b/test/fixtures/form/empty2.html similarity index 100% rename from tests/files/form/empty2.html rename to test/fixtures/form/empty2.html diff --git a/tests/files/form/enctype_file.html b/test/fixtures/form/enctype_file.html similarity index 100% rename from tests/files/form/enctype_file.html rename to test/fixtures/form/enctype_file.html diff --git a/tests/files/form/enctype_normal.html b/test/fixtures/form/enctype_normal.html similarity index 100% rename from tests/files/form/enctype_normal.html rename to test/fixtures/form/enctype_normal.html diff --git a/tests/files/form/escape.html b/test/fixtures/form/escape.html similarity index 100% rename from tests/files/form/escape.html rename to test/fixtures/form/escape.html diff --git a/tests/files/form/hidden.html b/test/fixtures/form/hidden.html similarity index 100% rename from tests/files/form/hidden.html rename to test/fixtures/form/hidden.html diff --git a/tests/files/form/maxlength.html b/test/fixtures/form/maxlength.html similarity index 100% rename from tests/files/form/maxlength.html rename to test/fixtures/form/maxlength.html diff --git a/tests/files/form/minlength.html b/test/fixtures/form/minlength.html similarity index 100% rename from tests/files/form/minlength.html rename to test/fixtures/form/minlength.html diff --git a/tests/files/form/minmax.html b/test/fixtures/form/minmax.html similarity index 100% rename from tests/files/form/minmax.html rename to test/fixtures/form/minmax.html diff --git a/tests/files/form/multicheckbox.html b/test/fixtures/form/multicheckbox.html similarity index 100% rename from tests/files/form/multicheckbox.html rename to test/fixtures/form/multicheckbox.html diff --git a/tests/files/form/multiple.html b/test/fixtures/form/multiple.html similarity index 100% rename from tests/files/form/multiple.html rename to test/fixtures/form/multiple.html diff --git a/tests/files/form/multiple_file.html b/test/fixtures/form/multiple_file.html similarity index 100% rename from tests/files/form/multiple_file.html rename to test/fixtures/form/multiple_file.html diff --git a/tests/files/form/multiple_fixed.html b/test/fixtures/form/multiple_fixed.html similarity index 100% rename from tests/files/form/multiple_fixed.html rename to test/fixtures/form/multiple_fixed.html diff --git a/tests/files/form/multiradio.html b/test/fixtures/form/multiradio.html similarity index 100% rename from tests/files/form/multiradio.html rename to test/fixtures/form/multiradio.html diff --git a/tests/files/form/multiradio_optional.html b/test/fixtures/form/multiradio_optional.html similarity index 100% rename from tests/files/form/multiradio_optional.html rename to test/fixtures/form/multiradio_optional.html diff --git a/tests/files/form/optional.html b/test/fixtures/form/optional.html similarity index 100% rename from tests/files/form/optional.html rename to test/fixtures/form/optional.html diff --git a/tests/files/form/options.html b/test/fixtures/form/options.html similarity index 100% rename from tests/files/form/options.html rename to test/fixtures/form/options.html diff --git a/tests/files/form/out_in.html b/test/fixtures/form/out_in.html similarity index 100% rename from tests/files/form/out_in.html rename to test/fixtures/form/out_in.html diff --git a/tests/files/form/passwords.html b/test/fixtures/form/passwords.html similarity index 100% rename from tests/files/form/passwords.html rename to test/fixtures/form/passwords.html diff --git a/tests/files/form/placeholder.html b/test/fixtures/form/placeholder.html similarity index 100% rename from tests/files/form/placeholder.html rename to test/fixtures/form/placeholder.html diff --git a/tests/files/form/placeholder_multiline.html b/test/fixtures/form/placeholder_multiline.html similarity index 100% rename from tests/files/form/placeholder_multiline.html rename to test/fixtures/form/placeholder_multiline.html diff --git a/tests/files/form/post-indicator.html b/test/fixtures/form/post-indicator.html similarity index 100% rename from tests/files/form/post-indicator.html rename to test/fixtures/form/post-indicator.html diff --git a/tests/files/form/post-values.html b/test/fixtures/form/post-values.html similarity index 100% rename from tests/files/form/post-values.html rename to test/fixtures/form/post-values.html diff --git a/tests/files/form/radios.html b/test/fixtures/form/radios.html similarity index 100% rename from tests/files/form/radios.html rename to test/fixtures/form/radios.html diff --git a/tests/files/form/readonly.html b/test/fixtures/form/readonly.html similarity index 100% rename from tests/files/form/readonly.html rename to test/fixtures/form/readonly.html diff --git a/tests/files/form/regex.html b/test/fixtures/form/regex.html similarity index 100% rename from tests/files/form/regex.html rename to test/fixtures/form/regex.html diff --git a/tests/files/form/required.html b/test/fixtures/form/required.html similarity index 100% rename from tests/files/form/required.html rename to test/fixtures/form/required.html diff --git a/tests/files/form/reset.html b/test/fixtures/form/reset.html similarity index 100% rename from tests/files/form/reset.html rename to test/fixtures/form/reset.html diff --git a/tests/files/form/select-multiple.html b/test/fixtures/form/select-multiple.html similarity index 100% rename from tests/files/form/select-multiple.html rename to test/fixtures/form/select-multiple.html diff --git a/tests/files/form/select-required.html b/test/fixtures/form/select-required.html similarity index 100% rename from tests/files/form/select-required.html rename to test/fixtures/form/select-required.html diff --git a/tests/files/form/select.html b/test/fixtures/form/select.html similarity index 100% rename from tests/files/form/select.html rename to test/fixtures/form/select.html diff --git a/tests/files/form/source.html b/test/fixtures/form/source.html similarity index 100% rename from tests/files/form/source.html rename to test/fixtures/form/source.html diff --git a/tests/files/form/step.html b/test/fixtures/form/step.html similarity index 100% rename from tests/files/form/step.html rename to test/fixtures/form/step.html diff --git a/tests/files/form/step_default.html b/test/fixtures/form/step_default.html similarity index 100% rename from tests/files/form/step_default.html rename to test/fixtures/form/step_default.html diff --git a/tests/files/form/step_default_int.html b/test/fixtures/form/step_default_int.html similarity index 100% rename from tests/files/form/step_default_int.html rename to test/fixtures/form/step_default_int.html diff --git a/tests/files/form/test.html b/test/fixtures/form/test.html similarity index 100% rename from tests/files/form/test.html rename to test/fixtures/form/test.html diff --git a/tests/files/form/upload.html b/test/fixtures/form/upload.html similarity index 100% rename from tests/files/form/upload.html rename to test/fixtures/form/upload.html diff --git a/tests/files/form/upload_image.html b/test/fixtures/form/upload_image.html similarity index 100% rename from tests/files/form/upload_image.html rename to test/fixtures/form/upload_image.html diff --git a/tests/files/form/values.html b/test/fixtures/form/values.html similarity index 100% rename from tests/files/form/values.html rename to test/fixtures/form/values.html diff --git a/tests/files/parser/attributes.html b/test/fixtures/parser/attributes.html similarity index 100% rename from tests/files/parser/attributes.html rename to test/fixtures/parser/attributes.html diff --git a/tests/files/parser/basic.html b/test/fixtures/parser/basic.html similarity index 100% rename from tests/files/parser/basic.html rename to test/fixtures/parser/basic.html diff --git a/tests/files/parser/form_presence.html b/test/fixtures/parser/form_presence.html similarity index 100% rename from tests/files/parser/form_presence.html rename to test/fixtures/parser/form_presence.html diff --git a/tests/files/parser/head.html b/test/fixtures/parser/head.html similarity index 100% rename from tests/files/parser/head.html rename to test/fixtures/parser/head.html diff --git a/tests/files/parser/option_out_of_select.html b/test/fixtures/parser/option_out_of_select.html similarity index 100% rename from tests/files/parser/option_out_of_select.html rename to test/fixtures/parser/option_out_of_select.html diff --git a/tests/files/parser/types.html b/test/fixtures/parser/types.html similarity index 100% rename from tests/files/parser/types.html rename to test/fixtures/parser/types.html diff --git a/tests/files/parser/untyped_input.html b/test/fixtures/parser/untyped_input.html similarity index 100% rename from tests/files/parser/untyped_input.html rename to test/fixtures/parser/untyped_input.html diff --git a/tests/files/parser/values.html b/test/fixtures/parser/values.html similarity index 100% rename from tests/files/parser/values.html rename to test/fixtures/parser/values.html diff --git a/tests/files/upload/image.jpg b/test/fixtures/upload/image.jpg similarity index 100% rename from tests/files/upload/image.jpg rename to test/fixtures/upload/image.jpg diff --git a/tests/files/upload/long.txt b/test/fixtures/upload/long.txt similarity index 100% rename from tests/files/upload/long.txt rename to test/fixtures/upload/long.txt diff --git a/tests/files/upload/test.txt b/test/fixtures/upload/test.txt similarity index 100% rename from tests/files/upload/test.txt rename to test/fixtures/upload/test.txt From d273e2de4b8af5b4c05187f102e1ed9117d55df1 Mon Sep 17 00:00:00 2001 From: Ashley Kitson Date: Mon, 21 May 2018 18:14:38 +0100 Subject: [PATCH 2/5] make sure coverage runs --- .gitignore | 1 + phpunit.xml | 4 ++-- src/Language/Turkish.php | 2 -- test/ConstraintsTest.php | 5 +++-- test/FactoryTest.php | 1 + test/FormTest.php | 4 +++- test/ParserTest.php | 1 + test/bootstrap.php | 15 --------------- 8 files changed, 11 insertions(+), 22 deletions(-) delete mode 100644 test/bootstrap.php diff --git a/.gitignore b/.gitignore index da84e31..c6064c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ composer.lock vendor **.swp +docs/contract.html \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index b26d4fb..acb769c 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -9,7 +9,7 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false" - bootstrap="test/bootstrap.php" + bootstrap="./vendor/autoload.php" > @@ -22,7 +22,7 @@ - + diff --git a/src/Language/Turkish.php b/src/Language/Turkish.php index 9d7a47c..9f100d1 100644 --- a/src/Language/Turkish.php +++ b/src/Language/Turkish.php @@ -1,6 +1,4 @@ - registerType('file', '\FileField_NoSave'); + $factory->registerType('file', '\Test\Gregwar\Formidable\FileField_NoSave'); $form = $factory->getForm(__DIR__.'/fixtures/form/upload.html'); $file = __DIR__.'/fixtures/upload/test.txt'; $hash = sha1(file_get_contents($file)); @@ -601,7 +602,7 @@ public function testFile() public function testMultipleFiles() { $factory = new Factory; - $factory->registerType('file', '\FileField_NoSave'); + $factory->registerType('file', '\Test\Gregwar\Formidable\FileField_NoSave'); $form = $factory->getForm(__DIR__.'/fixtures/form/multiple_file.html'); $file = __DIR__.'/fixtures/upload/test.txt'; diff --git a/test/FactoryTest.php b/test/FactoryTest.php index 9d54e20..8703b91 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -1,4 +1,5 @@ setCacheDirectory($this->getCacheDirectory()); $form = $this->getForm('basic.html', null, $cache); diff --git a/test/ParserTest.php b/test/ParserTest.php index 2878031..c5e1608 100644 --- a/test/ParserTest.php +++ b/test/ParserTest.php @@ -1,4 +1,5 @@ - */ -include(__DIR__.'/../autoload.php'); - From 84ad504cf63314a70a438dbb5999fab2ef270c53 Mon Sep 17 00:00:00 2001 From: Ashley Kitson Date: Mon, 21 May 2018 18:23:17 +0100 Subject: [PATCH 3/5] update examples --- README.md | 2 ++ examples/basic.php | 2 +- examples/cache-file.php | 2 +- examples/cache.php | 2 +- examples/custom.php | 2 +- examples/index.php | 4 ++-- examples/mapping.php | 2 +- examples/minmax.php | 2 +- examples/multiple.php | 2 +- examples/performances.php | 2 +- examples/placeholder.php | 2 +- examples/select.php | 2 +- examples/source.php | 2 +- 13 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8feba98..9b468ac 100644 --- a/README.md +++ b/README.md @@ -454,3 +454,5 @@ to set the cache directory. V2.0.0 End support for PHP <5.6 V2.1.0 Remove hard dependency on Captcha library + +V2.1.1 Standardise code structure \ No newline at end of file diff --git a/examples/basic.php b/examples/basic.php index 67f0d5b..f8cfd76 100644 --- a/examples/basic.php +++ b/examples/basic.php @@ -1,6 +1,6 @@ What\'s your name?
diff --git a/examples/cache-file.php b/examples/cache-file.php index 0454324..d17d032 100644 --- a/examples/cache-file.php +++ b/examples/cache-file.php @@ -1,7 +1,7 @@ What\'s your name?
diff --git a/examples/custom.php b/examples/custom.php index e845890..f1d15d3 100644 --- a/examples/custom.php +++ b/examples/custom.php @@ -1,6 +1,6 @@ diff --git a/examples/index.php b/examples/index.php index 8fcb6e4..10d6f4c 100644 --- a/examples/index.php +++ b/examples/index.php @@ -1,6 +1,6 @@ Formidable Demo
-

Validations error

+

Validations error

  • diff --git a/examples/mapping.php b/examples/mapping.php index 15ab7b1..033ce7b 100644 --- a/examples/mapping.php +++ b/examples/mapping.php @@ -1,6 +1,6 @@ How old are you? diff --git a/examples/multiple.php b/examples/multiple.php index 13d3575..032cf58 100644 --- a/examples/multiple.php +++ b/examples/multiple.php @@ -6,7 +6,7 @@ class Film public $actors; } -include(__DIR__.'/../autoload.php'); +include(__DIR__ . '/../vendor/autoload.php'); $form = new Gregwar\Formidable\Form('
    diff --git a/examples/performances.php b/examples/performances.php index 826a769..9869bde 100644 --- a/examples/performances.php +++ b/examples/performances.php @@ -1,5 +1,5 @@ Hello diff --git a/examples/select.php b/examples/select.php index 0535e7b..702e58e 100644 --- a/examples/select.php +++ b/examples/select.php @@ -1,6 +1,6 @@ From 489817fad4496433e26d2c155179dbcdc503e5b7 Mon Sep 17 00:00:00 2001 From: Ashley Kitson Date: Mon, 21 May 2018 19:31:45 +0100 Subject: [PATCH 4/5] Update PostIndicator.php remove extraneous text --- src/PostIndicator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PostIndicator.php b/src/PostIndicator.php index ce62a28..a534e06 100644 --- a/src/PostIndicator.php +++ b/src/PostIndicator.php @@ -50,7 +50,7 @@ protected function generateToken() ); if (isset($_SESSION)) { - $key = sha1(__DIR__ . 'PostIndicator.php/' . 'formidable_secret'); + $key = sha1(__DIR__ . '/' . 'formidable_secret'); if (isset($_SESSION[$key])) { $secret['csrf'] = $_SESSION[$key]; From 1ba0cf6ed7d2e18954ae3826d43e7c445a618775 Mon Sep 17 00:00:00 2001 From: Ashley Kitson Date: Tue, 22 May 2018 18:45:19 +0100 Subject: [PATCH 5/5] update documentation for Forms class --- autoload.php | 21 ------- src/Form.php | 138 +++++++++++++++++++++++++++++++++++++++------ src/ParserData.php | 5 ++ 3 files changed, 126 insertions(+), 38 deletions(-) delete mode 100644 autoload.php diff --git a/autoload.php b/autoload.php deleted file mode 100644 index d3365e5..0000000 --- a/autoload.php +++ /dev/null @@ -1,21 +0,0 @@ -value,...] */ - protected $variables = null; + protected $variables = []; /** * Current position for iterator + * @var int */ protected $position = 0; /** - * Factory + * @var Factory */ protected $factory; /** * Parser raw data + * @var ? */ protected $originalParserData; + + /** + * @var ParserData + */ protected $parserData; /** * Property accessor + * @var ? */ protected $accessor = null; /*** * Cache system + * @var Cache|null */ protected $cache = null; /** * Form constraints + * @var array */ - protected $constraints = array(); + protected $constraints = []; /** * Is the form cached? + * @var bool */ public $isCached = true; + /** + * Form constructor. + * + * @param string $pathOrContent + * @param array|null $variables + * @param Cache|bool|null $cache + * @param Factory|null $factory + * + * @throws \InvalidArgumentException + */ public function __construct($pathOrContent = '', $variables = null, $cache = false, $factory = null) { if (null === $factory) { @@ -72,8 +98,8 @@ public function __construct($pathOrContent = '', $variables = null, $cache = fal if ($cache !== null && $cache !== false) { if ($cache === true) { - $this->cache = new \Gregwar\Cache\Cache; - } else if ($cache instanceof \Gregwar\Cache\Cache) { + $this->cache = new Cache; + } else if ($cache instanceof Cache) { $this->cache = $cache; } else { throw new \InvalidArgumentException('The parameter $cache should be false, true or an instance of Gregwar\Cache\Cache'); @@ -92,6 +118,9 @@ public function __construct($pathOrContent = '', $variables = null, $cache = fal $this->parse(); } + /** + * @return Factory|null + */ public function getFactory() { return $this->factory; @@ -99,6 +128,8 @@ public function getFactory() /** * Gets the parser data + * + * @return ParserData */ public function getParserData() { @@ -107,8 +138,10 @@ public function getParserData() /** * Sets the language + * + * @param Language $language */ - public function setLanguage(Language\Language $language) + public function setLanguage(Language $language) { $this->factory->setLanguage($language); $this->pushLanguage(); @@ -122,8 +155,8 @@ protected function pushLanguage() $language = $this->factory->getLanguage(); if ($language && $this->parserData) { - $fields = $this->parserData->getFields(); - foreach ($fields as &$field) { + /** @var Field $field */ + foreach ($this->parserData->getFields() as &$field) { $field->setLanguage($this->factory->getLanguage()); } } @@ -131,6 +164,10 @@ protected function pushLanguage() /** * Get the form contents + * + * @return string + * + * @throws \InvalidArgumentException */ public function getContent() { @@ -156,11 +193,10 @@ public function getContent() */ protected function parse() { - $formidable = $this; - $generate = function() use ($formidable) { + $generate = function() { // Parses the contents - $parser = $formidable->getFactory()->getParser($formidable->getContent()); - $formidable->isCached = false; + $parser = $this->getFactory()->getParser($this->getContent()); + $this->isCached = false; return $parser; }; @@ -240,6 +276,10 @@ public function getValues() */ public function setValues($values, array $files = array()) { + /** + * @var string $name + * @var Field $field + */ foreach ($this->getFields() as $name => $field) { $name = $field->getBaseName(); $index = $field->getIndex(); @@ -298,6 +338,7 @@ public function setData($entity) $this->accessor = new PropertyAccessor; } + /** @var Field $field */ foreach ($this->getFields() as $field) { if (is_object($field)) { if (($mapping = $field->getMappingName()) && !$field->readOnly()) { @@ -316,6 +357,9 @@ public function setData($entity) /** * Defines a field value + * + * @param string $name + * @param mixed $value */ public function setValue($name, $value) { @@ -324,6 +368,9 @@ public function setValue($name, $value) /** * Defines a placeholder value + * + * @param string $name + * @param mixed $value */ public function setPlaceholder($name, $value) { @@ -332,6 +379,10 @@ public function setPlaceholder($name, $value) /** * Gets a field value + * + * @param string $name + * + * @return mixed */ public function getValue($name) { @@ -340,6 +391,9 @@ public function getValue($name) /** * Add a constraint on a field + * + * @param string $name + * @param \Closure|callable $closure */ public function addConstraint($name, $closure = null) { @@ -357,6 +411,10 @@ public function addConstraint($name, $closure = null) /** * Defines an attribute value + * + * @param string $name Field name + * @param string $attribute Attribute name + * @param string $value Attribute value */ public function setAttribute($name, $attribute, $value) { @@ -381,19 +439,28 @@ public function setOptionClass($select, $val, $class) /** * Get a field + * + * @return Field */ public function getField($name) { return $this->parserData->getField($name); } + /** + * Get all fields + * + * @return array [Field,...] + */ public function getFields() { return $this->parserData->getFields(); } /** - * Convert to HTML + * @proxy getHtml() + * + * @return string Html string */ public function __toString() { @@ -402,6 +469,8 @@ public function __toString() /** * Get the JavaScript code to embed + * + * @return string Html script tag */ public function getJs() { @@ -415,6 +484,8 @@ public function getJs() /** * Convert to HTML + * + * @return string HTML */ public function getHtml() { @@ -441,6 +512,8 @@ public function getHtml() /** * Error checking + * + * @return array [Error,...] */ public function check() { @@ -474,16 +547,25 @@ public function check() /** * Values sourcing + * + * @param string $source + * @param mixed $data */ public function source($source, $data) { - $sources = $this->parserData->getSources(); - - $sources[$source]->source($data); + $this->parserData + ->getSources()[$source] + ->source($data); } /** * Gets the data using mapping + * + * Side effect:? + * + * @param array $entity + * + * @return ? */ public function getData($entity = array()) { @@ -506,6 +588,10 @@ public function getData($entity = array()) /** * Get a field's value + * + * @param string $name + * + * @return mixed */ public function __get($name) { @@ -514,6 +600,9 @@ public function __get($name) /** * Set a field value + * + * @param string $var + * @param mixed $val */ public function __set($var, $val) { @@ -522,6 +611,8 @@ public function __set($var, $val) /** * Get the CSRF manager + * + * @return PostIndicator|null */ public function getPostIndicator() { @@ -536,6 +627,8 @@ public function getPostIndicator() /** * Gets the post indicator + * + * @return string */ public function getToken() { @@ -544,6 +637,12 @@ public function getToken() /** * Check if the form was posted + * + * Side effect: will set form values according to $_GET, $_POST and $_FILES + * + * @param string $method + * + * @return bool */ public function posted($method = 'post') { @@ -563,8 +662,13 @@ public function posted($method = 'post') /** * Check a form, helper function + * + * @param callable|null $callback + * @param callable|null $errorsCallback + * + * @return array */ - public function handle($callback = null, $errorsCallback = null) + public function handle(callable $callback = null, callable $errorsCallback = null) { if ($this->posted()) { $errors = $this->check(); diff --git a/src/ParserData.php b/src/ParserData.php index a0d1003..703485e 100644 --- a/src/ParserData.php +++ b/src/ParserData.php @@ -52,6 +52,7 @@ public function getData() /** * Fields mapped by name + * @return array */ public function getFields() { @@ -92,6 +93,10 @@ public function needJs() /** * Gets a field + * + * @return Field + * + * @throws \InvalidArgumentException */ public function getField($name) {