Skip to content

Commit 5e793c1

Browse files
authored
Merge pull request #2 from phalcongelist/2.0.x
Bump version
2 parents dca2daf + 8ce0ac1 commit 5e793c1

File tree

5 files changed

+47
-18
lines changed

5 files changed

+47
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
# [2.0.0](https://github.com/phalcongelist/php-diff/releases/tag/v2.0.0) (2016-XX-XX)
1+
# [2.0.0](https://github.com/phalcongelist/php-diff/releases/tag/v2.0.0) (2016-07-17)
22

33
* Refactored code in order to follow PSR2 coding standard
4+
* Introduced `Phalcon\Diff\Render\RenderInterface`
5+
* Fixed `Phalcon\Diff::getGroupedOpcodes`. Missing `context` option pass to `SequenceMatcher`

src/Diff.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
namespace Phalcon;
2020

2121
use Phalcon\Diff\SequenceMatcher;
22-
use Phalcon\Diff\Render\AbstractRender;
22+
use Phalcon\Diff\Render\RenderInterface;
2323

2424
/**
2525
* Diff
@@ -84,10 +84,10 @@ public function __construct(array $a, array $b, array $options = [])
8484
/**
8585
* Render a diff using the supplied rendering class and return it.
8686
*
87-
* @param AbstractRender $renderer An instance of the rendering object to use for generating the diff.
87+
* @param RenderInterface $renderer An instance of the rendering object to use for generating the diff.
8888
* @return string The generated diff. Exact return value depends on the rendered.
8989
*/
90-
public function render(AbstractRender $renderer)
90+
public function render(RenderInterface $renderer)
9191
{
9292
$renderer->diff = $this;
9393

@@ -159,7 +159,7 @@ public function getGroupedOpcodes()
159159
}
160160

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

164164
return $this->groupedCodes;
165165
}

src/Diff/Renderer/AbstractRender.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@
1818

1919
namespace Phalcon\Diff\Render;
2020

21+
use Phalcon\Diff;
22+
2123
/**
2224
* Abstract class for diff renderers.
2325
*
2426
* @package Phalcon\Diff\Render
2527
*/
26-
abstract class AbstractRender
28+
abstract class AbstractRender implements RenderInterface
2729
{
2830
/**
2931
* Instance of the diff class that this renderer is generating the rendered diff for.
30-
* @var \Phalcon\Diff
32+
* @var Diff
3133
*/
3234
public $diff;
3335

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

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

6971
return $this;
7072
}
71-
72-
/**
73-
* Render and return diff.
74-
*
75-
* @return string.
76-
*/
77-
abstract public function render();
7873
}

src/Diff/Renderer/Html/Array.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ private function getChangeExtent($fromLine, $toLine)
169169
private function formatLines($lines)
170170
{
171171
if ($this->options['tabSize'] !== false) {
172-
$lines = array_map(array($this, 'ExpandTabs'), $lines);
172+
$lines = array_map([$this, 'ExpandTabs'], $lines);
173173
}
174174

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

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

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

202-
return str_repeat('  ', $div).str_repeat(' ', $mod);
202+
return str_repeat('  ', $div) . str_repeat(' ', $mod);
203203
}
204204

205205
/**

src/Diff/Renderer/RenderInterface.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
+------------------------------------------------------------------------+
5+
| Phalcon Diff |
6+
+------------------------------------------------------------------------+
7+
| Copyright (c) 2009-2016, Chris Boulton <[email protected]> |
8+
| Copyright (c) 2016 Phalcon Team and contributors |
9+
+------------------------------------------------------------------------+
10+
| This source file is subject to the New BSD License that is bundled |
11+
| with this package in the file docs/LICENSE.txt. |
12+
| |
13+
| If you did not receive a copy of the license and are unable to |
14+
| obtain it through the world-wide-web, please send an email |
15+
| to [email protected] so we can send you a copy immediately. |
16+
+------------------------------------------------------------------------+
17+
*/
18+
19+
namespace Phalcon\Diff\Render;
20+
21+
/**
22+
* Render Interface
23+
*/
24+
interface RenderInterface
25+
{
26+
/**
27+
* Render and return diff.
28+
*
29+
* @return string
30+
*/
31+
public function render();
32+
}

0 commit comments

Comments
 (0)