Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the support for array<key, value> syntax #51

Merged
merged 1 commit into from
Aug 28, 2023
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
3 changes: 2 additions & 1 deletion src/Constraint/Typehint/PhpDocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function getReturnTypehint(string $originalDocComment): ?string
return null;
}

$docComment = preg_replace('/array<(.*?),\s(.*?)>/', 'array<$1,$2>', $docComment);
// Convert array<int, string> to array<int,string>
$docComment = preg_replace('/(\w+)<(.*?),\s(.*?)>/', '$1<$2,$3>', $docComment);
if ($docComment === null) {
return null; // @codeCoverageIgnore
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);

namespace DigitalRevolution\AccessorPairConstraint\Tests\Integration\data\success\Regular\Types\CompoundTypes;

class IterableTypedFullProperty
{
/** @var iterable<int, stdClass> */
private $property = false;

/**
* @return iterable<int, stdClass>
*/
public function getProperty(): iterable
{
return $this->property;
}

/**
* @param iterable<int, stdClass> $property
*/
public function setProperty(iterable $property): self
{
$this->property = $property;

return $this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

namespace DigitalRevolution\AccessorPairConstraint\Tests\Unit\Constraint\Typehint\data\All\DocComment;

use ArrayIterator;
use DigitalRevolution\AccessorPairConstraint\Tests\Unit\Constraint\Typehint\DataInterface;
use phpDocumentor\Reflection\Fqsen;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Collection;
use phpDocumentor\Reflection\Types\String_;

class IteratorTypedFull implements DataInterface
{
/**
* @param ArrayIterator<string, string> $param
*
* @return ArrayIterator<string, string>
*/
public function testMethod(ArrayIterator $param): ArrayIterator
{
return $param;
}

public function getExpectedType(): Type
{
return new Collection(new Fqsen('\\' . ArrayIterator::class), new String_(), new String_());
}
}