Skip to content

Commit 66287b0

Browse files
committed
Email parser: toString improvements.
1 parent 28e734e commit 66287b0

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/org/nameapi/client/services/email/emailnameparser/EmailNameParserMatch.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,17 @@ public function getConfidence() {
5858
}
5959

6060
public function __toString() {
61-
$ret = '{';
62-
$ret .= 'givenNames='. implode(", ",$this->givenNames);
63-
$ret .= ', surnames='. implode(", ",$this->surnames);
64-
$ret .= ', confidence='.$this->confidence;
65-
return $ret.'}';
61+
$ret = '';
62+
if (count($this->givenNames) >0) {
63+
if (!empty($ret)) $ret .= ', ';
64+
$ret .= 'givenNames='. implode(", ",$this->givenNames);
65+
}
66+
if (count($this->surnames) >0) {
67+
if (!empty($ret)) $ret .= ', ';
68+
$ret .= 'surnames='. implode(", ",$this->surnames);
69+
}
70+
if (!empty($ret)) $ret .= ', ';
71+
$ret .= 'confidence='.$this->confidence;
72+
return '{'.$ret.'}';
6673
}
6774
}

src/org/nameapi/client/services/email/emailnameparser/EmailNameParserResult.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public function getMatches() {
4545
public function __toString() {
4646
$ret = 'Result{';
4747
$ret .= 'type='.$this->resultType;
48-
$ret .= ', matches='. implode(", ",$this->matches);
48+
if (count($this->matches) >0) {
49+
$ret .= ', matches='. implode(", ",$this->matches);
50+
}
4951
return $ret.'}';
5052
}
5153

tests/functional/org/nameapi/client/services/email/emailnameparser/EmailNameParserServiceTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class EmailNameParserServiceTest extends BaseServiceTest {
1111
public function testParse_John_Doe() {
1212
$emailNameParser = $this->makeServiceFactory()->emailServices()->emailNameParser();
1313
$result = $emailNameParser->parse("[email protected]");
14-
echo $result;
1514
$this->assertEquals('PERSON_NAME', (string)$result->getResultType());
1615
$firstMatch = $result->getMatches()[0];
1716
$this->assertEquals('john', $firstMatch->getGivenNames()[0]->getName());

0 commit comments

Comments
 (0)