@@ -14,59 +14,45 @@ abstract public function getRequiredParams(): array;
1414 /**
1515 * @param GA4Exception $childErrors
1616 */
17- public function toArray (bool $ isParent = false , $ childErrors = null ): array
17+ public function toArray (bool $ isParent = false ): array
1818 {
19- if (!($ childErrors instanceof GA4Exception) && $ childErrors !== null ) {
20- throw new GA4Exception ("$ childErrors is neither NULL of instance of GA4Exception " );
21- }
22-
2319 $ return = [];
24- $ errorStack = null ;
25-
26- if ($ isParent !== null ) {
27- $ errorStack = $ childErrors ;
28- }
2920
3021 $ required = $ this ->getRequiredParams ();
3122 $ params = array_unique (array_merge ($ this ->getParams (), $ required ));
3223
3324 foreach ($ params as $ param ) {
3425 if (!property_exists ($ this , $ param )) {
35- $ errorStack = new GA4Exception ("Param ' {$ param }' is not defined " , $ errorStack );
26+ GA4Exception:: push ("Param ' {$ param }' is not defined " );
3627 continue ;
3728 } elseif (!isset ($ this ->{$ param })) {
3829 if (in_array ($ param , $ required )) {
39- $ errorStack = new GA4Exception ("Param ' {$ param }' is required but not set " , $ errorStack );
30+ GA4Exception:: push ("Param ' {$ param }' is required but not set " );
4031 }
4132 continue ;
4233 } elseif (empty ($ this ->{$ param }) && (is_array ($ this ->{$ param }) || strval ($ this ->{$ param }) !== '0 ' )) {
4334 if (in_array ($ param , $ required )) {
44- $ errorStack = new GA4Exception ("Param ' {$ param }' is required but empty " , $ errorStack );
35+ GA4Exception:: push ("Param ' {$ param }' is required but empty " );
4536 }
4637 continue ;
4738 }
4839
4940 if (strlen ($ param ) > 40 ) {
50- $ errorStack = new GA4Exception ("Param ' {$ param }' is too long, maximum is 40 characters " , $ errorStack );
41+ GA4Exception:: push ("Param ' {$ param }' is too long, maximum is 40 characters " );
5142 }
5243
5344 $ value = $ this ->{$ param };
5445
5546 // Array values be handled and validated within setter, fx addItem/setItem
5647 if (!is_array ($ value ) && mb_strlen ($ value ) > 100 ) {
57- $ errorStack = new GA4Exception ("Value ' {$ value }' is too long, maximum is 100 characters " , $ errorStack );
48+ GA4Exception:: push ("Value ' {$ value }' is too long, maximum is 100 characters " );
5849 }
5950
6051 $ return [$ param ] = $ value ;
6152 }
6253
63- if ($ isParent ) {
64- return [
65- 'data ' => $ return ,
66- 'error ' => $ errorStack
67- ];
68- } elseif ($ errorStack instanceof GA4Exception) {
69- throw $ errorStack ;
54+ if (!$ isParent && GA4Exception::hasStack ()) {
55+ throw GA4Exception::getFinalStack ();
7056 }
7157
7258 return $ return ;
0 commit comments