From 4b4a3a2fbc8b244e9b85fd89d18538e9aec8d1df Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Tue, 17 Mar 2026 11:45:02 +0100 Subject: [PATCH 1/4] fix: Rely on new Exception class pear stub --- composer.json | 25 ++++---- lib/Horde/Form.php | 78 +++++++++++++++++++++--- lib/Horde/Form/Action.php | 2 + lib/Horde/Form/Renderer.php | 4 +- lib/Horde/Form/Type.php | 59 +++++++++++++++--- test/bootstrap.php | 5 -- test/integration/FormIntegrationTest.php | 6 ++ test/unit/FormTest.php | 44 +++++-------- 8 files changed, 158 insertions(+), 65 deletions(-) diff --git a/composer.json b/composer.json index a3f9214..1aea01e 100644 --- a/composer.json +++ b/composer.json @@ -16,19 +16,19 @@ "role": "lead" } ], - "time": "2025-07-05", + "time": "2026-03-17", "repositories": [], "require": { "php": "^7.4 || ^8", - "horde/core": "^3 || dev-FRAMEWORK_6_0", - "horde/date": "^3 || dev-FRAMEWORK_6_0", - "horde/exception": "^3 || dev-FRAMEWORK_6_0", - "horde/mail": "^3 || dev-FRAMEWORK_6_0", - "horde/mime": "^3 || dev-FRAMEWORK_6_0", - "horde/nls": "^3 || dev-FRAMEWORK_6_0", - "horde/token": "^3 || dev-FRAMEWORK_6_0", - "horde/translation": "^3 || dev-FRAMEWORK_6_0", - "horde/util": "^3 || dev-FRAMEWORK_6_0", + "horde/core": "^3", + "horde/date": "^3", + "horde/exception": "^3", + "horde/mail": "^3", + "horde/mime": "^3", + "horde/nls": "^3", + "horde/token": "^3", + "horde/translation": "^3", + "horde/util": "^3", "ext-json": "*" }, "require-dev": { @@ -37,6 +37,7 @@ "phpstan/phpstan": "^2" }, "suggest": {}, + "minimum-stability": "alpha", "autoload": { "classmap": [ "lib/" @@ -51,7 +52,9 @@ } }, "config": { - "allow-plugins": {} + "allow-plugins": { + "horde/horde-installer-plugin": true + } }, "extra": { "branch-alias": { diff --git a/lib/Horde/Form.php b/lib/Horde/Form.php index bfdef04..4ba83e6 100644 --- a/lib/Horde/Form.php +++ b/lib/Horde/Form.php @@ -19,6 +19,8 @@ require_once 'Horde/Form/Type.php'; } +use Horde\Util\ArrayUtils; + /** * Horde_Form Master Class. * @@ -55,7 +57,8 @@ class Horde_Form public function __construct($vars, $title = '', $name = null) { if (empty($name)) { - $name = Horde_String::lower(get_class($this)); + static $counter = 0; + $name = Horde_String::lower(get_class($this)) . '_' . (++$counter); } $name = str_replace('\\', '_', $name); @@ -161,9 +164,21 @@ public function getRenderer($params = []) } /** - * Initialize a Horde_Form_Type object from a type id + * Initialize a Horde_Form_Type object from a type id (internal use only) + * + * This method is private as of 3.0.0-beta4 to encapsulate parameter normalization logic. + * External code should use Horde_Form_Type::create() instead for instantiating types. + * + * For legacy code not yet migrated to src/V3, use Horde_Form_Type::create($type, $params) + * which provides the same functionality with a stable public API. + * + * @param string $type Type identifier + * @param array $params Type initialization parameters * + * @return Horde_Form_Type * @throws Horde_Exception + * + * @since 3.0.0-beta4 Changed to private visibility */ private function getType($type, $params = []) { @@ -256,6 +271,50 @@ public function getSectionExpandedState($section, $boolean = false) } } + /** + * Get information about all form sections. + * + * Returns an array of section metadata for all sections in the form. + * Useful for rendering section navigation or inspecting section structure. + * Migration aid for V3 compatibility. + * + * @return array Array of section info keyed by section name, each containing: + * - title: Section description/title + * - image: Section image (if any) + * - expanded: Whether section is expanded (boolean) + * + * @since 3.0.0 + */ + public function getSectionInfo(): array + { + $info = []; + foreach ($this->_sections as $section => $data) { + $info[$section] = [ + 'title' => $data['desc'] ?? '', + 'image' => $data['image'] ?? '', + 'expanded' => $data['expanded'] ?? true, + ]; + } + return $info; + } + + /** + * Get the form encoding type. + * + * Returns the encoding type needed for the form (e.g., 'multipart/form-data' + * for forms with file upload fields). This is automatically set when file + * or image field types are added to the form. + * Migration aid for V3 compatibility. + * + * @return string|null The encoding type, or null if not set + * + * @since 3.0.0 + */ + public function getEnctype(): ?string + { + return $this->_enctype; + } + /** * Add a new form field variable to the form. */ @@ -682,6 +741,9 @@ public function validate($vars = null, $canAutoFill = false) $vars = $this->_vars; } + // Clear previous validation errors + $this->_errors = []; + /* Get submitted status. */ if ($this->isSubmitted() || $canAutoFill) { /* Form was submitted or can autofill; check for any variable @@ -777,7 +839,7 @@ public function clearError($var) public function isValid() { - return ($this->_autofilled || count($this->_errors) == 0); + return count($this->_errors) == 0; } public function execute() @@ -832,10 +894,10 @@ public function _getInfoFromVariables($variables, $vars, $info) } else { // A field name like example[key1][key2][key3] $varName = $var->getVarName(); - if (Horde_Array::getArrayParts($varName, $base, $keys)) { + if (ArrayUtils::getArrayParts($varName, $base, $keys)) { $res = $var->getInfo($vars, $varName); $path = array_merge([$base], $keys); - Horde_Array::setElement($info, $path, $res); + ArrayUtils::setElement($info, $path, $res); } else { if (!isset($info[$varName])) { $info[$varName] = null; @@ -867,11 +929,7 @@ public function hasHelp() public function isSubmitted() { if (is_null($this->_submitted)) { - if ($this->_vars->get('formname') == $this->getName()) { - $this->_submitted = true; - } else { - $this->_submitted = false; - } + return ($this->_vars->get('formname') == $this->getName()); } return $this->_submitted; diff --git a/lib/Horde/Form/Action.php b/lib/Horde/Form/Action.php index f328a7c..81d9c8b 100644 --- a/lib/Horde/Form/Action.php +++ b/lib/Horde/Form/Action.php @@ -12,6 +12,8 @@ * @package Form */ +use Horde\Exception\PEAR; + /** * The Horde_Form_Action class provides an API for adding actions to * Horde_Form variables. diff --git a/lib/Horde/Form/Renderer.php b/lib/Horde/Form/Renderer.php index 0e04d8d..ab7a377 100644 --- a/lib/Horde/Form/Renderer.php +++ b/lib/Horde/Form/Renderer.php @@ -11,6 +11,8 @@ * @package Form */ +use Horde\Util\ArrayUtils; + /** * The Horde_Form_Renderer class provides HTML and other renderings of * forms for the Horde_Form:: package. @@ -235,7 +237,7 @@ public function getFormVars($form) // past. The actual forms need to be fixed instead. if ($var->isHidden() || !$var->isReadonly()) { $varname = $var->getVarName(); - if (Horde_Array::getArrayParts($varname, $base, $keys)) { + if (ArrayUtils::getArrayParts($varname, $base, $keys)) { array_unshift($keys, $base); $place = &$vars; while ($key = array_shift($keys)) { diff --git a/lib/Horde/Form/Type.php b/lib/Horde/Form/Type.php index de56fd9..f4c53f2 100644 --- a/lib/Horde/Form/Type.php +++ b/lib/Horde/Form/Type.php @@ -12,6 +12,8 @@ * @package Form */ +use Horde\Util\ArrayUtils; + /** * Horde_Form_Type Class * @@ -96,6 +98,45 @@ public function about() return ['name' => $this->getTypeName()]; } + /** + * Factory method to create form type instances + * + * This is the public API for instantiating form types outside of Form context. + * Use this instead of calling Horde_Form::getType() which is private. + * + * @param string $type Type name (e.g., 'html', 'email') or app-prefixed (e.g., 'turba:TurbaTags') + * @param array $params Type parameters to pass to init() + * + * @return Horde_Form_Type + * @throws Horde_Exception If type class does not exist + * + * @since 3.0.0 + */ + public static function create(string $type, array $params = []): Horde_Form_Type + { + if (strpos($type, ':') !== false) { + [$app, $type] = explode(':', $type); + $type_class = $app . '_Form_Type_' . $type; + } else { + $type_class = 'Horde_Form_Type_' . $type; + } + + if (!class_exists($type_class)) { + throw new Horde_Exception(sprintf( + 'Nonexistent class "%s" for field type "%s"', + $type_class, + $type + )); + } + + $type_obj = new $type_class(); + if (!empty($params)) { + $type_obj->init(...array_values($params)); + } + + return $type_obj; + } + } class Horde_Form_Type_spacer extends Horde_Form_Type @@ -1264,19 +1305,19 @@ private function _getUpload($vars, $var) $this->_img['img']['type'] = $this->getUploadedFileType($varname . '[new]'); /* Get the other parts of the upload. */ - Horde_Array::getArrayParts($varname . '[new]', $base, $keys); + ArrayUtils::getArrayParts($varname . '[new]', $base, $keys); /* Get the temporary file name. */ $keys_path = array_merge([$base, 'tmp_name'], $keys); - $this->_img['img']['file'] = Horde_Array::getElement($_FILES, $keys_path); + $this->_img['img']['file'] = ArrayUtils::getElement($_FILES, $keys_path); /* Get the actual file name. */ $keys_path = array_merge([$base, 'name'], $keys); - $this->_img['img']['name'] = Horde_Array::getElement($_FILES, $keys_path); + $this->_img['img']['name'] = ArrayUtils::getElement($_FILES, $keys_path); /* Get the file size. */ $keys_path = array_merge([$base, 'size'], $keys); - $this->_img['img']['size'] = Horde_Array::getElement($_FILES, $keys_path); + $this->_img['img']['size'] = ArrayUtils::getElement($_FILES, $keys_path); /* Get any existing values for the image upload field. */ $upload = $vars->get($var->getVarName()); @@ -1326,14 +1367,14 @@ private function _getUpload($vars, $var) public function getUploadedFileType($field) { /* Get any index on the field name. */ - $index = Horde_Array::getArrayParts($field, $base, $keys); + $index = ArrayUtils::getArrayParts($field, $base, $keys); if ($index) { /* Index present, fetch the mime type var to check. */ $keys_path = array_merge([$base, 'type'], $keys); - $type = Horde_Array::getElement($_FILES, $keys_path); + $type = ArrayUtils::getElement($_FILES, $keys_path); $keys_path = array_merge([$base, 'tmp_name'], $keys); - $tmp_name = Horde_Array::getElement($_FILES, $keys_path); + $tmp_name = ArrayUtils::getElement($_FILES, $keys_path); } else { /* No index, simple set up of vars to check. */ $type = $_FILES[$field]['type']; @@ -1346,14 +1387,14 @@ public function getUploadedFileType($field) if ($index) { /* Get the name value. */ $keys_path = array_merge([$base, 'name'], $keys); - $name = Horde_Array::getElement($_FILES, $keys_path); + $name = ArrayUtils::getElement($_FILES, $keys_path); /* Work out the type from the file name. */ $type = Horde_Mime_Magic::filenameToMime($name); /* Set the type. */ $keys_path = array_merge([$base, 'type'], $keys); - Horde_Array::setElement($_FILES, $keys_path, $type); + ArrayUtils::setElement($_FILES, $keys_path, $type); } else { /* Work out the type from the file name. */ $type = Horde_Mime_Magic::filenameToMime($_FILES[$field]['name']); diff --git a/test/bootstrap.php b/test/bootstrap.php index 4f1071f..ff05c96 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -2,12 +2,7 @@ /** * Bootstrap file for PHPUnit tests. - * - * Loads Composer autoloader and test stubs. */ // Load Composer autoloader require_once __DIR__ . '/../vendor/autoload.php'; - -// Load Horde class stubs for testing -require_once __DIR__ . '/stubs/HordeStubs.php'; diff --git a/test/integration/FormIntegrationTest.php b/test/integration/FormIntegrationTest.php index 756d4be..89e1bae 100644 --- a/test/integration/FormIntegrationTest.php +++ b/test/integration/FormIntegrationTest.php @@ -38,6 +38,7 @@ public function testSimpleFeedbackFormLifecycle(): void // 1. Create form $vars = new Horde_Variables(); $form = new Horde_Form($vars, 'Report inappropriate content'); + $form->useToken(false); // 2. Add fields $form->addHidden('', 'item_id', 'int', true); @@ -55,6 +56,7 @@ public function testSimpleFeedbackFormLifecycle(): void $this->assertFalse($form->validate($vars)); // 4. Simulate submission with missing required field + $vars->set('formname', $form->getName()); $vars->set($form->getName() . '_submitted', '1'); $vars->set('item_id', 123); // reason is missing @@ -87,6 +89,7 @@ public function testMultiSectionForm(): void { $vars = new Horde_Variables(); $form = new Horde_Form($vars, 'Task Form'); + $form->useToken(false); // Section 1: General $form->setSection('general', 'General'); @@ -111,6 +114,7 @@ public function testMultiSectionForm(): void $this->assertCount(2, $allVars['details']); // Submit form + $vars->set('formname', $form->getName()); $vars->set($form->getName() . '_submitted', '1'); $vars->set('name', 'My Task'); $vars->set('priority', 3); @@ -212,6 +216,7 @@ public function testInheritedFormClass(): void { $vars = new Horde_Variables(); $form = new TestContactForm($vars); + $form->useToken(false); // Check that constructor set up fields $variables = $form->getVariables(); @@ -224,6 +229,7 @@ public function testInheritedFormClass(): void $this->assertContains('phone', $varNames); // Submit form + $vars->set('formname', $form->getName()); $vars->set($form->getName() . '_submitted', '1'); $vars->set('name', 'John Doe'); $vars->set('email', 'john@example.com'); diff --git a/test/unit/FormTest.php b/test/unit/FormTest.php index 7720670..a284858 100644 --- a/test/unit/FormTest.php +++ b/test/unit/FormTest.php @@ -17,6 +17,7 @@ namespace Horde\Form\Test\Unit; use Horde_Form; +use Horde_Form_Type; use Horde_Form_Variable; use Horde_Variables; use PHPUnit\Framework\Attributes\CoversClass; @@ -402,41 +403,25 @@ public function testRemoveVariableReturnsFalseIfNotFound(): void public function testGetTypeWithStringReturnsTypeObject(): void { - $vars = new Horde_Variables(); - $form = new Horde_Form($vars); - - $type = $form->getType('text'); + $type = Horde_Form_Type::create(type: 'text'); $this->assertInstanceOf(\Horde_Form_Type_text::class, $type); } - public function testGetTypeWithObjectReturnsObject(): void + public function testGetTypeWithInvalidTypeThrowsException(): void { - $vars = new Horde_Variables(); - $form = new Horde_Form($vars); - - $typeObj = new \Horde_Form_Type_text(); - $result = $form->getType($typeObj); + $this->expectException(\Horde_Exception::class); + $this->expectExceptionMessage('Nonexistent class'); - $this->assertSame($typeObj, $result); - } - - public function testGetTypeWithInvalidTypeReturnsInvalid(): void - { - $vars = new Horde_Variables(); - $form = new Horde_Form($vars); - - $type = $form->getType('nonexistent_type'); - - $this->assertInstanceOf(\Horde_Form_Type_invalid::class, $type); + Horde_Form_Type::create(type: 'nonexistent_type'); } public function testGetTypeWithParametersInitializesType(): void { - $vars = new Horde_Variables(); - $form = new Horde_Form($vars); - - $type = $form->getType('enum', [['opt1' => 'Option 1', 'opt2' => 'Option 2']]); + $type = Horde_Form_Type::create( + type: 'enum', + params: [['opt1' => 'Option 1', 'opt2' => 'Option 2']] + ); $this->assertInstanceOf(\Horde_Form_Type_enum::class, $type); $values = $type->getValues(); @@ -445,11 +430,11 @@ public function testGetTypeWithParametersInitializesType(): void public function testGetTypeConvertsNamedParamsToPositional(): void { - $vars = new Horde_Variables(); - $form = new Horde_Form($vars); - // Named parameters should be wrapped in array - $type = $form->getType('monthdayyear', ['start_year' => 1900, 'end_year' => 2050]); + $type = Horde_Form_Type::create( + type: 'monthdayyear', + params: ['start_year' => 1900, 'end_year' => 2050] + ); $this->assertInstanceOf(\Horde_Form_Type_monthdayyear::class, $type); } @@ -477,6 +462,7 @@ public function testValidateReturnsTrueForValidForm(): void 'formname' => 'test_form' ]); $form = new Horde_Form($vars, '', 'test_form'); + $form->useToken(false); $form->addVariable('Name', 'name', 'text', true); $vars->set($form->getName() . '_submitted', '1'); From b97ca27b99361f1cf4811c57cda555991946e15a Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Tue, 17 Mar 2026 12:08:21 +0100 Subject: [PATCH 2/4] fix: cast to string explicitly. --- lib/Horde/Form/Type.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Horde/Form/Type.php b/lib/Horde/Form/Type.php index f4c53f2..cfc2dfc 100644 --- a/lib/Horde/Form/Type.php +++ b/lib/Horde/Form/Type.php @@ -422,7 +422,7 @@ public function isValid($var, $vars, $value, $message) } if ($var->isRequired() && empty($this->_regex)) { - if (strlen(trim($value)) == 0) { + if (strlen(trim((string)$value)) == 0) { return $this->invalid('This field is required.'); } } elseif (!empty($this->_regex) && !preg_match($this->_regex, $value)) { From 66cde40f7517c74c91469e45ebde7d9b04c4ccc8 Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Tue, 17 Mar 2026 12:09:22 +0100 Subject: [PATCH 3/4] test: Reduce reliance on real externals in unit tests and prefer named parameters --- test/bootstrap.php | 33 ++++++++++++++++++++++ test/unit/ActionTest.php | 16 +++++++++-- test/unit/Type/TextTypeTest.php | 50 +++++++++++++++++++++++++-------- 3 files changed, 85 insertions(+), 14 deletions(-) diff --git a/test/bootstrap.php b/test/bootstrap.php index ff05c96..756242a 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -6,3 +6,36 @@ // Load Composer autoloader require_once __DIR__ . '/../vendor/autoload.php'; + +// Setup minimal global mocks for Horde dependencies +// These are needed by Horde_Form when form tokens are enabled + +// Mock injector +if (!isset($GLOBALS['injector'])) { + $GLOBALS['injector'] = new class { + public function getInstance($interface) + { + if ($interface === 'Horde_Token') { + return new class { + public function verify($token) + { + // Mock token verification - always returns true for tests + return true; + } + }; + } + return null; + } + }; +} + +// Mock session +if (!isset($GLOBALS['session'])) { + $GLOBALS['session'] = new class { + public function get($app, $key) + { + // Mock session - returns true to simulate valid form secret + return true; + } + }; +} diff --git a/test/unit/ActionTest.php b/test/unit/ActionTest.php index b19c286..cd1846a 100644 --- a/test/unit/ActionTest.php +++ b/test/unit/ActionTest.php @@ -97,9 +97,13 @@ public function testGetActionScriptReturnsEmptyString(): void { $action = new Horde_Form_Action(); $form = $this->createMock(Horde_Form::class); - $renderer = null; + $renderer = $this->createMock(\Horde_Form_Renderer::class); - $script = $action->getActionScript($form, $renderer, 'varname'); + $script = $action->getActionScript( + form: $form, + renderer: $renderer, + varname: 'varname' + ); $this->assertEquals('', $script); } @@ -120,7 +124,13 @@ public function testSetValuesDoesNothing(): void $vars = new Horde_Variables(); // Should not throw exception - $action->setValues($vars, 'value', null, false); + // Note: setValues uses positional params ($vars, $sourceVal, $index, $arrayVal) + $action->setValues( + vars: $vars, + sourceVal: 'value', + index: null, + arrayVal: false + ); $this->assertTrue(true); } diff --git a/test/unit/Type/TextTypeTest.php b/test/unit/Type/TextTypeTest.php index 435b11f..e2ccded 100644 --- a/test/unit/Type/TextTypeTest.php +++ b/test/unit/Type/TextTypeTest.php @@ -115,12 +115,18 @@ public function testIsValidAllowsZeroForRequiredField(): void public function testIsValidReturnsFalseWhenExceedsMaxLength(): void { $type = new Horde_Form_Type_text(); - $type->init(40, 10); // Max 10 characters + // init() uses variadic params: init(regex, size, maxlength) + $type->init('', 40, 10); - $var = $this->createMockVariable(false); + $var = $this->createMockVariable(required: false); $vars = new Horde_Variables(); - $result = $type->isValid($var, $vars, 'this is too long', $message = ''); + $result = $type->isValid( + var: $var, + vars: $vars, + value: 'this is too long', + message: '' + ); $this->assertFalse($result); } @@ -128,12 +134,18 @@ public function testIsValidReturnsFalseWhenExceedsMaxLength(): void public function testIsValidReturnsTrueWhenWithinMaxLength(): void { $type = new Horde_Form_Type_text(); - $type->init(40, 20); // Max 20 characters + // init() uses variadic params: init(regex, size, maxlength) + $type->init('', 40, 20); - $var = $this->createMockVariable(false); + $var = $this->createMockVariable(required: false); $vars = new Horde_Variables(); - $result = $type->isValid($var, $vars, 'short', $message = ''); + $result = $type->isValid( + var: $var, + vars: $vars, + value: 'short', + message: '' + ); $this->assertTrue($result); } @@ -141,23 +153,39 @@ public function testIsValidReturnsTrueWhenWithinMaxLength(): void public function testIsValidWithRegex(): void { $type = new Horde_Form_Type_text(); - $type->init(40, null); + // init() uses variadic params: init(regex, size, maxlength) + $type->init('', 40, null); // Access protected property via reflection for testing $reflection = new \ReflectionClass($type); $regexProp = $reflection->getProperty('_regex'); $regexProp->setAccessible(true); $regexProp->setValue($type, '/^[0-9]+$/'); - $var = $this->createMockVariable(false); + $var = $this->createMockVariable(required: false); $vars = new Horde_Variables(); - $this->assertTrue($type->isValid($var, $vars, '12345', $message = '')); - $this->assertFalse($type->isValid($var, $vars, 'abc', $message = '')); + $this->assertTrue($type->isValid( + var: $var, + vars: $vars, + value: '12345', + message: '' + )); + $this->assertFalse($type->isValid( + var: $var, + vars: $vars, + value: 'abc', + message: '' + )); } private function createMockVariable(bool $required): Horde_Form_Variable { $type = new Horde_Form_Type_text(); - return new Horde_Form_Variable('Test', 'test', $type, $required); + return new Horde_Form_Variable( + humanName: 'Test', + varName: 'test', + type: $type, + required: $required + ); } } From dcdd3d5018c5500d3a0c63ccf0a6ace91d13a3f8 Mon Sep 17 00:00:00 2001 From: Ralf Lang Date: Tue, 17 Mar 2026 12:20:06 +0100 Subject: [PATCH 4/4] fix: More security casting --- src/V3/DateVariable.php | 2 +- src/V3/Ip6addressVariable.php | 2 +- src/V3/IpaddressVariable.php | 2 +- src/V3/PasswordVariable.php | 2 +- src/V3/PhoneVariable.php | 2 +- src/V3/TextVariable.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/V3/DateVariable.php b/src/V3/DateVariable.php index 95cae47..51a8507 100644 --- a/src/V3/DateVariable.php +++ b/src/V3/DateVariable.php @@ -28,7 +28,7 @@ public function init(...$params) protected function isValid(Horde_Variables|array $vars, $value): bool { - if ($this->isRequired() && strlen(trim($value)) == 0) { + if ($this->isRequired() && strlen(trim((string)$value)) == 0) { $this->message = sprintf(Horde_Form_Translation::t("%s is required"), $this->getHumanName()); return false; } diff --git a/src/V3/Ip6addressVariable.php b/src/V3/Ip6addressVariable.php index 0ff9d03..62a3dbb 100644 --- a/src/V3/Ip6addressVariable.php +++ b/src/V3/Ip6addressVariable.php @@ -15,7 +15,7 @@ class Ip6addressVariable extends TextVariable { public function isValid(Horde_Variables $vars, $value): bool { - if (strlen(trim($value)) > 0) { + if (strlen(trim((string)$value)) > 0) { $valid = @inet_pton($value); if ($valid === false) { return $this->invalid('Please enter a valid IP address.'); diff --git a/src/V3/IpaddressVariable.php b/src/V3/IpaddressVariable.php index 54d258f..c737182 100644 --- a/src/V3/IpaddressVariable.php +++ b/src/V3/IpaddressVariable.php @@ -15,7 +15,7 @@ class IpaddressVariable extends TextVariable { public function isValid(Horde_Variables $vars, $value): bool { - if (strlen(trim($value)) > 0) { + if (strlen(trim((string)$value)) > 0) { $ip = explode('.', $value); $valid = (count($ip) == 4); if ($valid) { diff --git a/src/V3/PasswordVariable.php b/src/V3/PasswordVariable.php index 763493c..6f60601 100644 --- a/src/V3/PasswordVariable.php +++ b/src/V3/PasswordVariable.php @@ -11,7 +11,7 @@ class PasswordVariable extends BaseVariable { public function isValid(Horde_Variables $vars, $value): bool { - if ($this->isRequired() && strlen(trim($value)) == 0) { + if ($this->isRequired() && strlen(trim((string)$value)) == 0) { return $this->invalid('This field is required.'); } diff --git a/src/V3/PhoneVariable.php b/src/V3/PhoneVariable.php index fe0c451..d04be1f 100644 --- a/src/V3/PhoneVariable.php +++ b/src/V3/PhoneVariable.php @@ -31,7 +31,7 @@ public function init(...$params) public function isValid(Horde_Variables $vars, $value): bool { - if (!strlen(trim($value))) { + if (!strlen(trim((string)$value))) { if ($this->isRequired()) { return $this->invalid('This field is required.'); } diff --git a/src/V3/TextVariable.php b/src/V3/TextVariable.php index 839b976..72cc463 100644 --- a/src/V3/TextVariable.php +++ b/src/V3/TextVariable.php @@ -41,7 +41,7 @@ public function isValid(Horde_Variables $vars, $value): bool } if ($this->isRequired() && empty($this->_regex)) { - if (strlen(trim($value)) == 0) { + if (strlen(trim((string)$value)) == 0) { return $this->invalid('This field is required.'); } } elseif (!empty($this->_regex) && !preg_match($this->_regex, $value)) {