Skip to content

Commit

Permalink
Merge pull request #156 from anoriar/validation-for-one-char-name
Browse files Browse the repository at this point in the history
фамилия, имя, отчество, состоящее из одной буквы считается несклоняемым
  • Loading branch information
wapmorgan authored Sep 26, 2024
2 parents 55cba44 + 0acb078 commit cb4565d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Russian/FirstNamesInflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ public static function getCases($name, $gender = null)
*/
public static function isMutable($name, $gender = null)
{
if (S::length($name) === 1) {
return false;
}

$name = S::lower($name);

if (in_array($name, static::$immutableNames, true)) {
Expand Down
5 changes: 5 additions & 0 deletions src/Russian/LastNamesInflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ public static function getCase($name, $case, $gender = null)
*/
public static function isMutable($name, $gender = null)
{
if (S::length($name) === 1) {
return false;
}

$name = S::lower($name);

if ($gender === null) {
$gender = static::detectGender($name);
}
Expand Down
5 changes: 5 additions & 0 deletions src/Russian/MiddleNamesInflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public static function detectGender($name)
*/
public static function isMutable($name, $gender = null)
{
if (S::length($name) === 1) {
return false;
}

$name = S::lower($name);

if (in_array(S::slice($name, -2), ['ич', 'на'], true)) {
return true;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Russian/FirstNamesInflecionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ public function immutableNamesProvider()
['Грегори', FirstNamesInflection::MALE],
['Гиви', FirstNamesInflection::MALE],
['Франсуа', FirstNamesInflection::MALE],
['А', NamesInflection::FEMALE],
];
}

Expand Down
1 change: 1 addition & 0 deletions tests/Russian/LastNamesInflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public function immutableNamesProvider()
['Хитрово', NamesInflection::MALE],
['Бози', NamesInflection::MALE],
['Цой', NamesInflection::FEMALE],
['А', NamesInflection::FEMALE],
];
}
}
16 changes: 16 additions & 0 deletions tests/Russian/MiddleNamesInflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use morphos\NamesInflection;
use morphos\Russian\Cases;
use morphos\Russian\LastNamesInflection;
use morphos\Russian\MiddleNamesInflection;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -90,4 +91,19 @@ public function testGetCase($name, $gender, $case2)
{
$this->assertEquals($case2, MiddleNamesInflection::getCase($name, Cases::RODIT, $gender));
}

/**
* @dataProvider immutableNamesProvider()
*/
public function testImmutable($name, $gender)
{
$this->assertFalse(MiddleNamesInflection::isMutable($name, $gender));
}

public function immutableNamesProvider()
{
return [
['А', NamesInflection::FEMALE],
];
}
}

0 comments on commit cb4565d

Please sign in to comment.