From 41df5290f0bfc89ad7b54dcf005449483f533b8d Mon Sep 17 00:00:00 2001 From: Grigory Parshikov Date: Tue, 5 Nov 2013 23:54:51 +0600 Subject: [PATCH] Some improvements --- Petrovich.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Petrovich.php b/Petrovich.php index 97e6629..b2b245a 100644 --- a/Petrovich.php +++ b/Petrovich.php @@ -124,22 +124,18 @@ public function lastname($lastname, $case = Petrovich::CASE_NOMENATIVE) { * @return bool|string */ private function inflect($name,$case,$type) { - if(($exception = $this->checkException($name,$case,$type)) !== false) - return $exception; + $names_arr = explode('-',$name); + $result = array(); - //если двойное имя или фамилия или отчество - if(mb_substr_count($name,'-') > 0) { - $names_arr = explode('-',$name); - $result = ''; - - foreach($names_arr as $arr_name) { - $result .= $this->findInRules($arr_name,$case,$type).'-'; + foreach($names_arr as $arr_name) { + if(($exception = $this->checkException($arr_name,$case,$type)) !== false) { + $result[] = $exception; + } + else { + $result[] = $this->findInRules($arr_name,$case,$type); } - return mb_substr($result,0,mb_strlen($result)-1); - } - else { - return $this->findInRules($name,$case,$type); } + return implode('-',$result); } /** @@ -184,6 +180,8 @@ private function checkException($name,$case,$type) { if ( ! $this->checkGender($rule->gender) ) continue; if(array_search($lower_name,$rule->test) !== false) { + if($rule->mods[$case] == '.') + return $name; return $this->applyRule($rule->mods,$name,$case); } }