value ('' clears). */ public static function compute( $answers ) { $get = function ( $key ) use ( $answers ) { return isset( $answers[ $key ] ) ? $answers[ $key ] : ''; }; $purpose = $get( 'purpose' ); $out = array(); // Refinancing the home you live in: the property is the mailing address. $same = ( 'Home Refinance' === $purpose && 'Primary Residence' === $get( 'property_use' ) ); $out['mailing_same_as_property'] = $purpose ? ( $same ? 'Yes' : 'No' ) : ''; $num = function ( $key ) use ( $get ) { $v = $get( $key ); return ( '' === $v || ! is_numeric( $v ) ) ? null : (float) $v; }; if ( 'Home Purchase' === $purpose && null !== $num( 'purchase_price' ) ) { $out['loan_amount'] = (string) max( 0, (int) ( $num( 'purchase_price' ) - (float) $num( 'down_payment' ) ) ); } elseif ( 'Home Refinance' === $purpose && null !== $num( 'mortgage_balance' ) ) { $out['loan_amount'] = (string) (int) ( $num( 'mortgage_balance' ) + (float) $num( 'additional_funds' ) ); } else { $out['loan_amount'] = ''; } $out['cash_out_box'] = (string) $get( 'additional_funds' ); $loan_type = $get( 'current_loan_type' ); if ( '' !== $loan_type ) { $out['has_FHA'] = 'FHA' === $loan_type ? 'Yes' : ( 'Not sure' === $loan_type ? 'I do not know' : 'No' ); $out['use_va_loans'] = 'VA' === $loan_type ? 'Yes' : 'No'; } $dob = $get( 'dob' ); if ( is_string( $dob ) && preg_match( '/^\d{4}-\d{2}-\d{2}$/', $dob ) ) { $out['age'] = (string) ( new \DateTime( $dob ) )->diff( new \DateTime( 'today' ) )->y; } // 2.6 hidden address fields (the connector maps "state"). $property = $get( 'zip_code' ); if ( is_array( $property ) ) { $out['address'] = $property['street']; $out['city'] = $property['city']; $out['state'] = $property['state']; $out['zip_code_only'] = $property['zip']; } return $out; } }