Skip to content

Commit c53c230

Browse files
committed
use strict types
1 parent 0c3fd1a commit c53c230

File tree

9 files changed

+42
-31
lines changed

9 files changed

+42
-31
lines changed

lib/jblond/Diff.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
namespace jblond;
34

45
use jblond\Diff\SequenceMatcher;
@@ -121,7 +122,7 @@ public function render($renderer)
121122
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
122123
* @return array Array of all of the lines between the specified range.
123124
*/
124-
public function getA($start = 0, $end = null)
125+
public function getA($start = 0, $end = null) : array
125126
{
126127
if ($start == 0 && $end === null) {
127128
return $this->a;
@@ -146,7 +147,7 @@ public function getA($start = 0, $end = null)
146147
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
147148
* @return array Array of all of the lines between the specified range.
148149
*/
149-
public function getB($start = 0, $end = null)
150+
public function getB($start = 0, $end = null) : array
150151
{
151152
if ($start == 0 && $end === null) {
152153
return $this->b;
@@ -169,7 +170,7 @@ public function getB($start = 0, $end = null)
169170
*
170171
* @return array Array of the grouped op codes for the generated diff.
171172
*/
172-
public function getGroupedOpcodes()
173+
public function getGroupedOpcodes() : array
173174
{
174175
if (!is_null($this->groupedCodes)) {
175176
return $this->groupedCodes;

lib/jblond/Diff/Renderer/Html/HtmlArray.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
namespace jblond\Diff\Renderer\Html;
34

45
use jblond\Diff\Renderer\RendererAbstract;
@@ -254,12 +255,12 @@ protected function fixSpaces($matches)
254255
if ($count == 0) {
255256
continue;
256257
}
257-
$div = ($count / 2);
258+
$div = (int) ($count / 2);
258259
$mod = $count % 2;
259260
$buffer .= str_repeat('&#xA0; ', $div).str_repeat('&#xA0;', $mod);
260261
}
261262

262-
$div = ($count / 2);
263+
$div = (int) ($count / 2);
263264
$mod = $count % 2;
264265
return str_repeat('&#xA0; ', $div).str_repeat('&#xA0;', $mod);
265266
}

lib/jblond/Diff/Renderer/Html/Inline.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
namespace jblond\Diff\Renderer\Html;
34

45
/**
@@ -53,7 +54,7 @@ class Inline extends HtmlArray
5354
*
5455
* @return string The generated inline diff.
5556
*/
56-
public function render()
57+
public function render() : string
5758
{
5859
$changes = parent::render();
5960
$html = '';
@@ -105,7 +106,7 @@ public function render()
105106
*
106107
* @return string Html code representation of the table's header.
107108
*/
108-
private function generateTableHeader()
109+
private function generateTableHeader() : string
109110
{
110111
$html = '<table class="Differences DifferencesInline">';
111112
$html .= '<thead>';
@@ -123,7 +124,7 @@ private function generateTableHeader()
123124
*
124125
* @return string Html code representing empty table body.
125126
*/
126-
private function generateSkippedTable()
127+
private function generateSkippedTable() : string
127128
{
128129
$html = '<tbody class="Skipped">';
129130
$html .= '<th>&hellip;</th>';
@@ -139,7 +140,7 @@ private function generateSkippedTable()
139140
* @param array &$change Array with data about changes.
140141
* @return string Html code representing one or more rows of text with no difference.
141142
*/
142-
private function generateTableRowsEqual(&$change)
143+
private function generateTableRowsEqual(&$change) : string
143144
{
144145
$html = "";
145146
foreach ($change['base']['lines'] as $no => $line) {
@@ -160,7 +161,7 @@ private function generateTableRowsEqual(&$change)
160161
* @param array &$change Array with data about changes.
161162
* @return string Html code representing one or more rows of added text.
162163
*/
163-
private function generateTableRowsInsert(&$change)
164+
private function generateTableRowsInsert(&$change) : string
164165
{
165166
$html = "";
166167
foreach ($change['changed']['lines'] as $no => $line) {
@@ -180,7 +181,7 @@ private function generateTableRowsInsert(&$change)
180181
* @param array &$change Array with data about changes.
181182
* @return string Html code representing one or more rows of removed text.
182183
*/
183-
private function generateTableRowsDelete(&$change)
184+
private function generateTableRowsDelete(&$change) : string
184185
{
185186
$html = "";
186187
foreach ($change['base']['lines'] as $no => $line) {
@@ -200,7 +201,7 @@ private function generateTableRowsDelete(&$change)
200201
* @param array &$change Array with data about changes.
201202
* @return string Html code representing one or more rows of modified.
202203
*/
203-
private function generateTableRowsReplace(&$change)
204+
private function generateTableRowsReplace(&$change) : string
204205
{
205206
$html = "";
206207

lib/jblond/Diff/Renderer/Html/SideBySide.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
namespace jblond\Diff\Renderer\Html;
34

45
/**
@@ -53,7 +54,7 @@ class SideBySide extends HtmlArray
5354
*
5455
* @return string The generated side by side diff.
5556
*/
56-
public function render()
57+
public function render() : string
5758
{
5859
$changes = parent::render();
5960

@@ -102,7 +103,7 @@ public function render()
102103
*
103104
* @return string Html code representation of the table's header.
104105
*/
105-
private function generateTableHeader()
106+
private function generateTableHeader() : string
106107
{
107108
$html = '<table class="Differences DifferencesSideBySide">';
108109
$html .= '<thead>';
@@ -119,7 +120,7 @@ private function generateTableHeader()
119120
*
120121
* @return string Html code representing empty table body.
121122
*/
122-
private function generateSkippedTable()
123+
private function generateSkippedTable() : string
123124
{
124125
$html = '<tbody class="Skipped">';
125126
$html .= '<th>&hellip;</th><td>&#xA0;</td>';
@@ -134,7 +135,7 @@ private function generateSkippedTable()
134135
* @param array &$change Array with data about changes.
135136
* @return string Html code representing one or more rows of text with no difference.
136137
*/
137-
private function generateTableRowsEqual(&$change)
138+
private function generateTableRowsEqual(&$change) : string
138139
{
139140
$html = "";
140141
foreach ($change['base']['lines'] as $no => $line) {
@@ -156,7 +157,7 @@ private function generateTableRowsEqual(&$change)
156157
* @param array &$change Array with data about changes.
157158
* @return string Html code representing one or more rows of added text.
158159
*/
159-
private function generateTableRowsInsert(&$change)
160+
private function generateTableRowsInsert(&$change) : string
160161
{
161162
$html = "";
162163
foreach ($change['changed']['lines'] as $no => $line) {
@@ -177,7 +178,7 @@ private function generateTableRowsInsert(&$change)
177178
* @param array &$change Array with data about changes.
178179
* @return string Html code representing one or more rows of removed text.
179180
*/
180-
private function generateTableRowsDelete(&$change)
181+
private function generateTableRowsDelete(&$change) : string
181182
{
182183
$html = "";
183184
foreach ($change['base']['lines'] as $no => $line) {
@@ -198,7 +199,7 @@ private function generateTableRowsDelete(&$change)
198199
* @param array &$change Array with data about changes.
199200
* @return string Html code representing one or more rows of modified.
200201
*/
201-
private function generateTableRowsReplace(&$change)
202+
private function generateTableRowsReplace(&$change) : string
202203
{
203204
$html = "";
204205

lib/jblond/Diff/Renderer/RendererAbstract.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
namespace jblond\Diff\Renderer;
34

45
/**

lib/jblond/Diff/Renderer/Text/Context.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
namespace jblond\Diff\Renderer\Text;
34

45
use jblond\Diff\Renderer\RendererAbstract;
@@ -64,7 +65,7 @@ class Context extends RendererAbstract
6465
*
6566
* @return string The generated context diff.
6667
*/
67-
public function render()
68+
public function render() : string
6869
{
6970
$diff = '';
7071
$opCodes = $this->diff->getGroupedOpcodes();

lib/jblond/Diff/Renderer/Text/Unified.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
namespace jblond\Diff\Renderer\Text;
34

45
use jblond\Diff\Renderer\RendererAbstract;
@@ -54,7 +55,7 @@ class Unified extends RendererAbstract
5455
*
5556
* @return string The unified diff.
5657
*/
57-
public function render()
58+
public function render() : string
5859
{
5960
$diff = '';
6061
$opCodes = $this->diff->getGroupedOpcodes();

lib/jblond/Diff/SequenceMatcher.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
2+
declare(strict_types=1);
23
namespace jblond\Diff;
34

5+
use phpDocumentor\Reflection\Types\Boolean;
6+
47
/**
58
* Sequence matcher for Diff
69
*
@@ -236,7 +239,7 @@ private function chainB()
236239
* @param string $b
237240
* @return boolean $b True if the character is considered junk. False if not.
238241
*/
239-
private function isBJunk($b)
242+
private function isBJunk($b) : bool
240243
{
241244
if (isset($this->junkDict[$b])) {
242245
return true;
@@ -265,7 +268,7 @@ private function isBJunk($b)
265268
* @return array Array containing the longest match that includes the starting position in $a,
266269
* start in $b and the length/size.
267270
*/
268-
public function findLongestMatch($alo, $ahi, $blo, $bhi)
271+
public function findLongestMatch($alo, $ahi, $blo, $bhi) : array
269272
{
270273
$a = $this->a;
271274
$b = $this->b;
@@ -348,7 +351,7 @@ public function findLongestMatch($alo, $ahi, $blo, $bhi)
348351
* @param int $bIndex Line number to check against in b.
349352
* @return boolean True if the lines are different and false if not.
350353
*/
351-
public function linesAreDifferent($aIndex, $bIndex)
354+
public function linesAreDifferent($aIndex, $bIndex) : bool
352355
{
353356
$lineA = $this->a[$aIndex];
354357
$lineB = $this->b[$bIndex];
@@ -381,7 +384,7 @@ public function linesAreDifferent($aIndex, $bIndex)
381384
*
382385
* @return array Nested array of the matching blocks, as described by the function.
383386
*/
384-
public function getMatchingBlocks()
387+
public function getMatchingBlocks() : array
385388
{
386389
if (!empty($this->matchingBlocks)) {
387390
return $this->matchingBlocks;
@@ -491,7 +494,7 @@ public function getMatchingBlocks()
491494
*
492495
* @return array Array of the opcodes describing the differences between the strings.
493496
*/
494-
public function getOpCodes()
497+
public function getOpCodes() : array
495498
{
496499
if (!empty($this->opCodes)) {
497500
return $this->opCodes;
@@ -553,7 +556,7 @@ public function getOpCodes()
553556
* @param int $context The number of lines of context to provide around the groups.
554557
* @return array Nested array of all of the grouped op codes.
555558
*/
556-
public function getGroupedOpcodes($context = 3)
559+
public function getGroupedOpcodes($context = 3) : array
557560
{
558561
$opCodes = $this->getOpCodes();
559562
if (empty($opCodes)) {
@@ -638,7 +641,7 @@ public function getGroupedOpcodes($context = 3)
638641
*
639642
* @return float The calculated ratio.
640643
*/
641-
public function ratio()
644+
public function ratio() : float
642645
{
643646
$matches = array_reduce($this->getMatchingBlocks(), array($this, 'ratioReduce'), 0);
644647
return $this->calculateRatio($matches, count($this->a) + count($this->b));
@@ -651,7 +654,7 @@ public function ratio()
651654
* @param array $triple Array containing the matching block triple to add to the running total.
652655
* @return int The new running total for the number of matches.
653656
*/
654-
private function ratioReduce($sum, $triple)
657+
private function ratioReduce($sum, $triple) : int
655658
{
656659
return $sum + ($triple[count($triple) - 1]);
657660
}
@@ -664,7 +667,7 @@ private function ratioReduce($sum, $triple)
664667
* @param int $length The length of the two strings.
665668
* @return float The calculated ratio.
666669
*/
667-
private function calculateRatio($matches, $length = 0)
670+
private function calculateRatio($matches, $length = 0) : float
668671
{
669672
if ($length) {
670673
return 2 * ($matches / $length);
@@ -697,7 +700,7 @@ private function arrayGetDefault($array, $key, $default)
697700
* @param array $b Second array to compare.
698701
* @return int -1, 0 or 1, as expected by the usort function.
699702
*/
700-
private function tupleSort($a, $b)
703+
private function tupleSort($a, $b) : int
701704
{
702705
$max = max(count($a), count($b));
703706
for ($i = 0; $i < $max; ++$i) {

tests/Diff/Renderer/ArrayTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
namespace Tests\Diff\Renderer\Html;
34

45
require "../../../lib/Autoloader.php";

0 commit comments

Comments
 (0)