Skip to content
Snippets Groups Projects
functions.php 794 B
<?php declare(strict_types=1);
/**
 * Used to load functions.
 */

// todo: TESTS: better assertion messages + throw FunctionSignatureAssertionError + catch in fn + pass it to assert -> compatible with PHP assert config
// todo: covariance and contra-variance
// todo: tests for primitive types

namespace Grifart\AssertFunction;

function params(string ...$params): array
{
	return $params;
}

function nullable(string $classType): string
{
	return '?' . $classType;
}

function assertSignature(callable $function, array $parameters, ?string $expectedReturnType): void
{
	try {
		SignatureAssertionUtil::checkSignature(
			$function,
			$parameters,
			$expectedReturnType
		);

	} catch (FunctionSignatureAssertionError $error) {
		// todo: add callee position
		assert(FALSE, $error);
	}

}