Skip to content

Commit ac96828

Browse files
committed
Email name parser: toString() in result objects.
1 parent 49a44b3 commit ac96828

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,11 @@ public function getConfidence() {
5757
return $this->confidence;
5858
}
5959

60+
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.'}';
66+
}
6067
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,12 @@ public function getMatches() {
4141
return $this->matches;
4242
}
4343

44+
45+
public function __toString() {
46+
$ret = 'Result{';
47+
$ret .= 'type='.$this->resultType;
48+
$ret .= ', matches='. implode(", ",$this->matches);
49+
return $ret.'}';
50+
}
51+
4452
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,17 @@ public function getNameType() {
4040
return $this->nameType;
4141
}
4242

43+
44+
public function __toString() {
45+
// $ret = 'NameFromEmailAddress{';
46+
// $ret .= 'name='.$this->name;
47+
// $ret .= ', nameType='.$this->nameType;
48+
// return $ret.'}';
49+
50+
$ret = $this->name;
51+
if ($this->nameType->toString()!='NAME') {
52+
$ret .= ' (type='.$this->nameType->toString().')';
53+
}
54+
return $ret;
55+
}
4356
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ 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;
1415
$this->assertEquals('PERSON_NAME', $result->getResultType()->toString());
1516
$firstMatch = $result->getMatches()[0];
1617
$this->assertEquals('john', $firstMatch->getGivenNames()[0]->getName());

0 commit comments

Comments
 (0)