@@ -22,18 +22,21 @@ public function __construct(
22
22
protected ?string $ number = null ,
23
23
protected ?string $ country = null ,
24
24
) {
25
- $ this ->number = format (TaxNumberFormatter::class, $ this ->number , $ this -> country );
25
+ $ this ->number = $ this ->format ( );
26
26
27
- $ this ->when ($ this ->isWithCountry (), function () {
28
- $ this ->country = str ($ this ->number )
29
- ->substr (0 , 2 )
30
- ->upper ()
31
- ->value ();
27
+ if ($ this ->isWithCountry ()) {
28
+ $ this ->split ();
29
+ }
30
+ }
32
31
33
- $ this ->number = str ($ this ->number )
34
- ->substr (2 )
35
- ->value ();
36
- });
32
+ /**
33
+ * Check if the tax number length is less or equal two.
34
+ *
35
+ * @return bool
36
+ */
37
+ public function isWithCountry (): bool
38
+ {
39
+ return strlen ($ this ->number ) >= 2 && ! is_numeric ($ this ->number );
37
40
}
38
41
39
42
/**
@@ -71,23 +74,40 @@ public function country(): string
71
74
}
72
75
73
76
/**
74
- * Check if the tax number length is less or equal two .
77
+ * Get the object value .
75
78
*
76
- * @return bool
79
+ * @return string
77
80
*/
78
- public function isWithCountry (): bool
81
+ public function value (): string
79
82
{
80
- return strlen ( $ this ->number ) >= 2 && ! is_numeric ( $ this -> number );
83
+ return $ this ->fullTaxNumber ( );
81
84
}
82
85
83
86
/**
84
- * Get the object value.
87
+ * Format the value.
85
88
*
86
89
* @return string
87
90
*/
88
- public function value (): string
91
+ protected function format (): string
89
92
{
90
- return $ this ->fullTaxNumber ();
93
+ return format (TaxNumberFormatter::class, $ this ->taxNumber (), $ this ->country ());
94
+ }
95
+
96
+ /**
97
+ * Split the value.
98
+ *
99
+ * @return void
100
+ */
101
+ protected function split (): void
102
+ {
103
+ $ this ->country = str ($ this ->number )
104
+ ->substr (0 , 2 )
105
+ ->upper ()
106
+ ->value ();
107
+
108
+ $ this ->number = str ($ this ->number )
109
+ ->substr (2 )
110
+ ->value ();
91
111
}
92
112
93
113
/**
0 commit comments