Skip to content

Commit 9cc5cfb

Browse files
committed
stronger type hinting
1 parent 8f19707 commit 9cc5cfb

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

lib/jblond/Diff.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Diff
8787
* @param array $b Array containing the lines for the second string to compare.
8888
* @param array $options Array for the options
8989
*/
90-
public function __construct($a, $b, $options = array())
90+
public function __construct(array $a, array $b, array $options = array())
9191
{
9292
$this->a = $a;
9393
$this->b = $b;
@@ -119,10 +119,10 @@ public function render($renderer)
119119
* that line.
120120
*
121121
* @param int $start The starting number.
122-
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
122+
* @param int|null $end The ending number. If not supplied, only the item in $start will be returned.
123123
* @return array Array of all of the lines between the specified range.
124124
*/
125-
public function getA($start = 0, $end = null) : array
125+
public function getA(int $start = 0, $end = null) : array
126126
{
127127
if ($start == 0 && $end === null) {
128128
return $this->a;
@@ -144,10 +144,10 @@ public function getA($start = 0, $end = null) : array
144144
* that line.
145145
*
146146
* @param int $start The starting number.
147-
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
147+
* @param int|null $end The ending number. If not supplied, only the item in $start will be returned.
148148
* @return array Array of all of the lines between the specified range.
149149
*/
150-
public function getB($start = 0, $end = null) : array
150+
public function getB(int $start = 0, $end = null) : array
151151
{
152152
if ($start == 0 && $end === null) {
153153
return $this->b;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ class HtmlArray extends RendererAbstract
6565
* @param string $replacement The replacement string.
6666
* @param int $start If start is positive, the replacing will begin at the start'th offset into string.
6767
* If start is negative, the replacing will begin at the start'th character from the end of string.
68-
* @param int $length If given and is positive, it represents the length of the portion of string which is to
68+
* @param int|null $length If given and is positive, it represents the length of the portion of string which is to
6969
* be replaced. If it is negative, it represents the number of characters from the end of string at which to
7070
* stop replacing. If it is not given, then it will default to strlen( string ); i.e. end the replacing at the
7171
* end of string. Of course, if length is zero then this function will have the effect of inserting replacement
7272
* into string at the given start offset.
7373
* @return string|array The result string is returned. If string is an array then array is returned.
7474
*/
75-
public function mbSubstrReplace(string $string, string $replacement, int $start, int $length = null)
75+
public function mbSubstrReplace(string $string, string $replacement, int $start, $length = null)
7676
{
7777
if (is_array($string)) {
7878
$num = count($string);
@@ -204,7 +204,7 @@ public function render()
204204
* @param string $toLine The second string.
205205
* @return array Array containing the starting position (0 by default) and the ending position (-1 by default)
206206
*/
207-
private function getChangeExtent($fromLine, $toLine)
207+
private function getChangeExtent(string $fromLine, string $toLine)
208208
{
209209
$start = 0;
210210
$limit = min(mb_strlen($fromLine), mb_strlen($toLine));
@@ -230,7 +230,7 @@ private function getChangeExtent($fromLine, $toLine)
230230
* @param array $lines Array of lines to format.
231231
* @return array Array of the formatted lines.
232232
*/
233-
protected function formatLines($lines)
233+
protected function formatLines(array $lines) : array
234234
{
235235
if ($this->options['tabSize'] !== false) {
236236
$lines = array_map(array($this, 'ExpandTabs'), $lines);
@@ -248,7 +248,7 @@ protected function formatLines($lines)
248248
* @param array $matches The string of spaces.
249249
* @return string The HTML representation of the string.
250250
*/
251-
protected function fixSpaces($matches)
251+
protected function fixSpaces(array $matches) : string
252252
{
253253
$buffer = '';
254254
$count = 0;
@@ -273,7 +273,7 @@ protected function fixSpaces($matches)
273273
* @param string $line The containing tabs to convert.
274274
* @return string The line with the tabs converted to spaces.
275275
*/
276-
private function expandTabs($line)
276+
private function expandTabs(string $line) : string
277277
{
278278
$tabSize = $this->options['tabSize'];
279279
while (($pos = strpos($line, "\t")) !== false) {
@@ -292,7 +292,7 @@ private function expandTabs($line)
292292
* @param string $string The string.
293293
* @return string The string with the HTML characters replaced by entities.
294294
*/
295-
private function htmlSafe($string)
295+
private function htmlSafe(string $string) : string
296296
{
297297
return htmlspecialchars($string, ENT_NOQUOTES, 'UTF-8');
298298
}
@@ -303,7 +303,7 @@ private function htmlSafe($string)
303303
* @param integer $j1
304304
* @return array
305305
*/
306-
private function getDefaultArray($tag, $i1, $j1)
306+
private function getDefaultArray(string $tag, int $i1, int $j1) : array
307307
{
308308
return array
309309
(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private function generateSkippedTable() : string
140140
* @param array &$change Array with data about changes.
141141
* @return string Html code representing one or more rows of text with no difference.
142142
*/
143-
private function generateTableRowsEqual(&$change) : string
143+
private function generateTableRowsEqual(array &$change) : string
144144
{
145145
$html = "";
146146
foreach ($change['base']['lines'] as $no => $line) {
@@ -161,7 +161,7 @@ private function generateTableRowsEqual(&$change) : string
161161
* @param array &$change Array with data about changes.
162162
* @return string Html code representing one or more rows of added text.
163163
*/
164-
private function generateTableRowsInsert(&$change) : string
164+
private function generateTableRowsInsert(array &$change) : string
165165
{
166166
$html = "";
167167
foreach ($change['changed']['lines'] as $no => $line) {
@@ -181,7 +181,7 @@ private function generateTableRowsInsert(&$change) : string
181181
* @param array &$change Array with data about changes.
182182
* @return string Html code representing one or more rows of removed text.
183183
*/
184-
private function generateTableRowsDelete(&$change) : string
184+
private function generateTableRowsDelete(array &$change) : string
185185
{
186186
$html = "";
187187
foreach ($change['base']['lines'] as $no => $line) {
@@ -201,7 +201,7 @@ private function generateTableRowsDelete(&$change) : string
201201
* @param array &$change Array with data about changes.
202202
* @return string Html code representing one or more rows of modified.
203203
*/
204-
private function generateTableRowsReplace(&$change) : string
204+
private function generateTableRowsReplace(array &$change) : string
205205
{
206206
$html = "";
207207

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private function generateSkippedTable() : string
135135
* @param array &$change Array with data about changes.
136136
* @return string Html code representing one or more rows of text with no difference.
137137
*/
138-
private function generateTableRowsEqual(&$change) : string
138+
private function generateTableRowsEqual(array &$change) : string
139139
{
140140
$html = "";
141141
foreach ($change['base']['lines'] as $no => $line) {
@@ -157,7 +157,7 @@ private function generateTableRowsEqual(&$change) : string
157157
* @param array &$change Array with data about changes.
158158
* @return string Html code representing one or more rows of added text.
159159
*/
160-
private function generateTableRowsInsert(&$change) : string
160+
private function generateTableRowsInsert(array &$change) : string
161161
{
162162
$html = "";
163163
foreach ($change['changed']['lines'] as $no => $line) {
@@ -178,7 +178,7 @@ private function generateTableRowsInsert(&$change) : string
178178
* @param array &$change Array with data about changes.
179179
* @return string Html code representing one or more rows of removed text.
180180
*/
181-
private function generateTableRowsDelete(&$change) : string
181+
private function generateTableRowsDelete(array &$change) : string
182182
{
183183
$html = "";
184184
foreach ($change['base']['lines'] as $no => $line) {
@@ -199,7 +199,7 @@ private function generateTableRowsDelete(&$change) : string
199199
* @param array &$change Array with data about changes.
200200
* @return string Html code representing one or more rows of modified.
201201
*/
202-
private function generateTableRowsReplace(&$change) : string
202+
private function generateTableRowsReplace(array &$change) : string
203203
{
204204
$html = "";
205205

lib/jblond/Diff/SequenceMatcher.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class SequenceMatcher
110110
* @param string|array|null $junkCallback Either an array or string that references a callback function
111111
* (if there is one) to determine 'junk' characters.
112112
*/
113-
public function __construct($a, $b, $options, $junkCallback = null)
113+
public function __construct($a, $b, array $options, $junkCallback = null)
114114
{
115115
$this->a = array();
116116
$this->b = array();
@@ -122,7 +122,7 @@ public function __construct($a, $b, $options, $junkCallback = null)
122122
/**
123123
* @param array $options
124124
*/
125-
public function setOptions($options)
125+
public function setOptions(array $options)
126126
{
127127
$this->options = array_merge($this->defaultOptions, $options);
128128
}
@@ -237,7 +237,7 @@ private function chainB()
237237
* @param string $b
238238
* @return bool $b True if the character is considered junk. False if not.
239239
*/
240-
private function isBJunk($b) : bool
240+
private function isBJunk(string $b) : bool
241241
{
242242
if (isset($this->junkDict[$b])) {
243243
return true;
@@ -266,7 +266,7 @@ private function isBJunk($b) : bool
266266
* @return array Array containing the longest match that includes the starting position in $a,
267267
* start in $b and the length/size.
268268
*/
269-
public function findLongestMatch($alo, $ahi, $blo, $bhi) : array
269+
public function findLongestMatch(int $alo, int $ahi, int $blo, int $bhi) : array
270270
{
271271
$a = $this->a;
272272
$b = $this->b;
@@ -349,7 +349,7 @@ public function findLongestMatch($alo, $ahi, $blo, $bhi) : array
349349
* @param int $bIndex Line number to check against in b.
350350
* @return bool True if the lines are different and false if not.
351351
*/
352-
public function linesAreDifferent($aIndex, $bIndex) : bool
352+
public function linesAreDifferent(int $aIndex, int $bIndex) : bool
353353
{
354354
$lineA = $this->a[$aIndex];
355355
$lineB = $this->b[$bIndex];
@@ -554,7 +554,7 @@ public function getOpCodes() : array
554554
* @param int $context The number of lines of context to provide around the groups.
555555
* @return array Nested array of all of the grouped op codes.
556556
*/
557-
public function getGroupedOpcodes($context = 3) : array
557+
public function getGroupedOpcodes(int $context = 3) : array
558558
{
559559
$opCodes = $this->getOpCodes();
560560
if (empty($opCodes)) {
@@ -652,7 +652,7 @@ public function ratio() : float
652652
* @param array $triple Array containing the matching block triple to add to the running total.
653653
* @return int The new running total for the number of matches.
654654
*/
655-
private function ratioReduce($sum, $triple) : int
655+
private function ratioReduce(int $sum, array $triple) : int
656656
{
657657
return $sum + ($triple[count($triple) - 1]);
658658
}
@@ -665,7 +665,7 @@ private function ratioReduce($sum, $triple) : int
665665
* @param int $length The length of the two strings.
666666
* @return float The calculated ratio.
667667
*/
668-
private function calculateRatio($matches, $length = 0) : float
668+
private function calculateRatio(int $matches, int $length = 0) : float
669669
{
670670
if ($length) {
671671
return 2 * ($matches / $length);
@@ -683,7 +683,7 @@ private function calculateRatio($matches, $length = 0) : float
683683
* @param mixed $default The value to return as the default value if the key doesn't exist.
684684
* @return mixed The value from the array if the key exists or otherwise the default.
685685
*/
686-
private function arrayGetDefault($array, $key, $default)
686+
private function arrayGetDefault(array $array, $key, $default)
687687
{
688688
if (isset($array[$key])) {
689689
return $array[$key];
@@ -698,7 +698,7 @@ private function arrayGetDefault($array, $key, $default)
698698
* @param array $b Second array to compare.
699699
* @return int -1, 0 or 1, as expected by the usort function.
700700
*/
701-
private function tupleSort($a, $b) : int
701+
private function tupleSort(array $a, array $b) : int
702702
{
703703
$max = max(count($a), count($b));
704704
for ($i = 0; $i < $max; ++$i) {

0 commit comments

Comments
 (0)