@@ -25,6 +25,13 @@ class NumberToWords {
2525 */
2626 static private $ currencyData ;
2727
28+ /**
29+ * Formatted text data
30+ *
31+ * @var mixed
32+ */
33+ static private $ text ;
34+
2835 /**
2936 * Allow Cents
3037 * @param bool|null $cents
@@ -34,11 +41,11 @@ class NumberToWords {
3441 */
3542 static public function cents ($ cents = null )
3643 {
37- $ self = clone new self ();
44+ $ clone = self :: clone ();
3845
3946 self ::$ allowCents = $ cents ;
4047
41- return $ self ;
48+ return $ clone ;
4249 }
4350
4451 /**
@@ -51,11 +58,11 @@ static public function cents($cents = null)
5158 */
5259 static public function iso ($ code = null )
5360 {
54- $ self = clone new self ();
61+ $ clone = self :: clone ();
5562
5663 self ::$ currencyData = self ::getCurrencyText ($ code );
5764
58- return $ self ;
65+ return $ clone ;
5966 }
6067
6168 /**
@@ -67,10 +74,12 @@ static public function iso($code = null)
6774 * @param bool|null $cents
6875 * - [optional] Default is false
6976 *
70- * @return string
77+ * @return $this
7178 */
72- static public function text ($ number , $ cents = null )
79+ static public function number ($ number , $ cents = null )
7380 {
81+ $ clone = self ::clone ();
82+
7483 if (is_null (self ::$ allowCents ) && is_bool ($ cents )){
7584 self ::$ allowCents = $ cents ;
7685 }
@@ -79,7 +88,7 @@ static public function text($number, $cents = null)
7988 $ number = Str::trim ($ number );
8089
8190 // if cents is allowed
82- if (self ::$ allowCents ){
91+ if (self ::$ allowCents ){
8392
8493 // get name of currency
8594 $ currencyText = self ::$ currencyData ['name ' ] ?? null ;
@@ -98,7 +107,20 @@ static public function text($number, $cents = null)
98107 Str::replace (["\n" , "\r" ], '' , $ numberText )
99108 );
100109
101- return ucfirst ($ numberText ) . $ currencyText . self ::toCents ($ number );
110+ // add to text
111+ self ::$ text = ucfirst ($ numberText ) . $ currencyText . self ::toCents ($ number );
112+
113+ return $ clone ;
114+ }
115+
116+ /**
117+ * Translate text into readable formats
118+ *
119+ * @return string|null
120+ */
121+ static public function translate ()
122+ {
123+ return self ::$ text ;
102124 }
103125
104126 /**
@@ -233,4 +255,14 @@ static public function getCurrencyText($code = null)
233255 return Str::convertArrayCase ($ data , 'lower ' , 'lower ' );
234256 }
235257
258+ /**
259+ * Clone self
260+ *
261+ * @return $this
262+ */
263+ static private function clone ()
264+ {
265+ return clone new self ();
266+ }
267+
236268}
0 commit comments