Skip to content
Snippets Groups Projects
Commit 9e8de572 authored by Jan Kuchař's avatar Jan Kuchař
Browse files

Merge branch 'php74' into 'master'

Replace assertFunctionSignature with phpstan's callable types

See merge request !1
parents 41f88295 4538fd22
No related branches found
No related tags found
1 merge request!1Replace assertFunctionSignature with phpstan's callable types
Pipeline #22034 passed
...@@ -22,3 +22,7 @@ test.verify.php73: ...@@ -22,3 +22,7 @@ test.verify.php73:
<<: *test-verify-template <<: *test-verify-template
image: grifart/php7.3-with-gulp-and-all-php-modules image: grifart/php7.3-with-gulp-and-all-php-modules
test.verify.php74:
<<: *test-verify-template
image: grifart/php7.4-with-gulp-and-all-php-modules
...@@ -22,10 +22,9 @@ ...@@ -22,10 +22,9 @@
"require": { "require": {
"php": "~7.2.0 | ~7.3.0", "php": "^7.2",
"nette/utils": "^3.0.1", "nette/utils": "^3.0.1",
"dibi/dibi": "^4.0.2", "dibi/dibi": "^4.0.2"
"grifart/assert-function-signature": "^0.1.0"
}, },
"require-dev": { "require-dev": {
"nette/tester": "^2.3", "nette/tester": "^2.3",
......
<?php declare(strict_types=1); <?php declare(strict_types=1);
namespace Grifart\Tables; namespace Grifart\Tables;
use function Grifart\AssertFunction\assertSignature;
use function Grifart\AssertFunction\nullable;
final class TypeMapper final class TypeMapper
{ {
private $matchers; /**
private $mappings; * @var (callable(string $typeName, string $location): ?string)[]
*/
public function __construct() private $matchers = [];
{
$this->mappings = [];
$this->matchers = [];
}
// TODO: isn't it too general? Or just map db-type name to php type and back? /**
public function addMapping(callable $typeMatcher, callable $mapper) { * @var (callable(mixed $value, string $typeName): mixed)[]
*/
private $mappings = [];
assertSignature($typeMatcher, ['string', 'string'], nullable('string'));
assertSignature($mapper, ['any'], 'mixed');
/**
* @param (callable(string $typeName, string $location): ?string) $typeMatcher
* @param (callable(mixed $value, string $typeName): mixed) $mapper
*
* TODO: isn't it too general? Or just map db-type name to php type and back?
*/
public function addMapping(callable $typeMatcher, callable $mapper) {
$this->matchers[] = $typeMatcher; $this->matchers[] = $typeMatcher;
$this->mappings[] = $mapper; $this->mappings[] = $mapper;
} }
...@@ -38,12 +36,6 @@ final class TypeMapper ...@@ -38,12 +36,6 @@ final class TypeMapper
$translatingType = $matcher($typeName, $location); $translatingType = $matcher($typeName, $location);
if ($translatingType !== NULL) { if ($translatingType !== NULL) {
$mapper = $this->mappings[$idx]; $mapper = $this->mappings[$idx];
// assertSignature(
// $mapper, [
// $this->getTypeForValue($value)
// ],
// 'mixed' // todo: $translatingType does not work for reverse mapping
// );
return $mapper($value, $typeName); return $mapper($value, $typeName);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment