Skip to content

Commit

Permalink
Merge pull request #9 from JBlond/development
Browse files Browse the repository at this point in the history
tabs vs space
  • Loading branch information
JBlond authored Jan 19, 2019
2 parents ab6e491 + f326877 commit ea72a0a
Show file tree
Hide file tree
Showing 12 changed files with 1,635 additions and 1,630 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_size = 4
indent_style = space
38 changes: 19 additions & 19 deletions lib/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
class Autoloader
{

/**
* Autoloader constructor.
*/
public function __construct()
{
spl_autoload_register(array($this, '__autoload'));
}
/**
* Autoloader constructor.
*/
public function __construct()
{
spl_autoload_register(array($this, '__autoload'));
}

/**
* @param string $class
*/
private function __autoload($class)
{
$class = str_replace('\\', '/', $class); // revert path for old PHP on Linux
$dir = str_replace('\\', '/', __DIR__);
if (file_exists($dir . '/' . $class . '.php')) {
/** @noinspection PhpIncludeInspection */
require_once $dir . '/' . $class . '.php';
}
}
/**
* @param string $class
*/
private function __autoload($class)
{
$class = str_replace('\\', '/', $class); // revert path for old PHP on Linux
$dir = str_replace('\\', '/', __DIR__);
if (file_exists($dir . '/' . $class . '.php')) {
/** @noinspection PhpIncludeInspection */
require_once $dir . '/' . $class . '.php';
}
}
}
262 changes: 131 additions & 131 deletions lib/jblond/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,135 +49,135 @@
*/
class Diff
{
/**
* @var array The "old" sequence to use as the basis for the comparison.
*/
private $a = null;

/**
* @var array The "new" sequence to generate the changes for.
*/
private $b = null;

/**
* @var array Array containing the generated op codes for the differences between the two items.
*/
private $groupedCodes = null;

/**
* @var array Associative array of the default options available for the diff class and their default value.
*/
private $defaultOptions = array(
'context' => 3,
'ignoreNewLines' => false,
'ignoreWhitespace' => false,
'ignoreCase' => false,
'labelDifferences'=>'Differences'
);

/**
* @var array Array of the options that have been applied for generating the diff.
*/
public $options = array();

/**
* The constructor.
*
* @param array $a Array containing the lines of the first string to compare.
* @param array $b Array containing the lines for the second string to compare.
* @param array $options Array for the options
*/
public function __construct($a, $b, $options = array())
{
$this->a = $a;
$this->b = $b;

if (is_array($options)) {
$this->options = array_merge($this->defaultOptions, $options);
} else {
$this->options = $this->defaultOptions;
}
}


/**
* Render a diff using the supplied rendering class and return it.
*
* @param object $renderer object $renderer An instance of the rendering object to use for generating the diff.
* @return mixed The generated diff. Exact return value depends on the rendered.
*/
public function render($renderer)
{
$renderer->diff = $this;
return $renderer->render();
}

/**
* Get a range of lines from $start to $end from the first comparison string
* and return them as an array. If no values are supplied, the entire string
* is returned. It's also possible to specify just one line to return only
* that line.
*
* @param int $start The starting number.
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
* @return array Array of all of the lines between the specified range.
*/
public function getA($start = 0, $end = null) : array
{
if ($start == 0 && $end === null) {
return $this->a;
}

if ($end === null) {
$length = 1;
} else {
$length = $end - $start;
}

return array_slice($this->a, $start, $length);
}

/**
* Get a range of lines from $start to $end from the second comparison string
* and return them as an array. If no values are supplied, the entire string
* is returned. It's also possible to specify just one line to return only
* that line.
*
* @param int $start The starting number.
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
* @return array Array of all of the lines between the specified range.
*/
public function getB($start = 0, $end = null) : array
{
if ($start == 0 && $end === null) {
return $this->b;
}

if ($end === null) {
$length = 1;
} else {
$length = $end - $start;
}

return array_slice($this->b, $start, $length);
}

/**
* Generate a list of the compiled and grouped op codes for the differences between the
* two strings. Generally called by the renderer, this class instantiates the sequence
* matcher and performs the actual diff generation and return an array of the op codes
* for it. Once generated, the results are cached in the diff class instance.
*
* @return array Array of the grouped op codes for the generated diff.
*/
public function getGroupedOpcodes() : array
{
if (!is_null($this->groupedCodes)) {
return $this->groupedCodes;
}

$sequenceMatcher = new SequenceMatcher($this->a, $this->b, $this->options, null);
$this->groupedCodes = $sequenceMatcher->getGroupedOpcodes($this->options['context']);
return $this->groupedCodes;
}
/**
* @var array The "old" sequence to use as the basis for the comparison.
*/
private $a = null;

/**
* @var array The "new" sequence to generate the changes for.
*/
private $b = null;

/**
* @var array Array containing the generated op codes for the differences between the two items.
*/
private $groupedCodes = null;

/**
* @var array Associative array of the default options available for the diff class and their default value.
*/
private $defaultOptions = array(
'context' => 3,
'ignoreNewLines' => false,
'ignoreWhitespace' => false,
'ignoreCase' => false,
'labelDifferences'=>'Differences'
);

/**
* @var array Array of the options that have been applied for generating the diff.
*/
public $options = array();

/**
* The constructor.
*
* @param array $a Array containing the lines of the first string to compare.
* @param array $b Array containing the lines for the second string to compare.
* @param array $options Array for the options
*/
public function __construct($a, $b, $options = array())
{
$this->a = $a;
$this->b = $b;

if (is_array($options)) {
$this->options = array_merge($this->defaultOptions, $options);
} else {
$this->options = $this->defaultOptions;
}
}


/**
* Render a diff using the supplied rendering class and return it.
*
* @param object $renderer object $renderer An instance of the rendering object to use for generating the diff.
* @return mixed The generated diff. Exact return value depends on the rendered.
*/
public function render($renderer)
{
$renderer->diff = $this;
return $renderer->render();
}

/**
* Get a range of lines from $start to $end from the first comparison string
* and return them as an array. If no values are supplied, the entire string
* is returned. It's also possible to specify just one line to return only
* that line.
*
* @param int $start The starting number.
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
* @return array Array of all of the lines between the specified range.
*/
public function getA($start = 0, $end = null) : array
{
if ($start == 0 && $end === null) {
return $this->a;
}

if ($end === null) {
$length = 1;
} else {
$length = $end - $start;
}

return array_slice($this->a, $start, $length);
}

/**
* Get a range of lines from $start to $end from the second comparison string
* and return them as an array. If no values are supplied, the entire string
* is returned. It's also possible to specify just one line to return only
* that line.
*
* @param int $start The starting number.
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
* @return array Array of all of the lines between the specified range.
*/
public function getB($start = 0, $end = null) : array
{
if ($start == 0 && $end === null) {
return $this->b;
}

if ($end === null) {
$length = 1;
} else {
$length = $end - $start;
}

return array_slice($this->b, $start, $length);
}

/**
* Generate a list of the compiled and grouped op codes for the differences between the
* two strings. Generally called by the renderer, this class instantiates the sequence
* matcher and performs the actual diff generation and return an array of the op codes
* for it. Once generated, the results are cached in the diff class instance.
*
* @return array Array of the grouped op codes for the generated diff.
*/
public function getGroupedOpcodes() : array
{
if (!is_null($this->groupedCodes)) {
return $this->groupedCodes;
}

$sequenceMatcher = new SequenceMatcher($this->a, $this->b, $this->options, null);
$this->groupedCodes = $sequenceMatcher->getGroupedOpcodes($this->options['context']);
return $this->groupedCodes;
}
}
Loading

0 comments on commit ea72a0a

Please sign in to comment.