Skip to content

Development #16

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 3 commits into from
Oct 8, 2019
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
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "7.*",
"phpunit/phpunit": "8.*",
"squizlabs/php_codesniffer": "*"
},
"autoload": {
"psr-4": {
"jblond\\": "lib/jblond"
}
},
"config": {
"classmap-authoritative": true
},
"scripts": {
"phpunit": "phpunit ./tests/",
"php_src": "phpcs --standard=phpcs.xml -s -p --colors ./lib/",
Expand Down
1 change: 1 addition & 0 deletions lib/Autoloader.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace jblond;

/**
Expand Down
12 changes: 7 additions & 5 deletions lib/jblond/Diff.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace jblond;

use jblond\Diff\SequenceMatcher;
Expand All @@ -16,7 +18,7 @@
* @author Chris Boulton <[email protected]>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.12
* @version 1.13
* @link https://github.com/JBlond/php-diff
*/
class Diff
Expand Down Expand Up @@ -44,7 +46,7 @@ class Diff
'ignoreNewLines' => false,
'ignoreWhitespace' => false,
'ignoreCase' => false,
'labelDifferences'=>'Differences'
'labelDifferences' => 'Differences'
);

/**
Expand Down Expand Up @@ -94,7 +96,7 @@ public function render($renderer)
* @param int|null $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 getOld(int $start = 0, $end = null) : array
public function getOld(int $start = 0, $end = null): array
{
if ($start == 0 && $end === null) {
return $this->old;
Expand All @@ -118,7 +120,7 @@ public function getOld(int $start = 0, $end = null) : array
* @param int|null $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 getNew(int $start = 0, $end = null) : array
public function getNew(int $start = 0, $end = null): array
{
if ($start == 0 && $end === null) {
return $this->new;
Expand All @@ -140,7 +142,7 @@ public function getNew(int $start = 0, $end = null) : array
*
* @return array Array of the grouped op codes for the generated diff.
*/
public function getGroupedOpcodes() : array
public function getGroupedOpcodes(): array
{
if (!is_null($this->groupedCodes)) {
return $this->groupedCodes;
Expand Down
22 changes: 12 additions & 10 deletions lib/jblond/Diff/Renderer/Html/HtmlArray.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace jblond\Diff\Renderer\Html;

use jblond\Diff\Renderer\RendererAbstract;
Expand All @@ -13,7 +15,7 @@
* @author Chris Boulton <[email protected]>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.12
* @version 1.13
* @link https://github.com/JBlond/php-diff
*/
class HtmlArray extends RendererAbstract
Expand Down Expand Up @@ -50,7 +52,7 @@ public function renderHtml($changes, $object)
}

foreach ($blocks as $change) {
$html .= '<tbody class="Change'.ucfirst($change['tag']).'">';
$html .= '<tbody class="Change' . ucfirst($change['tag']) . '">';
switch ($change['tag']) {
// Equal changes should be shown on both sides of the diff
case 'equal':
Expand Down Expand Up @@ -125,7 +127,7 @@ public function render()

if ($tag != $lastTag) {
$blocks[] = $this->getDefaultArray($tag, $i1, $j1);
$lastBlock = count($blocks)-1;
$lastBlock = count($blocks) - 1;
}

$lastTag = $tag;
Expand Down Expand Up @@ -190,7 +192,7 @@ private function getChangeExtent(string $fromLine, string $toLine)
* @param array $lines Array of lines to format.
* @return array Array of the formatted lines.
*/
protected function formatLines(array $lines) : array
protected function formatLines(array $lines): array
{
if ($this->options['tabSize'] !== false) {
$lines = array_map(
Expand Down Expand Up @@ -218,7 +220,7 @@ function ($item) {
* @param array $matches The string of spaces.
* @return string The HTML representation of the string.
*/
protected function fixSpaces(array $matches) : string
protected function fixSpaces(array $matches): string
{
$buffer = '';
$count = 0;
Expand All @@ -229,12 +231,12 @@ protected function fixSpaces(array $matches) : string
}
$div = (int) ($count / 2);
$mod = $count % 2;
$buffer .= str_repeat('&#xA0; ', $div).str_repeat('&#xA0;', $mod);
$buffer .= str_repeat('&#xA0; ', $div) . str_repeat('&#xA0;', $mod);
}

$div = (int) ($count / 2);
$mod = $count % 2;
return str_repeat('&#xA0; ', $div).str_repeat('&#xA0;', $mod);
return str_repeat('&#xA0; ', $div) . str_repeat('&#xA0;', $mod);
}

/**
Expand All @@ -243,7 +245,7 @@ protected function fixSpaces(array $matches) : string
* @param string $line The containing tabs to convert.
* @return string The line with the tabs converted to spaces.
*/
private function expandTabs(string $line) : string
private function expandTabs(string $line): string
{
$tabSize = $this->options['tabSize'];
while (($pos = strpos($line, "\t")) !== false) {
Expand All @@ -262,7 +264,7 @@ private function expandTabs(string $line) : string
* @param string $string The string.
* @return string The string with the HTML characters replaced by entities.
*/
private function htmlSafe(string $string) : string
private function htmlSafe(string $string): string
{
return htmlspecialchars($string, ENT_NOQUOTES, 'UTF-8');
}
Expand All @@ -273,7 +275,7 @@ private function htmlSafe(string $string) : string
* @param integer $j1
* @return array
*/
private function getDefaultArray(string $tag, int $i1, int $j1) : array
private function getDefaultArray(string $tag, int $i1, int $j1): array
{
return array
(
Expand Down
40 changes: 21 additions & 19 deletions lib/jblond/Diff/Renderer/Html/Inline.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace jblond\Diff\Renderer\Html;

/**
Expand All @@ -11,7 +13,7 @@
* @author Chris Boulton <[email protected]>
* @copyright (c) 2009 Chris Boulton
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
* @version 1.12
* @version 1.13
* @link https://github.com/JBlond/php-diff
*/
class Inline extends HtmlArray
Expand All @@ -22,7 +24,7 @@ class Inline extends HtmlArray
*
* @return string The generated inline diff.
*/
public function render() : string
public function render(): string
{
$changes = parent::render();
return parent::renderHtml($changes, $this);
Expand All @@ -35,7 +37,7 @@ public function render() : string
*
* @return string Html code representation of the table's header.
*/
public function generateTableHeader() : string
public function generateTableHeader(): string
{
$html = '<table class="Differences DifferencesInline">';
$html .= '<thead>';
Expand All @@ -53,7 +55,7 @@ public function generateTableHeader() : string
*
* @return string Html code representing empty table body.
*/
public function generateSkippedTable() : string
public function generateSkippedTable(): string
{
$html = '<tbody class="Skipped">';
$html .= '<th>&hellip;</th>';
Expand All @@ -69,16 +71,16 @@ public function generateSkippedTable() : string
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of text with no difference.
*/
public function generateTableRowsEqual(array &$change) : string
public function generateTableRowsEqual(array &$change): string
{
$html = "";
foreach ($change['base']['lines'] as $no => $line) {
$fromLine = $change['base']['offset'] + $no + 1;
$toLine = $change['changed']['offset'] + $no + 1;
$html .= '<tr>';
$html .= '<th>'.$fromLine.'</th>';
$html .= '<th>'.$toLine.'</th>';
$html .= '<td class="Left">'.$line.'</td>';
$html .= '<th>' . $fromLine . '</th>';
$html .= '<th>' . $toLine . '</th>';
$html .= '<td class="Left">' . $line . '</td>';
$html .= '</tr>';
}
return $html;
Expand All @@ -90,15 +92,15 @@ public function generateTableRowsEqual(array &$change) : string
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of added text.
*/
public function generateTableRowsInsert(array &$change) : string
public function generateTableRowsInsert(array &$change): string
{
$html = "";
foreach ($change['changed']['lines'] as $no => $line) {
$toLine = $change['changed']['offset'] + $no + 1;
$html .= '<tr>';
$html .= '<th>&#xA0;</th>';
$html .= '<th>'.$toLine.'</th>';
$html .= '<td class="Right"><ins>'.$line.'</ins>&#xA0;</td>';
$html .= '<th>' . $toLine . '</th>';
$html .= '<td class="Right"><ins>' . $line . '</ins>&#xA0;</td>';
$html .= '</tr>';
}
return $html;
Expand All @@ -110,15 +112,15 @@ public function generateTableRowsInsert(array &$change) : string
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of removed text.
*/
public function generateTableRowsDelete(array &$change) : string
public function generateTableRowsDelete(array &$change): string
{
$html = "";
foreach ($change['base']['lines'] as $no => $line) {
$fromLine = $change['base']['offset'] + $no + 1;
$html .= '<tr>';
$html .= '<th>'.$fromLine.'</th>';
$html .= '<th>' . $fromLine . '</th>';
$html .= '<th>&#xA0;</th>';
$html .= '<td class="Left"><del>'.$line.'</del>&#xA0;</td>';
$html .= '<td class="Left"><del>' . $line . '</del>&#xA0;</td>';
$html .= '</tr>';
}
return $html;
Expand All @@ -130,25 +132,25 @@ public function generateTableRowsDelete(array &$change) : string
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of modified.
*/
public function generateTableRowsReplace(array &$change) : string
public function generateTableRowsReplace(array &$change): string
{
$html = "";

foreach ($change['base']['lines'] as $no => $line) {
$fromLine = $change['base']['offset'] + $no + 1;
$html .= '<tr>';
$html .= '<th>'.$fromLine.'</th>';
$html .= '<th>' . $fromLine . '</th>';
$html .= '<th>&#xA0;</th>';
$html .= '<td class="Left"><span>'.$line.'</span></td>';
$html .= '<td class="Left"><span>' . $line . '</span></td>';
$html .= '</tr>';
}

foreach ($change['changed']['lines'] as $no => $line) {
$toLine = $change['changed']['offset'] + $no + 1;
$html .= '<tr>';
$html .= '<th>&#xA0;</th>';
$html .= '<th>'.$toLine.'</th>';
$html .= '<td class="Right"><span>'.$line.'</span></td>';
$html .= '<th>' . $toLine . '</th>';
$html .= '<td class="Right"><span>' . $line . '</span></td>';
$html .= '</tr>';
}

Expand Down
Loading