Skip to content

Development #12

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 8 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
stronger type hinting
  • Loading branch information
JBlond committed Feb 15, 2019
commit 9cc5cfbaf8ff2a149386756ad77d2419e25533c6
10 changes: 5 additions & 5 deletions lib/jblond/Diff.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Diff
* @param array $b Array containing the lines for the second string to compare.
* @param array $options Array for the options
*/
public function __construct($a, $b, $options = array())
public function __construct(array $a, array $b, array $options = array())
{
$this->a = $a;
$this->b = $b;
Expand Down Expand Up @@ -119,10 +119,10 @@ public function render($renderer)
* that line.
*
* @param int $start The starting number.
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
* @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 getA($start = 0, $end = null) : array
public function getA(int $start = 0, $end = null) : array
{
if ($start == 0 && $end === null) {
return $this->a;
Expand All @@ -144,10 +144,10 @@ public function getA($start = 0, $end = null) : array
* that line.
*
* @param int $start The starting number.
* @param int $end The ending number. If not supplied, only the item in $start will be returned.
* @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 getB($start = 0, $end = null) : array
public function getB(int $start = 0, $end = null) : array
{
if ($start == 0 && $end === null) {
return $this->b;
Expand Down
16 changes: 8 additions & 8 deletions lib/jblond/Diff/Renderer/Html/HtmlArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ class HtmlArray extends RendererAbstract
* @param string $replacement The replacement string.
* @param int $start If start is positive, the replacing will begin at the start'th offset into string.
* If start is negative, the replacing will begin at the start'th character from the end of string.
* @param int $length If given and is positive, it represents the length of the portion of string which is to
* @param int|null $length If given and is positive, it represents the length of the portion of string which is to
* be replaced. If it is negative, it represents the number of characters from the end of string at which to
* stop replacing. If it is not given, then it will default to strlen( string ); i.e. end the replacing at the
* end of string. Of course, if length is zero then this function will have the effect of inserting replacement
* into string at the given start offset.
* @return string|array The result string is returned. If string is an array then array is returned.
*/
public function mbSubstrReplace(string $string, string $replacement, int $start, int $length = null)
public function mbSubstrReplace(string $string, string $replacement, int $start, $length = null)
{
if (is_array($string)) {
$num = count($string);
Expand Down Expand Up @@ -204,7 +204,7 @@ public function render()
* @param string $toLine The second string.
* @return array Array containing the starting position (0 by default) and the ending position (-1 by default)
*/
private function getChangeExtent($fromLine, $toLine)
private function getChangeExtent(string $fromLine, string $toLine)
{
$start = 0;
$limit = min(mb_strlen($fromLine), mb_strlen($toLine));
Expand All @@ -230,7 +230,7 @@ private function getChangeExtent($fromLine, $toLine)
* @param array $lines Array of lines to format.
* @return array Array of the formatted lines.
*/
protected function formatLines($lines)
protected function formatLines(array $lines) : array
{
if ($this->options['tabSize'] !== false) {
$lines = array_map(array($this, 'ExpandTabs'), $lines);
Expand All @@ -248,7 +248,7 @@ protected function formatLines($lines)
* @param array $matches The string of spaces.
* @return string The HTML representation of the string.
*/
protected function fixSpaces($matches)
protected function fixSpaces(array $matches) : string
{
$buffer = '';
$count = 0;
Expand All @@ -273,7 +273,7 @@ protected function fixSpaces($matches)
* @param string $line The containing tabs to convert.
* @return string The line with the tabs converted to spaces.
*/
private function expandTabs($line)
private function expandTabs(string $line) : string
{
$tabSize = $this->options['tabSize'];
while (($pos = strpos($line, "\t")) !== false) {
Expand All @@ -292,7 +292,7 @@ private function expandTabs($line)
* @param string $string The string.
* @return string The string with the HTML characters replaced by entities.
*/
private function htmlSafe($string)
private function htmlSafe(string $string) : string
{
return htmlspecialchars($string, ENT_NOQUOTES, 'UTF-8');
}
Expand All @@ -303,7 +303,7 @@ private function htmlSafe($string)
* @param integer $j1
* @return array
*/
private function getDefaultArray($tag, $i1, $j1)
private function getDefaultArray(string $tag, int $i1, int $j1) : array
{
return array
(
Expand Down
8 changes: 4 additions & 4 deletions lib/jblond/Diff/Renderer/Html/Inline.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private 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.
*/
private function generateTableRowsEqual(&$change) : string
private function generateTableRowsEqual(array &$change) : string
{
$html = "";
foreach ($change['base']['lines'] as $no => $line) {
Expand All @@ -161,7 +161,7 @@ private function generateTableRowsEqual(&$change) : string
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of added text.
*/
private function generateTableRowsInsert(&$change) : string
private function generateTableRowsInsert(array &$change) : string
{
$html = "";
foreach ($change['changed']['lines'] as $no => $line) {
Expand All @@ -181,7 +181,7 @@ private function generateTableRowsInsert(&$change) : string
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of removed text.
*/
private function generateTableRowsDelete(&$change) : string
private function generateTableRowsDelete(array &$change) : string
{
$html = "";
foreach ($change['base']['lines'] as $no => $line) {
Expand All @@ -201,7 +201,7 @@ private function generateTableRowsDelete(&$change) : string
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of modified.
*/
private function generateTableRowsReplace(&$change) : string
private function generateTableRowsReplace(array &$change) : string
{
$html = "";

Expand Down
8 changes: 4 additions & 4 deletions lib/jblond/Diff/Renderer/Html/SideBySide.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private 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.
*/
private function generateTableRowsEqual(&$change) : string
private function generateTableRowsEqual(array &$change) : string
{
$html = "";
foreach ($change['base']['lines'] as $no => $line) {
Expand All @@ -157,7 +157,7 @@ private function generateTableRowsEqual(&$change) : string
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of added text.
*/
private function generateTableRowsInsert(&$change) : string
private function generateTableRowsInsert(array &$change) : string
{
$html = "";
foreach ($change['changed']['lines'] as $no => $line) {
Expand All @@ -178,7 +178,7 @@ private function generateTableRowsInsert(&$change) : string
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of removed text.
*/
private function generateTableRowsDelete(&$change) : string
private function generateTableRowsDelete(array &$change) : string
{
$html = "";
foreach ($change['base']['lines'] as $no => $line) {
Expand All @@ -199,7 +199,7 @@ private function generateTableRowsDelete(&$change) : string
* @param array &$change Array with data about changes.
* @return string Html code representing one or more rows of modified.
*/
private function generateTableRowsReplace(&$change) : string
private function generateTableRowsReplace(array &$change) : string
{
$html = "";

Expand Down
20 changes: 10 additions & 10 deletions lib/jblond/Diff/SequenceMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class SequenceMatcher
* @param string|array|null $junkCallback Either an array or string that references a callback function
* (if there is one) to determine 'junk' characters.
*/
public function __construct($a, $b, $options, $junkCallback = null)
public function __construct($a, $b, array $options, $junkCallback = null)
{
$this->a = array();
$this->b = array();
Expand All @@ -122,7 +122,7 @@ public function __construct($a, $b, $options, $junkCallback = null)
/**
* @param array $options
*/
public function setOptions($options)
public function setOptions(array $options)
{
$this->options = array_merge($this->defaultOptions, $options);
}
Expand Down Expand Up @@ -237,7 +237,7 @@ private function chainB()
* @param string $b
* @return bool $b True if the character is considered junk. False if not.
*/
private function isBJunk($b) : bool
private function isBJunk(string $b) : bool
{
if (isset($this->junkDict[$b])) {
return true;
Expand Down Expand Up @@ -266,7 +266,7 @@ private function isBJunk($b) : bool
* @return array Array containing the longest match that includes the starting position in $a,
* start in $b and the length/size.
*/
public function findLongestMatch($alo, $ahi, $blo, $bhi) : array
public function findLongestMatch(int $alo, int $ahi, int $blo, int $bhi) : array
{
$a = $this->a;
$b = $this->b;
Expand Down Expand Up @@ -349,7 +349,7 @@ public function findLongestMatch($alo, $ahi, $blo, $bhi) : array
* @param int $bIndex Line number to check against in b.
* @return bool True if the lines are different and false if not.
*/
public function linesAreDifferent($aIndex, $bIndex) : bool
public function linesAreDifferent(int $aIndex, int $bIndex) : bool
{
$lineA = $this->a[$aIndex];
$lineB = $this->b[$bIndex];
Expand Down Expand Up @@ -554,7 +554,7 @@ public function getOpCodes() : array
* @param int $context The number of lines of context to provide around the groups.
* @return array Nested array of all of the grouped op codes.
*/
public function getGroupedOpcodes($context = 3) : array
public function getGroupedOpcodes(int $context = 3) : array
{
$opCodes = $this->getOpCodes();
if (empty($opCodes)) {
Expand Down Expand Up @@ -652,7 +652,7 @@ public function ratio() : float
* @param array $triple Array containing the matching block triple to add to the running total.
* @return int The new running total for the number of matches.
*/
private function ratioReduce($sum, $triple) : int
private function ratioReduce(int $sum, array $triple) : int
{
return $sum + ($triple[count($triple) - 1]);
}
Expand All @@ -665,7 +665,7 @@ private function ratioReduce($sum, $triple) : int
* @param int $length The length of the two strings.
* @return float The calculated ratio.
*/
private function calculateRatio($matches, $length = 0) : float
private function calculateRatio(int $matches, int $length = 0) : float
{
if ($length) {
return 2 * ($matches / $length);
Expand All @@ -683,7 +683,7 @@ private function calculateRatio($matches, $length = 0) : float
* @param mixed $default The value to return as the default value if the key doesn't exist.
* @return mixed The value from the array if the key exists or otherwise the default.
*/
private function arrayGetDefault($array, $key, $default)
private function arrayGetDefault(array $array, $key, $default)
{
if (isset($array[$key])) {
return $array[$key];
Expand All @@ -698,7 +698,7 @@ private function arrayGetDefault($array, $key, $default)
* @param array $b Second array to compare.
* @return int -1, 0 or 1, as expected by the usort function.
*/
private function tupleSort($a, $b) : int
private function tupleSort(array $a, array $b) : int
{
$max = max(count($a), count($b));
for ($i = 0; $i < $max; ++$i) {
Expand Down