Skip to content

Bump version #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# [2.0.0](https://github.com/phalcongelist/php-diff/releases/tag/v2.0.0) (2016-XX-XX)
# [2.0.0](https://github.com/phalcongelist/php-diff/releases/tag/v2.0.0) (2016-07-17)

* Refactored code in order to follow PSR2 coding standard
* Introduced `Phalcon\Diff\Render\RenderInterface`
* Fixed `Phalcon\Diff::getGroupedOpcodes`. Missing `context` option pass to `SequenceMatcher`
8 changes: 4 additions & 4 deletions src/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace Phalcon;

use Phalcon\Diff\SequenceMatcher;
use Phalcon\Diff\Render\AbstractRender;
use Phalcon\Diff\Render\RenderInterface;

/**
* Diff
Expand Down Expand Up @@ -84,10 +84,10 @@ public function __construct(array $a, array $b, array $options = [])
/**
* Render a diff using the supplied rendering class and return it.
*
* @param AbstractRender $renderer An instance of the rendering object to use for generating the diff.
* @param RenderInterface $renderer An instance of the rendering object to use for generating the diff.
* @return string The generated diff. Exact return value depends on the rendered.
*/
public function render(AbstractRender $renderer)
public function render(RenderInterface $renderer)
{
$renderer->diff = $this;

Expand Down Expand Up @@ -159,7 +159,7 @@ public function getGroupedOpcodes()
}

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

return $this->groupedCodes;
}
Expand Down
15 changes: 5 additions & 10 deletions src/Diff/Renderer/AbstractRender.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@

namespace Phalcon\Diff\Render;

use Phalcon\Diff;

/**
* Abstract class for diff renderers.
*
* @package Phalcon\Diff\Render
*/
abstract class AbstractRender
abstract class AbstractRender implements RenderInterface
{
/**
* Instance of the diff class that this renderer is generating the rendered diff for.
* @var \Phalcon\Diff
* @var Diff
*/
public $diff;

Expand Down Expand Up @@ -56,7 +58,7 @@ public function __construct(array $options = [])

/**
* Set the options of the renderer to those supplied in the passed in array.
* Options are merged with the default to ensure that there aren't any missing
* Options are merged with the default to ensure that there are not any missing
* options.
*
* @param array $options Array of options to set.
Expand All @@ -68,11 +70,4 @@ public function setOptions(array $options)

return $this;
}

/**
* Render and return diff.
*
* @return string.
*/
abstract public function render();
}
6 changes: 3 additions & 3 deletions src/Diff/Renderer/Html/Array.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ private function getChangeExtent($fromLine, $toLine)
private function formatLines($lines)
{
if ($this->options['tabSize'] !== false) {
$lines = array_map(array($this, 'ExpandTabs'), $lines);
$lines = array_map([$this, 'ExpandTabs'], $lines);
}

$lines = array_map([$this, 'HtmlSafe'], $lines);

foreach ($lines as &$line) {
$line = preg_replace_callback('# ( +)|^ #', __CLASS__."::fixSpaces", $line);
$line = preg_replace_callback('# ( +)|^ #', __CLASS__ . "::fixSpaces", $line);
}

return $lines;
Expand All @@ -199,7 +199,7 @@ public static function fixSpaces($matches)
$div = floor($count / 2);
$mod = $count % 2;

return str_repeat('  ', $div).str_repeat(' ', $mod);
return str_repeat('  ', $div) . str_repeat(' ', $mod);
}

/**
Expand Down
32 changes: 32 additions & 0 deletions src/Diff/Renderer/RenderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
+------------------------------------------------------------------------+
| Phalcon Diff |
+------------------------------------------------------------------------+
| Copyright (c) 2009-2016, Chris Boulton <[email protected]> |
| Copyright (c) 2016 Phalcon Team and contributors |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to [email protected] so we can send you a copy immediately. |
+------------------------------------------------------------------------+
*/

namespace Phalcon\Diff\Render;

/**
* Render Interface
*/
interface RenderInterface
{
/**
* Render and return diff.
*
* @return string
*/
public function render();
}