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

Add new types #211

Open
wants to merge 12 commits into
base: 1.x
Choose a base branch
from
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
71 changes: 71 additions & 0 deletions src/PseudoTypes/AbstractConditional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

/**
* 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
*/

namespace phpDocumentor\Reflection\PseudoTypes;

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

/**
* Represents a conditional. This is an abstract class for Conditional and ConditionalParameter.
*
* @psalm-immutable
*/
abstract class AbstractConditional extends Mixed_ implements PseudoType
{
/** @var Type */
protected $target;

/** @var Type */
protected $if;

/** @var Type */
protected $else;

/** @var bool */
protected $negated;

public function __construct(Type $target, Type $if, Type $else, bool $negated)
{
$this->target = $target;
$this->if = $if;
$this->else = $else;
$this->negated = $negated;
}

public function getTarget(): Type
{
return $this->target;
}

public function getIf(): Type
{
return $this->if;
}

public function getElse(): Type
{
return $this->else;
}

public function getNegated(): bool
{
return $this->negated;
}

public function underlyingType(): Type
{
return new Mixed_();
}
}
2 changes: 1 addition & 1 deletion src/PseudoTypes/ArrayShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use function implode;

/** @psalm-immutable */
class ArrayShape implements PseudoType
class ArrayShape extends Array_ implements PseudoType
{
/** @var ArrayShapeItem[] */
private $items;
Expand Down
39 changes: 39 additions & 0 deletions src/PseudoTypes/ClosedResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/**
* 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
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Types\Resource_;

/**
* Value Object representing the 'closed-resource' Type.
*
* @psalm-immutable
*/
final class ClosedResource extends Resource_ implements PseudoType
{
public function underlyingType(): Type
{
return new Resource_();
}

/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'closed-resource';
}
}
51 changes: 51 additions & 0 deletions src/PseudoTypes/Conditional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/**
* 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
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Type;

use function sprintf;

/** @psalm-immutable */
final class Conditional extends AbstractConditional
{
/** @var Type */
private $subject;

public function __construct(Type $subject, Type $target, Type $if, Type $else, bool $negated)
{
parent::__construct($target, $if, $else, $negated);
$this->subject = $subject;
}

public function getSubject(): Type
{
return $this->subject;
}

/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return sprintf(
'(%s %s %s ? %s : %s)',
$this->subject,
$this->negated ? 'is not' : 'is',
$this->target,
$this->if,
$this->else
);
}
}
51 changes: 51 additions & 0 deletions src/PseudoTypes/ConditionalParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/**
* 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
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Type;

use function sprintf;

/** @psalm-immutable */
final class ConditionalParameter extends AbstractConditional
{
/** @var string */
private $parameter;

public function __construct(string $parameter, Type $target, Type $if, Type $else, bool $negated)
{
parent::__construct($target, $if, $else, $negated);
$this->parameter = $parameter;
}

public function getParameterName(): string
{
return $this->parameter;
}

/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return sprintf(
'(%s %s %s ? %s : %s)',
$this->parameter,
$this->negated ? 'is not' : 'is',
$this->target,
$this->if,
$this->else
);
}
}
2 changes: 1 addition & 1 deletion src/PseudoTypes/ConstExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use function sprintf;

/** @psalm-immutable */
final class ConstExpression implements PseudoType
final class ConstExpression extends Mixed_ implements PseudoType
{
/** @var Type */
private $owner;
Expand Down
2 changes: 1 addition & 1 deletion src/PseudoTypes/FloatValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use phpDocumentor\Reflection\Types\Float_;

/** @psalm-immutable */
class FloatValue implements PseudoType
final class FloatValue extends Float_ implements PseudoType
{
/** @var float */
private $value;
Expand Down
42 changes: 42 additions & 0 deletions src/PseudoTypes/IntMask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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\Type;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\AggregatedType;

/** @psalm-immutable */
final class IntMask extends AggregatedType implements PseudoType
{
public function __construct(array $types)
{
parent::__construct($types, ', ');
}

public function underlyingType(): Type
{
return new Compound([new Integer()]);
}

/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'int-mask<' . parent::__toString() . '>';
}
}
42 changes: 42 additions & 0 deletions src/PseudoTypes/IntMaskOf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?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\Type;
use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Types\Integer;
use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\AggregatedType;

/** @psalm-immutable */
final class IntMaskOf extends AggregatedType implements PseudoType
{
public function __construct(array $types)
{
parent::__construct($types, '| ');
}

public function underlyingType(): Type
{
return new Compound([new Integer()]);
}

/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'int-mask-of<' . parent::__toString() . '>';
}
}
2 changes: 1 addition & 1 deletion src/PseudoTypes/IntegerValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use phpDocumentor\Reflection\Types\Integer;

/** @psalm-immutable */
final class IntegerValue implements PseudoType
final class IntegerValue extends Integer implements PseudoType
{
/** @var int */
private $value;
Expand Down
48 changes: 48 additions & 0 deletions src/PseudoTypes/KeyOf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/**
* 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
*/

namespace phpDocumentor\Reflection\PseudoTypes;

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

/** @psalm-immutable */
final class KeyOf extends Mixed_ implements PseudoType
{
/** @var Type */
protected $keyType;

public function __construct(Type $keyType)
{
$this->keyType = $keyType;
}

public function getKeyType(): Type
{
return $this->keyType;
}

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

/**
* Returns a rendered output of the Type as it would be used in a DocBlock.
*/
public function __toString(): string
{
return 'key-of<' . $this->keyType . '>';
}
}
2 changes: 1 addition & 1 deletion src/PseudoTypes/ObjectShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use function implode;

/** @psalm-immutable */
final class ObjectShape implements PseudoType
final class ObjectShape extends Object_ implements PseudoType
{
/** @var ObjectShapeItem[] */
private $items;
Expand Down
Loading
Loading