test(classifier): boundary + array-value tests for has_short_latin_name; @return tags
- Add @return bool to has_valid_email_anywhere docblock
- Add @return bool to has_short_latin_name docblock
- Add Cyrillic note to has_short_latin_name docblock
- Add test_has_short_latin_name_true_for_single_letter_boundary (lower bound)
- Add test_has_short_latin_name_false_for_four_letters_boundary (upper bound)
- Add test_has_short_latin_name_false_for_array_value_with_space_join (regression)
Addresses code review feedback from commit 660a0d2.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -226,6 +226,7 @@ final class Classifier
|
||||
* shape). Deeper nesting is intentionally NOT supported.
|
||||
*
|
||||
* @param array<string,string|string[]> $fields CF7 posted_data
|
||||
* @return bool True if any value contains a syntactically valid email
|
||||
*/
|
||||
public static function has_valid_email_anywhere(array $fields): bool
|
||||
{
|
||||
@@ -252,7 +253,10 @@ final class Classifier
|
||||
* the value-based heuristic in FieldDetector::find_name(). Returns false if no name
|
||||
* field is present (i.e. forms without a name field are immune to this rule).
|
||||
*
|
||||
* Cyrillic look-alikes (e.g. 'ОВ') are rejected because the regex is byte-range.
|
||||
*
|
||||
* @param array<string,string|string[]> $fields CF7 posted_data
|
||||
* @return bool True if a name field exists and is 1-3 ASCII alphanumeric chars
|
||||
*/
|
||||
public static function has_short_latin_name(array $fields): bool
|
||||
{
|
||||
|
||||
@@ -81,4 +81,25 @@ final class ClassifierDropTest extends Cf7stgTestCase
|
||||
$fields = ['text-211' => 'XY', 'text-212' => '+79991234567'];
|
||||
self::assertTrue(Classifier::has_short_latin_name($fields));
|
||||
}
|
||||
|
||||
public function test_has_short_latin_name_true_for_single_letter_boundary(): void
|
||||
{
|
||||
// Lower boundary of {1,3}: 1 char accepted
|
||||
$fields = ['your-name' => 'A'];
|
||||
self::assertTrue(Classifier::has_short_latin_name($fields));
|
||||
}
|
||||
|
||||
public function test_has_short_latin_name_false_for_four_letters_boundary(): void
|
||||
{
|
||||
// Upper boundary of {1,3}: 4 chars rejected
|
||||
$fields = ['your-name' => 'ABCD'];
|
||||
self::assertFalse(Classifier::has_short_latin_name($fields));
|
||||
}
|
||||
|
||||
public function test_has_short_latin_name_false_for_array_value_with_space_join(): void
|
||||
{
|
||||
// pick_field joins array values with a space → "OB MU" is 5 chars → no false positive.
|
||||
$fields = ['your-name' => ['OB', 'MU']];
|
||||
self::assertFalse(Classifier::has_short_latin_name($fields));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user