Skip to content

Commit 2a1bc29

Browse files
Replace fieldModel to formModel in parameters in Utils::class. (#5)
1 parent 36a1d22 commit 2a1bc29

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Change Log
22

3-
## 0.1.2 February 29, 2024
3+
## 0.2.0 February 29, 2024
44

55
- Enh #4: Refactor `getShortNameClass()` method to support optional `suffix` and `lowercase` parameters (@terabytesoftw)
6+
- Bug #5: Replace `fieldModel` to `formModel` in parameters in `Utils::class` helper (@terabytesoftw)
67

78
## 0.1.1 February 29, 2024
89

src/Utils.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static function generateId(string $prefix = 'id-'): string
9696
*
9797
* For example, if {@see generateInputName()} returns `Post[content]`, this method will return `post-content`.
9898
*
99-
* @param string $fieldModel The field model name.
99+
* @param string $formModel The form model name.
100100
* @param string $property The property name or expression.
101101
* @param string $charset default `UTF-8`.
102102
*
@@ -106,11 +106,11 @@ public static function generateId(string $prefix = 'id-'): string
106106
* @return string the generated input ID.
107107
*/
108108
public static function generateInputId(
109-
string $fieldModel = '',
109+
string $formModel = '',
110110
string $property = '',
111111
string $charset = 'UTF-8'
112112
): string {
113-
$name = mb_strtolower(self::generateInputName($fieldModel, $property), $charset);
113+
$name = mb_strtolower(self::generateInputName($formModel, $property), $charset);
114114

115115
return str_replace(['[]', '][', '[', ']', ' ', '.'], ['', '-', '-', '', '-', '-'], $name);
116116
}
@@ -127,30 +127,30 @@ public static function generateInputId(
127127
* setting the `$arrayable` parameter to `true`. For example, if the form name of the `Post` form is `Post`, then
128128
* the input name generated for the `tags[]` property would be `Post[tags][]`.
129129
*
130-
* @param string $fieldModel The field model name.
130+
* @param string $formModel The form model name.
131131
* @param string $property The property name or expression.
132132
* @param bool $arrayable Whether to generate an arrayable input name. This is mainly used in tabular data input.
133133
*
134134
* @throws InvalidArgumentException If the property name contains non-word characters or empty form name for
135135
* tabular inputs
136136
*/
137-
public static function generateInputName(string $fieldModel, string $property, bool $arrayable = false): string
137+
public static function generateInputName(string $formModel, string $property, bool $arrayable = false): string
138138
{
139139
if ($arrayable === true) {
140140
$property = self::generateArrayableName($property);
141141
}
142142

143143
$data = self::parseProperty($property);
144144

145-
if ($fieldModel === '' && $data['prefix'] === '') {
145+
if ($formModel === '' && $data['prefix'] === '') {
146146
return $property;
147147
}
148148

149-
if ($fieldModel !== '') {
150-
return $fieldModel . $data['prefix'] . '[' . $data['name'] . ']' . $data['suffix'];
149+
if ($formModel !== '') {
150+
return $formModel . $data['prefix'] . '[' . $data['name'] . ']' . $data['suffix'];
151151
}
152152

153-
throw new InvalidArgumentException('The field model cannot be empty for tabular inputs.');
153+
throw new InvalidArgumentException('The form model name cannot be empty for tabular inputs.');
154154
}
155155

156156
/**

tests/UtilsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testGetInputNamewithOnlyCharacters(): void
8585
public function testGetInputNameExceptionWithTabular(): void
8686
{
8787
$this->expectException(InvalidArgumentException::class);
88-
$this->expectExceptionMessage('The field model cannot be empty for tabular inputs.');
88+
$this->expectExceptionMessage('The form model name cannot be empty for tabular inputs.');
8989

9090
Utils::generateInputName('', '[0]dates[0]');
9191
}

0 commit comments

Comments
 (0)