SimpleDumper::describeDifference PHP Method

describeDifference() public method

Uses a dynamic call.
public describeDifference ( mixed $first, mixed $second, boolean $identical = false ) : string
$first mixed First variable.
$second mixed Value to compare with.
$identical boolean If true then type anomolies count.
return string Description of difference.
    public function describeDifference($first, $second, $identical = false)
    {
        if ($identical) {
            if (!$this->isTypeMatch($first, $second)) {
                return sprintf('with type mismatch as [%s] does not match [%s]', $this->describeValue($first), $this->describeValue($second));
            }
        }
        $type = $this->getType($first);
        if ($type === 'Unknown') {
            return 'with unknown type';
        }
        $method = 'describe' . $type . 'Difference';
        return $this->{$method}($first, $second, $identical);
    }

Usage Example

 /**
  *    Creates a human readable description of the
  *    difference between two variables. Uses a
  *    dynamic call.
  *    @param mixed $first        First variable.
  *    @param mixed $second       Value to compare with.
  *    @param boolean $identical  If true then type anomolies count.
  *    @return string             Description of difference.
  *    @access public
  */
 function describeDifference($first, $second, $identical = false)
 {
     $difference = parent::describeDifference($first, $second, $identical);
     $difference = htmlentities($difference, ENT_COMPAT, 'UTF-8');
     if ($this->getType($first) == 'String') {
         $diff = $this->describeStringDifferenceAsADiff($first, $second, $identical);
         if ($diff) {
             $difference .= PHP_EOL . PHP_EOL;
             $difference .= '<fieldset><legend>Unified diff</legend>';
             $difference .= '<div class="diff">' . $diff . '</div>';
             $difference .= '</fieldset>';
         }
     }
     return $difference;
 }