From 3396d355780cb6dec0dd85d7eccc9933c15e3f40 Mon Sep 17 00:00:00 2001 From: JBlond Date: Fri, 22 Feb 2019 16:08:38 +0100 Subject: [PATCH 1/9] update Readme with example code --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index dd7464f4..2091f782 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,36 @@ composer require jblond/php-diff ## Example Use +```PHP + true, + //'ignoreCase' => true, +); +// Initialize the diff class +$diff = new \jblond\Diff($a, $b, $options); + +//choose renderer +$renderer = new \jblond\Diff\Renderer\Html\SideBySide(array( + 'title_a' => 'Custom title for OLD version', + 'title_b' => 'Custom title for NEW version', +)); + +//show it +echo $diff->Render($renderer); +``` + +### Example Output A quick usage example can be found in the example/ directory and under example.php. From f755fce7c10923a75d7d77785e381353339b3563 Mon Sep 17 00:00:00 2001 From: JBlond Date: Fri, 22 Feb 2019 16:12:00 +0100 Subject: [PATCH 2/9] increase version number --- lib/jblond/Diff.php | 2 +- lib/jblond/Diff/Renderer/Html/HtmlArray.php | 2 +- lib/jblond/Diff/Renderer/Html/Inline.php | 2 +- lib/jblond/Diff/Renderer/Html/SideBySide.php | 2 +- lib/jblond/Diff/Renderer/RendererAbstract.php | 2 +- lib/jblond/Diff/Renderer/Text/Context.php | 2 +- lib/jblond/Diff/Renderer/Text/Unified.php | 2 +- lib/jblond/Diff/SequenceMatcher.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/jblond/Diff.php b/lib/jblond/Diff.php index c8c973e5..48c50cff 100644 --- a/lib/jblond/Diff.php +++ b/lib/jblond/Diff.php @@ -16,7 +16,7 @@ * @author Chris Boulton * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.11 + * @version 1.12 * @link https://github.com/JBlond/php-diff */ class Diff diff --git a/lib/jblond/Diff/Renderer/Html/HtmlArray.php b/lib/jblond/Diff/Renderer/Html/HtmlArray.php index 8d80b3a3..696982d3 100644 --- a/lib/jblond/Diff/Renderer/Html/HtmlArray.php +++ b/lib/jblond/Diff/Renderer/Html/HtmlArray.php @@ -13,7 +13,7 @@ * @author Chris Boulton * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.11 + * @version 1.12 * @link https://github.com/JBlond/php-diff */ class HtmlArray extends RendererAbstract diff --git a/lib/jblond/Diff/Renderer/Html/Inline.php b/lib/jblond/Diff/Renderer/Html/Inline.php index 8df07eda..a8cffc50 100644 --- a/lib/jblond/Diff/Renderer/Html/Inline.php +++ b/lib/jblond/Diff/Renderer/Html/Inline.php @@ -11,7 +11,7 @@ * @author Chris Boulton * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.11 + * @version 1.12 * @link https://github.com/JBlond/php-diff */ class Inline extends HtmlArray diff --git a/lib/jblond/Diff/Renderer/Html/SideBySide.php b/lib/jblond/Diff/Renderer/Html/SideBySide.php index a801d772..44c2144d 100644 --- a/lib/jblond/Diff/Renderer/Html/SideBySide.php +++ b/lib/jblond/Diff/Renderer/Html/SideBySide.php @@ -11,7 +11,7 @@ * @author Chris Boulton * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.11 + * @version 1.12 * @link https://github.com/JBlond/php-diff */ class SideBySide extends HtmlArray diff --git a/lib/jblond/Diff/Renderer/RendererAbstract.php b/lib/jblond/Diff/Renderer/RendererAbstract.php index 0a3599ad..f3a0afc6 100644 --- a/lib/jblond/Diff/Renderer/RendererAbstract.php +++ b/lib/jblond/Diff/Renderer/RendererAbstract.php @@ -13,7 +13,7 @@ * @author Chris Boulton * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.11 + * @version 1.12 * @link https://github.com/JBlond/php-diff */ abstract class RendererAbstract diff --git a/lib/jblond/Diff/Renderer/Text/Context.php b/lib/jblond/Diff/Renderer/Text/Context.php index 8dbaa035..42d0b0a9 100644 --- a/lib/jblond/Diff/Renderer/Text/Context.php +++ b/lib/jblond/Diff/Renderer/Text/Context.php @@ -13,7 +13,7 @@ * @author Chris Boulton * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.11 + * @version 1.12 * @link https://github.com/JBlond/php-diff */ class Context extends RendererAbstract diff --git a/lib/jblond/Diff/Renderer/Text/Unified.php b/lib/jblond/Diff/Renderer/Text/Unified.php index 8848d322..33088c9e 100644 --- a/lib/jblond/Diff/Renderer/Text/Unified.php +++ b/lib/jblond/Diff/Renderer/Text/Unified.php @@ -13,7 +13,7 @@ * @author Chris Boulton * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.11 + * @version 1.12 * @link https://github.com/JBlond/php-diff */ diff --git a/lib/jblond/Diff/SequenceMatcher.php b/lib/jblond/Diff/SequenceMatcher.php index 93b376c6..7c61b0e2 100644 --- a/lib/jblond/Diff/SequenceMatcher.php +++ b/lib/jblond/Diff/SequenceMatcher.php @@ -11,7 +11,7 @@ * @author Chris Boulton * @copyright (c) 2009 Chris Boulton * @license New BSD License http://www.opensource.org/licenses/bsd-license.php - * @version 1.11 + * @version 1.12 * @link https://github.com/JBlond/php-diff */ class SequenceMatcher From 1dd40d8f83543a82df00598310761cbb0e121590 Mon Sep 17 00:00:00 2001 From: JBlond Date: Fri, 1 Mar 2019 14:32:53 +0100 Subject: [PATCH 3/9] remove BOM --- example/example.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/example.php b/example/example.php index 901091a6..2777827b 100644 --- a/example/example.php +++ b/example/example.php @@ -1,4 +1,4 @@ - + From 745b3317bcf208722bc8e0b201ef8ae69fa1c43a Mon Sep 17 00:00:00 2001 From: JBlond Date: Fri, 1 Mar 2019 14:33:29 +0100 Subject: [PATCH 4/9] tabs vs space --- example/example.php | 98 ++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/example/example.php b/example/example.php index 2777827b..6a6b516a 100644 --- a/example/example.php +++ b/example/example.php @@ -1,67 +1,67 @@ - - - PHP LibDiff - Examples - - - -

