@@ -59,10 +59,10 @@ public function __construct(string $number, int $checkDigit = null)
59
59
/**
60
60
* Create a new number from an input that contains the check digit already
61
61
* @param string $input The input that contains the check digit already.
62
- * @throws ArgumentIsNotNumericException If the input does not consist entirely of numbers.
63
- * @throws LuhnAlgorithmExceptionInterface
64
62
* @return self
65
63
*
64
+ * @throws LuhnAlgorithmExceptionInterface
65
+ * @throws ArgumentIsNotNumericException If the input does not consist entirely of numbers.
66
66
*/
67
67
public static function fromString (string $ input ): self
68
68
{
@@ -83,12 +83,9 @@ public static function fromString(string $input): self
83
83
return new self ($ number , $ checkDigit );
84
84
}
85
85
86
- /**
87
- * {@inheritdoc}
88
- */
89
- public function getNumber (): string
86
+ public function __toString (): string
90
87
{
91
- return $ this ->number ;
88
+ return $ this ->number . $ this -> checkDigit ;
92
89
}
93
90
94
91
/**
@@ -99,18 +96,31 @@ public function getCheckDigit(): ?int
99
96
return $ this ->checkDigit ;
100
97
}
101
98
102
- public function __toString (): string
99
+ /**
100
+ * {@inheritdoc}
101
+ */
102
+ public function getNumber (): string
103
103
{
104
- return $ this ->number . $ this -> checkDigit ;
104
+ return $ this ->number ;
105
105
}
106
106
107
107
public function serialize (): string
108
108
{
109
- return serialize ([$ this ->number , $ this ->checkDigit ]);
109
+ return serialize ($ this ->__serialize ());
110
+ }
111
+
112
+ public function __serialize (): array
113
+ {
114
+ return [$ this ->number , $ this ->checkDigit ];
115
+ }
116
+
117
+ public function unserialize ($ data ): void
118
+ {
119
+ $ this ->__unserialize (unserialize ($ data ));
110
120
}
111
121
112
- public function unserialize ( $ serialized ): void
122
+ public function __unserialize ( array $ data ): void
113
123
{
114
- [$ this ->number , $ this ->checkDigit ] = unserialize ( $ serialized ) ;
124
+ [$ this ->number , $ this ->checkDigit ] = $ data ;
115
125
}
116
126
}
0 commit comments