Skip to content

Commit

Permalink
PHP 8.4 insists that functions that have a default of null, also allo…
Browse files Browse the repository at this point in the history
…w null to be passed.
  • Loading branch information
Danack committed Jul 2, 2024
1 parent cbcf7bd commit cffe432
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ImagickKernel.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function addUnityKernel(float $scale): void {}
// KERNEL_*
public static function fromBuiltin(int $kernel, string $shape): ImagickKernel {}

public static function fromMatrix(array $matrix, array $origin = null): ImagickKernel {}
public static function fromMatrix(array $matrix, ?array $origin = null): ImagickKernel {}

public function getMatrix(): array {}

Expand Down
2 changes: 1 addition & 1 deletion ImagickKernel_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ImagickKernel_fromMatrix, 0, 0, 1)
#endif

#if PHP_VERSION_ID >= 80000
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, origin, IS_ARRAY, 0, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, origin, IS_ARRAY, 1, "null")
#else
ZEND_ARG_INFO(0, origin)
#endif
Expand Down
3 changes: 1 addition & 2 deletions imagickkernel_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ PHP_METHOD(ImagickKernel, __construct)
*/
#if PHP_VERSION_ID >= 70000
PHP_METHOD(ImagickKernel, fromMatrix)

{
zval *kernel_array;
zval *origin_array;
Expand All @@ -257,7 +256,7 @@ PHP_METHOD(ImagickKernel, fromMatrix)
row = 0;
origin_array = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|a", &kernel_array, &origin_array) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|a!", &kernel_array, &origin_array) == FAILURE) {
RETURN_THROWS();
}

Expand Down
19 changes: 19 additions & 0 deletions tests/145_imagickkernel_coverage.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@ if ($kernelMatrix !== $matrix) {
var_dump($kernelMatrix);
}




//Test Scaling, and with null origin
$matrixIn = array(
array(-1, 0, -1),
array( 0, 8, 0),
array(-1, 0, -1),
);
$kernel = ImagickKernel::fromMatrix($matrixIn, null); // <-- line under test
$kernel->scale(1, \Imagick::NORMALIZE_KERNEL_VALUE);
$matrixOut = $kernel->getMatrix();

if ($matrixOut[1][1] != 2) {
echo "Matrix was not normalised correctly.";
var_dump($matrixOut);
}


echo "Complete".PHP_EOL;
?>
--EXPECTF--
Expand Down

0 comments on commit cffe432

Please sign in to comment.