PHP LibDiff - Examples

-
- + + PHP LibDiff - Examples + + + +

PHP LibDiff - Examples

+
+ true, - //'ignoreCase' => true, - ); + // Options for generating the diff + $options = array( + //'ignoreWhitespace' => true, + //'ignoreCase' => true, + ); - // Initialize the diff class - $diff = new \jblond\Diff($a, $b, $options); + // Initialize the diff class + $diff = new \jblond\Diff($a, $b, $options); - ?> -

Side by Side Diff

- +

Side by Side Diff

+ 'Custom title for OLD version', 'title_b' => 'Custom title for NEW version', )); - echo $diff->Render($renderer); + echo $diff->Render($renderer); - ?> -

Inline Diff

- +

Inline Diff

+ render($renderer); + // Generate an inline diff + $renderer = new \jblond\Diff\Renderer\Html\Inline; + echo $diff->render($renderer); - ?> -

Unified Diff

-

+        

Unified Diff

+
render($renderer));
+        // Generate a unified diff
+        $renderer = new \jblond\Diff\Renderer\Text\Unified();
+        echo htmlspecialchars($diff->render($renderer));
 
-		?>
-		
-

Context Diff

-

+        
+

Context Diff

+
render($renderer));
-		?>
-		
- + // Generate a context diff + $renderer = new \jblond\Diff\Renderer\Text\Context; + echo htmlspecialchars($diff->render($renderer)); + ?> +
+ From e0f68420b12d6f7278163cc780aaff05eee9a4b8 Mon Sep 17 00:00:00 2001 From: JBlond Date: Fri, 1 Mar 2019 14:38:18 +0100 Subject: [PATCH 5/9] PHP Mess Detector Avoid unused private methods such as '__autoload'. even if not correct --- lib/Autoloader.php | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/Autoloader.php b/lib/Autoloader.php index 1cc14011..1341b1d6 100644 --- a/lib/Autoloader.php +++ b/lib/Autoloader.php @@ -13,19 +13,13 @@ class Autoloader */ 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'; - } + spl_autoload_register(function ($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'; + } + }); } } From 27b21ebe4f5d37ce853053325163a0965e7c9b87 Mon Sep 17 00:00:00 2001 From: JBlond Date: Mon, 18 Mar 2019 20:30:29 +0100 Subject: [PATCH 6/9] add more files to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 61ead866..77aae3df 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +/.idea +/composer.lock /vendor From 6d165a674b437ad4fa26cd8587c70e3b646862fd Mon Sep 17 00:00:00 2001 From: JBlond Date: Mon, 18 Mar 2019 20:42:35 +0100 Subject: [PATCH 7/9] add tests --- README.md | 7 +++++++ composer.json | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2091f782..9fb9e4c0 100644 --- a/README.md +++ b/README.md @@ -90,3 +90,10 @@ Contributors since I forked the repo. ### License (BSD License) see [License](LICENSE) + +## tests + +```BASH +composer run-script php_src +composer run-script php_test +``` diff --git a/composer.json b/composer.json index a571509f..aa27d1a6 100644 --- a/composer.json +++ b/composer.json @@ -22,11 +22,16 @@ "ext-mbstring": "*" }, "require-dev": { - "phpunit/phpunit": "7.*" + "phpunit/phpunit": "7.*", + "squizlabs/php_codesniffer": "*" }, "autoload": { "psr-4": { "jblond\\": "lib/jblond" } + }, + "scripts": { + "php_src": "phpcs --standard=phpcs.xml -s -p --colors ./lib/", + "php_test": "phpcs --standard=phpcs.xml -s -p --colors ./tests/" } } From e8a3f7194ab2685cbbb1ce80ff4453f4cd1135f5 Mon Sep 17 00:00:00 2001 From: JBlond Date: Mon, 18 Mar 2019 20:46:08 +0100 Subject: [PATCH 8/9] add phpunit test to composer --- README.md | 1 + composer.json | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index 9fb9e4c0..88bfd1d8 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,7 @@ see [License](LICENSE) ## tests ```BASH +composer run-script phpunit composer run-script php_src composer run-script php_test ``` diff --git a/composer.json b/composer.json index aa27d1a6..c3ab7814 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ } }, "scripts": { + "phpunit": "phpunit ./tests/", "php_src": "phpcs --standard=phpcs.xml -s -p --colors ./lib/", "php_test": "phpcs --standard=phpcs.xml -s -p --colors ./tests/" } From 2f11a9df1646818e8a90f94f58b52a1876f9e7c3 Mon Sep 17 00:00:00 2001 From: JBlond Date: Mon, 18 Mar 2019 20:51:08 +0100 Subject: [PATCH 9/9] remove files from .gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 77aae3df..61ead866 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -/.idea -/composer.lock /vendor