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
90 changes: 90 additions & 0 deletions src/PseudoTypes/Conditional.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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\Mixed_;

use function sprintf;

/**
* Value Object representing the conditional type.
*
* @psalm-immutable
*/
final class Conditional extends Mixed_ implements PseudoType
{
/** @var bool */
private $negated;
/** @var Type */
private $subjectType;
/** @var Type */
private $targetType;
/** @var Type */
private $if;
/** @var Type */
private $else;

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

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

public function getSubjectType(): Type
{
return $this->subjectType;
}

public function getTargetType(): Type
{
return $this->targetType;
}

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

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

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

public function __toString(): string
{
return sprintf(
'(%s %s %s ? %s : %s)',
(string) $this->subjectType,
$this->negated ? 'is not' : 'is',
(string) $this->targetType,
(string) $this->if,
(string) $this->else
);
}
}
90 changes: 90 additions & 0 deletions src/PseudoTypes/ConditionalForParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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\Mixed_;

use function sprintf;

/**
* Value Object representing the conditional type for parameter.
*
* @psalm-immutable
*/
final class ConditionalForParameter extends Mixed_ implements PseudoType
{
/** @var bool */
private $negated;
/** @var string */
private $parameterName;
/** @var Type */
private $targetType;
/** @var Type */
private $if;
/** @var Type */
private $else;

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

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

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

public function getTargetType(): Type
{
return $this->targetType;
}

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

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

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

public function __toString(): string
{
return sprintf(
'(%s %s %s ? %s : %s)',
'$' . $this->parameterName,
$this->negated ? 'is not' : 'is',
(string) $this->targetType,
(string) $this->if,
(string) $this->else
);
}
}
54 changes: 54 additions & 0 deletions src/PseudoTypes/IntMask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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\Integer;

use function implode;

/**
* Value Object representing the `int-mask` type.
*
* @psalm-immutable
*/
final class IntMask extends Integer implements PseudoType
{
/** @var Type[] */
private $types;

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

/**
* @return Type[]
*/
public function getTypes(): array
{
return $this->types;
}

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

public function __toString(): string
{
return 'int-mask<' . implode(', ', $this->types) . '>';
}
}
49 changes: 49 additions & 0 deletions src/PseudoTypes/IntMaskOf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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\Integer;

/**
* Value Object representing the `int-mask-of` type.
*
* @psalm-immutable
*/
final class IntMaskOf extends Integer implements PseudoType
{
/** @var Type */
private $type;

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

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

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

public function __toString(): string
{
return 'int-mask-of<' . $this->type . '>';
}
}
49 changes: 49 additions & 0 deletions src/PseudoTypes/KeyOf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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\ArrayKey;

/**
* Value Object representing the `key-of` type.
*
* @psalm-immutable
*/
final class KeyOf extends ArrayKey implements PseudoType
{
/** @var Type */
private $type;

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

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

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

public function __toString(): string
{
return 'key-of<' . $this->type . '>';
}
}
Loading