Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Diff_Result Class Reference

Wrapper for result of simplediff. More...

List of all members.

Public Member Functions

 __construct (array $result, P4Cms_Diff_Options $options)
 Create a new diff result from simplediff output.
 getChunks ()
 Get all value chunks.
 getDiffChunks ()
 Get only diff chunks (blocks of values where left and right differ).
 getDiffCount ()
 Count all differences.
 getOption ($name)
 Get a specific option from the original options.
 getOptions ()
 Get the original options that produced this result (ie.
 getRawResult ()
 Access to raw simplediff result array.
 hasDiffs ()
 Check if there are differences.
 isWhitespaceChange ($semantic=true)
 Check if the only changes are whitespace changes.

Protected Attributes

 $_options = null
 $_result = null

Detailed Description

Wrapper for result of simplediff.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Constructor & Destructor Documentation

P4Cms_Diff_Result::__construct ( array $  result,
P4Cms_Diff_Options options 
)

Create a new diff result from simplediff output.

Parameters:
array$resultoutput from simplediff.
P4Cms_Diff_Options$optionsoriginal options given to compare.
    {
        $this->_result  = $result;
        $this->_options = $options;
    }

Member Function Documentation

P4Cms_Diff_Result::getChunks ( )

Get all value chunks.

Includes values that are the same between left and right as well those that differ.

Returns:
array list of value chunks (P4Cms_Diff_Chunk instances)
    {
        // convert raw result into chunks.
        $chunks = array();
        foreach ($this->getRawResult() as $rawChunk) {

            // accumulate consecutive unchanged values in a single chunk.
            $chunk = end($chunks);
            if ($chunk && $chunk->isSame() && is_string($rawChunk)) {
                $values   = $chunk->getRawValues();
                $values[] = $rawChunk;
                $chunk->setRawValues($values);
            } else {
                $chunks[] = new P4Cms_Diff_Chunk((array) $rawChunk);
            }

        }

        return $chunks;
    }
P4Cms_Diff_Result::getDiffChunks ( )

Get only diff chunks (blocks of values where left and right differ).

Returns:
array list of differing value chunks
    {
        return array_filter(
            $this->getChunks(),
            function($chunk)
            {
                return !$chunk->isSame();
            }
        );
    }
P4Cms_Diff_Result::getDiffCount ( )

Count all differences.

Returns:
int the count of all differences
    {
        return count(array_filter($this->getRawResult(), 'is_array'));
    }
P4Cms_Diff_Result::getOption ( name)

Get a specific option from the original options.

Parameters:
string$namethe name of the option to get.
Returns:
mixed the value of the option
    {
        return $this->getOptions()->getOption($name);
    }
P4Cms_Diff_Result::getOptions ( )

Get the original options that produced this result (ie.

the options passed to the compare method).

Returns:
P4Cms_Diff_Options the original options.
    {
        return $this->_options;
    }
P4Cms_Diff_Result::getRawResult ( )

Access to raw simplediff result array.

    {
        if (!is_array($this->_result)) {
            throw new P4Cms_Diff_Exception(
                "Cannot get results. Results have not been set."
            );
        }

        return $this->_result;
    }
P4Cms_Diff_Result::hasDiffs ( )

Check if there are differences.

Returns:
bool true if there are diffs.
    {
        return (bool) $this->getDiffCount();
    }
P4Cms_Diff_Result::isWhitespaceChange ( semantic = true)

Check if the only changes are whitespace changes.

Parameters:
bool$semanticoptional - defaults to true - consider semantic changes (e.g. splitting one word or joining two) a non-whitespace change.
    {
        // if no diffs, can't be whitespace change.
        if (!$this->hasDiffs()) {
            return false;
        }

        // check each diff chunk.
        foreach ($this->getDiffChunks() as $chunk) {
            if (!$chunk->isWhitespaceChange($semantic)) {
                return false;
            }
        }

        // all diff chunks are whitespace changes.
        return true;
    }

Member Data Documentation

P4Cms_Diff_Result::$_options = null [protected]
P4Cms_Diff_Result::$_result = null [protected]

The documentation for this class was generated from the following file: