Replace 'self' with self::class in 2 Modules (#2773)
PHP 8.2 is supposed to deprecate the use of `['self', 'functionname']` for callables, suggesting the use of `[self::class, 'functionname']` instead. We made this change in a recent PR, and, while I'm thinking about it, I'll fix the remaining 2 modules with this construction. Vlookup is already adequately covered in unit tests. Reader/Xls/MD5 is not; a unit test is added.
This commit is contained in:
parent
450873b5fa
commit
0a531cf1cd
|
|
@ -790,26 +790,6 @@ parameters:
|
|||
count: 3
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/RowColumnInformation.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\LookupRef\\\\VLookup\\:\\:vlookupSort\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\LookupRef\\\\VLookup\\:\\:vlookupSort\\(\\) has parameter \\$a with no type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\LookupRef\\\\VLookup\\:\\:vlookupSort\\(\\) has parameter \\$b with no type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\(T, T\\)\\: int, array\\{'self', 'vlookupSort'\\} given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
|
||||
|
||||
-
|
||||
message: "#^Binary operation \"/\" between array\\|float\\|int\\|string and array\\|float\\|int\\|string results in an error\\.$#"
|
||||
count: 2
|
||||
|
|
@ -2370,36 +2350,6 @@ parameters:
|
|||
count: 1
|
||||
path: src/PhpSpreadsheet/Reader/Xls/ErrorCode.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\MD5\\:\\:f\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Reader/Xls/MD5.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\MD5\\:\\:g\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Reader/Xls/MD5.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\MD5\\:\\:h\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Reader/Xls/MD5.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\MD5\\:\\:i\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Reader/Xls/MD5.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\MD5\\:\\:rotate\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Reader/Xls/MD5.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\MD5\\:\\:step\\(\\) has parameter \\$func with no type specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Reader/Xls/MD5.php
|
||||
|
||||
-
|
||||
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Xls\\\\RC4\\:\\:\\$i has no type specified\\.$#"
|
||||
count: 1
|
||||
|
|
|
|||
|
|
@ -49,7 +49,9 @@ class VLookup extends LookupBase
|
|||
$firstColumn = array_shift($columnKeys) ?? 1;
|
||||
|
||||
if (!$notExactMatch) {
|
||||
uasort($lookupArray, ['self', 'vlookupSort']);
|
||||
/** @var callable */
|
||||
$callable = [self::class, 'vlookupSort'];
|
||||
uasort($lookupArray, $callable);
|
||||
}
|
||||
|
||||
$rowNumber = self::vLookupSearch($lookupValue, $lookupArray, $firstColumn, $notExactMatch);
|
||||
|
|
@ -62,7 +64,7 @@ class VLookup extends LookupBase
|
|||
return ExcelError::NA();
|
||||
}
|
||||
|
||||
private static function vlookupSort($a, $b)
|
||||
private static function vlookupSort(array $a, array $b): int
|
||||
{
|
||||
reset($a);
|
||||
$firstColumn = key($a);
|
||||
|
|
|
|||
|
|
@ -79,10 +79,10 @@ class MD5
|
|||
$C = $this->c;
|
||||
$D = $this->d;
|
||||
|
||||
$F = ['self', 'f'];
|
||||
$G = ['self', 'g'];
|
||||
$H = ['self', 'h'];
|
||||
$I = ['self', 'i'];
|
||||
$F = [self::class, 'f'];
|
||||
$G = [self::class, 'g'];
|
||||
$H = [self::class, 'h'];
|
||||
$I = [self::class, 'i'];
|
||||
|
||||
// ROUND 1
|
||||
self::step($F, $A, $B, $C, $D, $words[0], 7, 0xd76aa478);
|
||||
|
|
@ -162,33 +162,34 @@ class MD5
|
|||
$this->d = ($this->d + $D) & 0xffffffff;
|
||||
}
|
||||
|
||||
private static function f(int $X, int $Y, int $Z)
|
||||
private static function f(int $X, int $Y, int $Z): int
|
||||
{
|
||||
return ($X & $Y) | ((~$X) & $Z); // X AND Y OR NOT X AND Z
|
||||
}
|
||||
|
||||
private static function g(int $X, int $Y, int $Z)
|
||||
private static function g(int $X, int $Y, int $Z): int
|
||||
{
|
||||
return ($X & $Z) | ($Y & (~$Z)); // X AND Z OR Y AND NOT Z
|
||||
}
|
||||
|
||||
private static function h(int $X, int $Y, int $Z)
|
||||
private static function h(int $X, int $Y, int $Z): int
|
||||
{
|
||||
return $X ^ $Y ^ $Z; // X XOR Y XOR Z
|
||||
}
|
||||
|
||||
private static function i(int $X, int $Y, int $Z)
|
||||
private static function i(int $X, int $Y, int $Z): int
|
||||
{
|
||||
return $Y ^ ($X | (~$Z)); // Y XOR (X OR NOT Z)
|
||||
}
|
||||
|
||||
private static function step($func, int &$A, int $B, int $C, int $D, int $M, int $s, int $t): void
|
||||
private static function step(callable $func, int &$A, int $B, int $C, int $D, int $M, int $s, int $t): void
|
||||
{
|
||||
$A = ($A + call_user_func($func, $B, $C, $D) + $M + $t) & 0xffffffff;
|
||||
$A = self::rotate($A, $s);
|
||||
$A = ($B + $A) & 0xffffffff;
|
||||
}
|
||||
|
||||
/** @return float|int */
|
||||
private static function rotate(int $decimal, int $bits)
|
||||
{
|
||||
$binary = str_pad(decbin($decimal), 32, '0', STR_PAD_LEFT);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xls;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xls\MD5;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class Md5Test extends TestCase
|
||||
{
|
||||
public function testMd5(): void
|
||||
{
|
||||
$md5 = new MD5();
|
||||
$md5->add('123456789a123456789b123456789c123456789d123456789e123456789f1234');
|
||||
$context = $md5->getContext();
|
||||
self::assertSame('0761293f016b925b0bca11b34f1ed613', bin2hex($context));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue