@@ -44,7 +44,7 @@ public function getNumber(): string
4444 }
4545
4646 /** @inheritDoc */
47- public function setNumber (string $ number ): CardDetails
47+ public function setNumber (string $ number ): self
4848 {
4949 $ this ->number = $ number ;
5050 return $ this ;
@@ -57,7 +57,7 @@ public function getExpiryMonth(): int
5757 }
5858
5959 /** @inheritDoc */
60- public function setExpiryMonth (int $ expiryMonth ): CardDetails
60+ public function setExpiryMonth (int $ expiryMonth ): self
6161 {
6262 $ this ->expiryMonth = $ expiryMonth ;
6363 return $ this ;
@@ -70,8 +70,12 @@ public function getYear(): int
7070 }
7171
7272 /** @inheritDoc */
73- public function setYear (int $ year ): CardDetails
73+ public function setYear (int $ year ): self
7474 {
75+ if ( $ year < 1900 ) {
76+ throw new PaymentException ('Проверьте год выпуска карты ' );
77+ }
78+
7579 $ this ->year = $ year ;
7680 return $ this ;
7781 }
@@ -83,7 +87,7 @@ public function getExpiryYear(): int
8387 }
8488
8589 /** @inheritDoc */
86- public function setExpiryYear (int $ expiryYear ): CardDetails
90+ public function setExpiryYear (int $ expiryYear ): self
8791 {
8892 $ this ->expiryYear = $ expiryYear ;
8993 return $ this ;
@@ -96,7 +100,7 @@ public function getCvv(): int
96100 }
97101
98102 /** @inheritDoc */
99- public function setCvv (int $ cvv ): CardDetails
103+ public function setCvv (int $ cvv ): self
100104 {
101105 $ this ->cvv = $ cvv ;
102106 return $ this ;
@@ -109,7 +113,7 @@ public function getOwner(): string
109113 }
110114
111115 /** @inheritDoc */
112- public function setOwner (string $ owner ): CardDetails
116+ public function setOwner (string $ owner ): self
113117 {
114118 $ this ->owner = $ owner ;
115119 return $ this ;
@@ -122,7 +126,7 @@ public function getTimeSpentTypingNumber(): int
122126 }
123127
124128 /** @inheritDoc */
125- public function setTimeSpentTypingNumber (int $ timeSpentTypingNumber ): CardDetails
129+ public function setTimeSpentTypingNumber (int $ timeSpentTypingNumber ): self
126130 {
127131 $ this ->timeSpentTypingNumber = $ timeSpentTypingNumber ;
128132 return $ this ;
@@ -135,7 +139,7 @@ public function getTimeSpentTypingOwner(): int
135139 }
136140
137141 /** @inheritDoc */
138- public function setTimeSpentTypingOwner (int $ timeSpentTypingOwner ): CardDetails
142+ public function setTimeSpentTypingOwner (int $ timeSpentTypingOwner ): self
139143 {
140144 $ this ->timeSpentTypingOwner = $ timeSpentTypingOwner ;
141145 return $ this ;
@@ -148,7 +152,7 @@ public function getBin(): int
148152 }
149153
150154 /** @inheritDoc */
151- public function setBin (int $ bin ): CardDetails
155+ public function setBin (int $ bin ): self
152156 {
153157 $ this ->bin = $ bin ;
154158 return $ this ;
@@ -161,7 +165,7 @@ public function getPan(): string
161165 }
162166
163167 /** @inheritDoc */
164- public function setPan (string $ pan ): CardDetails
168+ public function setPan (string $ pan ): self
165169 {
166170 $ this ->pan = $ pan ;
167171 return $ this ;
@@ -174,7 +178,7 @@ public function getType(): string
174178 }
175179
176180 /** @inheritDoc */
177- public function setType (string $ type ): CardDetails
181+ public function setType (string $ type ): self
178182 {
179183 $ this ->type = $ type ;
180184 return $ this ;
@@ -187,9 +191,34 @@ public function getCardIssuerBank(): string
187191 }
188192
189193 /** @inheritDoc */
190- public function setCardIssuerBank (string $ cardIssuerBank ): CardDetails
194+ public function setCardIssuerBank (string $ cardIssuerBank ): self
191195 {
192196 $ this ->cardIssuerBank = $ cardIssuerBank ;
193197 return $ this ;
194198 }
195- }
199+
200+ /** @inheritDoc */
201+ public function toArray () : array
202+ {
203+ $ resultArray = get_object_vars ($ this );
204+
205+ foreach ($ resultArray as &$ value ) {
206+ if (is_object ($ value ) && method_exists ($ value , 'toArray ' )) {
207+
208+ $ value = $ value ->toArray ();
209+
210+ } else {
211+ if (is_array ($ value )) {
212+ foreach ($ value as &$ arrayValue ) {
213+ if (is_object ($ arrayValue ) && method_exists ($ arrayValue , 'toArray ' )) {
214+
215+ $ arrayValue = $ arrayValue ->toArray ();
216+ }
217+ }
218+ }
219+ }
220+ }
221+
222+ return $ resultArray ;
223+ }
224+ }
0 commit comments