@@ -48,22 +48,26 @@ abstract class AbstractDocument implements DigitCalculable, Formattable
4848 * @param int $numberOfDigits Max length of checker digits.
4949 * @param string $type Document name/type.
5050 */
51- public function __construct ($ number , $ length , $ numberOfDigits , $ type )
52- {
53- $ this ->type = (string ) $ type ;
54- $ this ->numberOfDigits = (int ) $ numberOfDigits ;
55- $ this ->length = (int ) $ length ;
51+ public function __construct (
52+ string $ number ,
53+ int $ length ,
54+ int $ numberOfDigits ,
55+ string $ type
56+ ) {
57+ $ this ->type = $ type ;
58+ $ this ->numberOfDigits = $ numberOfDigits ;
59+ $ this ->length = $ length ;
5660 $ this ->digit = $ this ->extractCheckerDigit ($ number );
5761 $ this ->assert ($ number );
5862 $ this ->number = $ number ;
5963 }
6064
61- public function __get ($ name )
65+ public function __get (string $ name )
6266 {
6367 return $ this ->$ name ;
6468 }
6569
66- public function __set ($ name , $ value )
70+ public function __set (string $ name , string $ value )
6771 {
6872 throw Exception \Readonly::notAllowed (static ::class, $ name );
6973 }
@@ -75,7 +79,7 @@ public function __set($name, $value)
7579 *
7680 * @return AbstractDocument|boolean Returns a new Document instance or FALSE on failure.
7781 */
78- abstract public static function createFromString ($ number );
82+ abstract public static function createFromString (string $ number );
7983
8084 /**
8185 * Try to create a Document object from given number.
@@ -87,8 +91,13 @@ abstract public static function createFromString($number);
8791 *
8892 * @return AbstractDocument|boolean Returns a new Document instance or FALSE on failure.
8993 */
90- protected static function tryCreateFromString ($ class , $ number , $ length , $ numberOfDigits , $ type )
91- {
94+ protected static function tryCreateFromString (
95+ string $ class ,
96+ string $ number ,
97+ int $ length ,
98+ int $ numberOfDigits ,
99+ string $ type
100+ ) {
92101 try {
93102 return new $ class ($ number , $ length , $ numberOfDigits , $ type );
94103 } catch (Exception \InvalidDocument $ exception ) {
@@ -101,7 +110,7 @@ protected static function tryCreateFromString($class, $number, $length, $numberO
101110 *
102111 * @return string
103112 */
104- public function __toString ()
113+ public function __toString () : string
105114 {
106115 return "{$ this ->number }" ;
107116 }
@@ -114,7 +123,7 @@ public function __toString()
114123 * @throws Exception\InvalidDocument when number is empty
115124 * @throws Exception\InvalidDocument when number is not valid
116125 */
117- protected function assert ($ number )
126+ protected function assert (string $ number )
118127 {
119128 if (empty ($ number )) {
120129 throw Exception \InvalidDocument::notEmpty ($ this ->type );
@@ -131,7 +140,7 @@ protected function assert($number)
131140 *
132141 * @return bool Returns true if it is a valid number, otherwise false.
133142 */
134- protected function isValid ($ number )
143+ protected function isValid (string $ number ) : bool
135144 {
136145 $ baseNumber = $ this ->extractBaseNumber ($ number );
137146
@@ -157,7 +166,7 @@ protected function isValid($number)
157166 *
158167 * @return string Returns only base number without checker digit.
159168 */
160- protected function extractBaseNumber ($ number )
169+ protected function extractBaseNumber (string $ number ) : string
161170 {
162171 return substr ($ number , 0 , -($ this ->numberOfDigits ));
163172 }
@@ -169,7 +178,7 @@ protected function extractBaseNumber($number)
169178 *
170179 * @return string Returns only checker digit.
171180 */
172- protected function extractCheckerDigit ($ number )
181+ protected function extractCheckerDigit (string $ number ) : string
173182 {
174183 return substr ($ number , -($ this ->numberOfDigits ));
175184 }
0 commit comments