Skip to content

Commit 570c19e

Browse files
authored
Merge pull request #4 from peter279k/issue_#3
Add type hint with PHPDoc comment annotation style
2 parents fb114be + 94c55ce commit 570c19e

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

src/Pluralizer.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
class Pluralizer
88
{
9+
/** @var array */
910
private $irregular = [
1011
'goose' => 'geese',
1112
];
1213

14+
/** @var array */
1315
private $uncountable = [
1416
'audio',
1517
'education',
@@ -18,13 +20,26 @@ class Pluralizer
1820
'mathematics',
1921
];
2022

23+
/** @var Word|null */
2124
private $word;
2225

26+
/**
27+
* Constructor.
28+
*
29+
* @param Word $word
30+
*
31+
* @return void
32+
*/
2333
public function __construct(Word $word)
2434
{
2535
$this->word = $word;
2636
}
2737

38+
/**
39+
* Pluralize the word.
40+
*
41+
* @return Word
42+
*/
2843
public function pluralize()
2944
{
3045
if ($this->isUncountable()) {
@@ -42,6 +57,11 @@ public function pluralize()
4257
return new Word($plural);
4358
}
4459

60+
/**
61+
* Singularize the word.
62+
*
63+
* @return Word
64+
*/
4565
public function singularize()
4666
{
4767
if ($this->isUncountable()) {
@@ -59,6 +79,11 @@ public function singularize()
5979
return new Word($singular);
6080
}
6181

82+
/**
83+
* Check the word is uncountable, meaning there is no spelling difference between the plural and singular versions of the word.
84+
*
85+
* @return bool
86+
*/
6287
private function isUncountable()
6388
{
6489
return in_array($this->word, $this->uncountable);

src/Word.php

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,54 @@
77

88
class Word
99
{
10+
/** @var string|null */
1011
private $word;
12+
13+
/** @var RWFileCache|null */
1114
private $cache;
1215

16+
/**
17+
* Constructor.
18+
*
19+
* @param string $word
20+
*
21+
* @return void
22+
*/
1323
public function __construct(string $word)
1424
{
1525
$this->word = $word;
1626
$this->setupCache();
1727
}
1828

29+
/**
30+
* Convert class instance to string.
31+
*
32+
* @return string
33+
*/
1934
public function __toString()
2035
{
2136
return $this->word;
2237
}
2338

39+
/**
40+
* Set up cache.
41+
*
42+
* @return void
43+
*/
2444
private function setupCache()
2545
{
2646
$this->cache = new RWFileCache();
2747
$this->cache->changeConfig(['cacheDirectory' => '/tmp/php-word-info-cache/']);
2848
}
2949

30-
public function rhymes($halfRhymes = false)
50+
/**
51+
* Add the rhyme in word.
52+
*
53+
* @param bool $halfRhymes
54+
*
55+
* @return mixed
56+
*/
57+
public function rhymes(bool $halfRhymes = false)
3158
{
3259
$cacheKey = $this->word.'.rhymes';
3360

@@ -65,31 +92,61 @@ public function rhymes($halfRhymes = false)
6592
return $rhymes;
6693
}
6794

95+
/**
96+
* Let word be half rhymes.
97+
*
98+
* @return mixed
99+
*/
68100
public function halfRhymes()
69101
{
70102
return $this->rhymes(true);
71103
}
72104

105+
/**
106+
* Syllables word.
107+
*
108+
* @return int
109+
*/
73110
public function syllables()
74111
{
75112
return Syllables::syllableCount($this->word);
76113
}
77114

115+
/**
116+
* Plural word.
117+
*
118+
* @return string
119+
*/
78120
public function plural()
79121
{
80122
return (new Pluralizer($this))->pluralize();
81123
}
82124

125+
/**
126+
* Singular word.
127+
*
128+
* @return string
129+
*/
83130
public function singular()
84131
{
85132
return (new Pluralizer($this))->singularize();
86133
}
87134

135+
/**
136+
* Check the word is offensive.
137+
*
138+
* @return bool
139+
*/
88140
public function offensive()
89141
{
90142
return is_offensive($this->word);
91143
}
92144

145+
/**
146+
* Portmanteaus word.
147+
*
148+
* @return mixed
149+
*/
93150
public function portmanteaus()
94151
{
95152
$cacheKey = $this->word.'.portmanteaus';

0 commit comments

Comments
 (0)