Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[PropertyInfo] Fix extracting int range type
  • Loading branch information
norkunas committed May 31, 2022
commit 16dbefa4f25a483a6074cbd697bce2b9ae008429
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,23 @@ public function testDummyNamespaceWithProperty()
$this->assertEquals('A\Property', $phpStanTypes[0]->getClassName());
$this->assertEquals($phpDocTypes[0]->getClassName(), $phpStanTypes[0]->getClassName());
}

/**
* @dataProvider intRangeTypeProvider
*/
public function testExtractorIntRangeType(string $property, ?array $types)
{
$this->assertEquals($types, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\IntRangeDummy', $property));
}

public function intRangeTypeProvider(): array
{
return [
['a', [new Type(Type::BUILTIN_TYPE_INT)]],
['b', [new Type(Type::BUILTIN_TYPE_INT, true)]],
['c', [new Type(Type::BUILTIN_TYPE_INT)]],
];
}
}

class PhpStanOmittedParamTagTypeDocBlock
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\PropertyInfo\Tests\Fixtures;

class IntRangeDummy
{
/**
* @var int<0, 100>
*/
public $a;

/**
* @var int<min, 100>|null
*/
public $b;

/**
* @var int<50, max>
*/
public $c;
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ private function extractTypes(TypeNode $node, NameScope $nameScope): array
if ($node instanceof GenericTypeNode) {
[$mainType] = $this->extractTypes($node->type, $nameScope);

if (Type::BUILTIN_TYPE_INT === $mainType->getBuiltinType()) {
return [$mainType];
}

$collectionKeyTypes = $mainType->getCollectionKeyTypes();
$collectionKeyValues = [];
if (1 === \count($node->genericTypes)) {
Expand Down