Skip to content
Open
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
27 changes: 27 additions & 0 deletions src/PseudoTypes/PrivatePropertiesOf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/*
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*
*/

declare(strict_types=1);

namespace phpDocumentor\Reflection\PseudoTypes;

/**
* Value Object representing the `private-properties-of` type.
*
* @psalm-immutable
*/
final class PrivatePropertiesOf extends PropertiesOf
{
public function __toString(): string
{
return 'private-properties-of<' . $this->type . '>';
}
}
53 changes: 53 additions & 0 deletions src/PseudoTypes/PropertiesOf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/*
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*
*/

declare(strict_types=1);

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\String_;

/**
* Value Object representing the `properties-of` type.
*
* @psalm-immutable
*/
class PropertiesOf extends Array_ implements PseudoType
{
/** @var Type */
protected $type;

public function __construct(Type $type)
{
parent::__construct(new Mixed_(), new String_());

$this->type = $type;
}

public function getType(): Type
{
return $this->type;
}

public function underlyingType(): Type
{
return new Array_(new Mixed_(), new String_());
}

public function __toString(): string
{
return 'properties-of<' . $this->type . '>';
}
}
27 changes: 27 additions & 0 deletions src/PseudoTypes/ProtectedPropertiesOf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/*
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*
*/

declare(strict_types=1);

namespace phpDocumentor\Reflection\PseudoTypes;

/**
* Value Object representing the `protected-properties-of` type.
*
* @psalm-immutable
*/
final class ProtectedPropertiesOf extends PropertiesOf
{
public function __toString(): string
{
return 'protected-properties-of<' . $this->type . '>';
}
}
27 changes: 27 additions & 0 deletions src/PseudoTypes/PublicPropertiesOf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/*
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @link http://phpdoc.org
*
*/

declare(strict_types=1);

namespace phpDocumentor\Reflection\PseudoTypes;

/**
* Value Object representing the `public-properties-of` type.
*
* @psalm-immutable
*/
final class PublicPropertiesOf extends PropertiesOf
{
public function __toString(): string
{
return 'public-properties-of<' . $this->type . '>';
}
}
16 changes: 16 additions & 0 deletions src/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
use phpDocumentor\Reflection\PseudoTypes\ObjectShapeItem;
use phpDocumentor\Reflection\PseudoTypes\OffsetAccess;
use phpDocumentor\Reflection\PseudoTypes\PositiveInteger;
use phpDocumentor\Reflection\PseudoTypes\PrivatePropertiesOf;
use phpDocumentor\Reflection\PseudoTypes\PropertiesOf;
use phpDocumentor\Reflection\PseudoTypes\ProtectedPropertiesOf;
use phpDocumentor\Reflection\PseudoTypes\PublicPropertiesOf;
use phpDocumentor\Reflection\PseudoTypes\Scalar;
use phpDocumentor\Reflection\PseudoTypes\StringValue;
use phpDocumentor\Reflection\PseudoTypes\TraitString;
Expand Down Expand Up @@ -440,6 +444,18 @@ private function createFromGeneric(GenericTypeNode $type, Context $context): Typ
case 'value-of':
return new ValueOf($this->createType($type->genericTypes[0], $context));

case 'properties-of':
return new PropertiesOf($this->createType($type->genericTypes[0], $context));

case 'public-properties-of':
return new PublicPropertiesOf($this->createType($type->genericTypes[0], $context));

case 'protected-properties-of':
return new ProtectedPropertiesOf($this->createType($type->genericTypes[0], $context));

case 'private-properties-of':
return new PrivatePropertiesOf($this->createType($type->genericTypes[0], $context));

case 'int-mask':
return new IntMask(...$this->createTypesByTypeNodes($type->genericTypes, $context));

Expand Down
18 changes: 18 additions & 0 deletions tests/unit/PseudoTypes/PrivatePropertiesOfTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Self_;
use PHPUnit\Framework\TestCase;

final class PrivatePropertiesOfTest extends TestCase
{
public function testToString(): void
{
$type = new PrivatePropertiesOf(new Self_());

$this->assertSame('private-properties-of<self>', (string) $type);
}
}
32 changes: 32 additions & 0 deletions tests/unit/PseudoTypes/PropertiesOfTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Mixed_;
use phpDocumentor\Reflection\Types\Self_;
use phpDocumentor\Reflection\Types\String_;
use PHPUnit\Framework\TestCase;

final class PropertiesOfTest extends TestCase
{
public function testCreate(): void
{
$childType = new Self_();
$type = new PropertiesOf($childType);

$this->assertSame($childType, $type->getType());
$this->assertEquals(new Array_(new Mixed_(), new String_()), $type->underlyingType());
$this->assertEquals(new String_(), $type->getKeyType());
$this->assertEquals(new Mixed_(), $type->getValueType());
}

public function testToString(): void
{
$type = new PropertiesOf(new Self_());

$this->assertSame('properties-of<self>', (string) $type);
}
}
18 changes: 18 additions & 0 deletions tests/unit/PseudoTypes/ProtectedPropertiesOfTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Self_;
use PHPUnit\Framework\TestCase;

final class ProtectedPropertiesOfTest extends TestCase
{
public function testToString(): void
{
$type = new ProtectedPropertiesOf(new Self_());

$this->assertSame('protected-properties-of<self>', (string) $type);
}
}
18 changes: 18 additions & 0 deletions tests/unit/PseudoTypes/PublicPropertiesOfTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Self_;
use PHPUnit\Framework\TestCase;

final class PublicPropertiesOfTest extends TestCase
{
public function testToString(): void
{
$type = new PublicPropertiesOf(new Self_());

$this->assertSame('public-properties-of<self>', (string) $type);
}
}
20 changes: 20 additions & 0 deletions tests/unit/TypeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
use phpDocumentor\Reflection\PseudoTypes\ObjectShapeItem;
use phpDocumentor\Reflection\PseudoTypes\OffsetAccess;
use phpDocumentor\Reflection\PseudoTypes\PositiveInteger;
use phpDocumentor\Reflection\PseudoTypes\PrivatePropertiesOf;
use phpDocumentor\Reflection\PseudoTypes\PropertiesOf;
use phpDocumentor\Reflection\PseudoTypes\ProtectedPropertiesOf;
use phpDocumentor\Reflection\PseudoTypes\PublicPropertiesOf;
use phpDocumentor\Reflection\PseudoTypes\Scalar;
use phpDocumentor\Reflection\PseudoTypes\StringValue;
use phpDocumentor\Reflection\PseudoTypes\TraitString;
Expand Down Expand Up @@ -1122,6 +1126,22 @@ public function genericsProvider(): array
'non-empty-list<mixed>',
new NonEmptyList(new Mixed_()),
],
[
'properties-of<self>',
new PropertiesOf(new Self_()),
],
[
'public-properties-of<self>',
new PublicPropertiesOf(new Self_()),
],
[
'protected-properties-of<self>',
new ProtectedPropertiesOf(new Self_()),
],
[
'private-properties-of<self>',
new PrivatePropertiesOf(new Self_()),
],
];
}

Expand Down