Set state in all paths through findContact() and return immediately in all cases
Created by: kenwest
When I press Re-check and there is a row in the CSV which matches 2 or more contacts on email address, a fatal error is raised saying " is not of type String".
Looking at the code it turns out that $record['state'] is not being set in this case. I've made 3 changes related to this ...
-
Reviewing the code of findContact(), it appears the pattern is that once a decision has been made, $record['state'] and $record['contact_id'] are set and we return. I added that logic in this case and the fatal error goes away.
-
Reviewing the code of findContact(), it appears the pattern found at point 1 is not followed in the case when more that 10 matching contacts are found. I adding a return statement, so this case doesn't fall through and revert to the 'impossible' case.
-
After matching on email address, the code looks at first name and then last name in an attempt to get a single item, which is then considered as the 'found' record. However the callback used will only ever return an empty result.
Caveat: when I load the CSV file the row for "email address matches multiple contacts" is grey and in the database its state is '' (the empty string). With my change I preserve this behaviour. @artfulrobot you may want to change '' to 'multiple' to match the other cases in findContact().