Skip to content

Commit

Permalink
Applied fixes from StyleCI (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue authored Aug 17, 2016
1 parent a3b8ac6 commit 7af85b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/Pinyin.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,12 @@ protected function romanize($string, $isName = false)
*
* @return string
*/
protected function convertSurname($string, $dictLoader) {
protected function convertSurname($string, $dictLoader)
{
$dictLoader->mapSurname(function ($dictionary) use (&$string) {
foreach ($dictionary as $surname => $pinyin) {
if (strpos($string, $surname) === 0) {
$string = $pinyin . mb_substr($string, mb_strlen($surname, 'UTF-8'), mb_strlen($string, 'UTF-8') - 1, 'UTF-8');
$string = $pinyin.mb_substr($string, mb_strlen($surname, 'UTF-8'), mb_strlen($string, 'UTF-8') - 1, 'UTF-8');
break;
}
}
Expand Down
7 changes: 3 additions & 4 deletions tests/PinyinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ public function testName()
$this->assertSame(array('yu', 'chi', 'pu'), $pinyin->name('尉迟朴'));
$this->assertSame(array('wei', 'mou', 'mou'), $pinyin->name('尉某某'));
$this->assertSame(array('yu', 'chi', 'mou', 'mou'), $pinyin->name('尉迟某某'));
$this->assertSame(array('zhai', 'di', 'di',), $pinyin->name('翟翟翟'));
$this->assertSame(array('zhai', 'di', 'di'), $pinyin->name('翟翟翟'));

// 以下两词在任何位置都不变
$this->assertSame(array('mou', 'mou', 'yu', 'chi',), $pinyin->name('某某尉迟'));
$this->assertSame(array('mou', 'mou', 'yu', 'chi'), $pinyin->name('某某尉迟'));
$this->assertSame(array('shan', 'chan', 'yu', 'dan'), $pinyin->name('单单于单'));
}

Expand Down Expand Up @@ -258,11 +258,10 @@ public function map(Closure $callback)
public function mapSurname(Closure $callback)
{
$dictionary = array(
'' => "shan",
'' => 'shan',
'' => 'piao',
'尉迟' => 'yu chi',
);
$callback($dictionary);
}

}

0 comments on commit 7af85b0

Please sign in to comment.