Skip to content

Commit

Permalink
#363 : add Disjunctive Normal Form Types support
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Nov 6, 2023
1 parent c23dfb1 commit 0dcd410
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ public function enterNode(Node $node)
if ($param->type instanceof Node\IntersectionType) {
$this->updateVersion('8.1.0', $versions['php.min']);
} elseif ($param->type instanceof Node\UnionType) {
$this->updateVersion('8.0.0', $versions['php.min']);
$unionTypes = $param->type->types;
$current = '8.0.0';
foreach ($unionTypes as $type) {
if ($type instanceof Node\IntersectionType) {
$current = '8.2.0';
}
}
$this->updateVersion($current, $versions['php.min']);
} elseif ($param->type instanceof Node\NullableType) {
// @link https://www.php.net/manual/en/migration71.new-features.php#migration71.new-features.nullable-types
$this->updateVersion('7.1.0', $versions['php.min']);
Expand Down
21 changes: 21 additions & 0 deletions tests/Sniffs/ParamTypeDeclarationSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @link https://www.php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
* @link https://www.php.net/manual/en/migration71.new-features.php#migration71.new-features.nullable-types
* @link https://www.php.net/manual/en/migration56.new-features.php#migration56.new-features.exponentiation
* @link https://www.php.net/manual/en/migration82.new-features.php#migration82.new-features.core.type-system
* @link https://github.com/llaville/php-compat-info/issues/142
* @link https://github.com/llaville/php-compat-info/issues/273
*/
Expand Down Expand Up @@ -249,4 +250,24 @@ public function testIntersectionTypes()
$functions['count_and_iterate']['php.min']
);
}

/**
* Feature test for Disjunctive Normal Form types
*
* @group features
* @link https://github.com/llaville/php-compatinfo/issues/363
* @return void
* @throws Exception
*/
public function testDisjunctiveNormalFormTypes()
{
$dataSource = 'dnf_types.php';
$metrics = $this->executeAnalysis($dataSource);
$functions = $metrics[self::$analyserId]['methods'];

$this->assertEquals(
'8.2.0',
$functions['Foo\bar']['php.min']
);
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/sniffs/functions/dnf_types.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

class Foo {
public function bar((A&B)|null $entity) {
return $entity;
}
}

0 comments on commit 0dcd410

Please sign in to comment.