@@ -24,9 +24,13 @@ abstract class AbstractCsvFileValidator
24
24
/**
25
25
* validate the header row
26
26
*
27
+ * as header rows do not have the same
28
+ * nuance as data rows, decided to cast as
29
+ * final to help ensure consistent return type
30
+ *
27
31
* @param array $headerRow
28
32
*
29
- * @return ValidatorResponse
33
+ * @return ValidatorResponse $response
30
34
*/
31
35
public final function validateHeader (array $ headerRow )
32
36
{
@@ -51,14 +55,46 @@ abstract protected function validateHeaderField($fieldValue);
51
55
52
56
/**
53
57
* validate non-header/data rows
58
+ * Checks for validation on each field, then checks
59
+ * for validation on multiple/joined fields
60
+ *
61
+ * Decided not to cast as final in the event that
62
+ * a validation situation comes up not covered by one
63
+ * of the below called methods
64
+ *
65
+ * As such, any classes extending this method should
66
+ * pay close attention to the method return signature
67
+ * for compatibility purposes
68
+ *
69
+ *
54
70
*
55
71
* @param array $rowData - the array of row data to be checked
56
72
*
57
- * @return ValidatorResponse
73
+ * @return ValidatorResponse $response
58
74
*/
59
75
public function validateDataRow (array $ rowData )
60
76
{
61
77
$ response = new ValidatorResponse ();
78
+
79
+ $ response = $ this ->validateDataRowFields ($ rowData , $ response );
80
+ $ response = $ this ->validateDataRowMultiFields ($ rowData , $ response );
81
+
82
+ return $ response ;
83
+ }
84
+
85
+ /**
86
+ * validates each pair in the provided $rowData
87
+ *
88
+ * @param array $rowData
89
+ * @param ValidatorResponse $response - a preexisting response object to modify, if any
90
+ * @return ValidatorResponse $response
91
+ */
92
+ protected final function validateDataRowFields (array $ rowData , ValidatorResponse $ response = null )
93
+ {
94
+ $ response = $ response
95
+ ? $ response
96
+ : new ValidatorResponse ();
97
+
62
98
foreach ($ rowData as $ dataFieldKey => $ dataFieldValue ) {
63
99
if (!$ this ->validateDataField ($ dataFieldKey , $ dataFieldValue )) {
64
100
$ response ->addErrorForField ($ dataFieldKey , new InvalidDataFieldException ($ dataFieldKey , $ dataFieldValue ));
@@ -68,6 +104,14 @@ public function validateDataRow(array $rowData)
68
104
return $ response ;
69
105
}
70
106
107
+ /**
108
+ * @param array $rowData
109
+ * @param ValidatorResponse $response
110
+ *
111
+ * @return ValidatorResponse $response
112
+ */
113
+ abstract protected function validateDataRowMultiFields (array $ rowData , ValidatorResponse $ response = null );
114
+
71
115
/**
72
116
* validates the given field for expected format
73
117
*
0 commit comments