Skip to content

Commit 42b2378

Browse files
committed
Conditional, ConditionalForParameter, IntMask, IntMaskOf, KeyOf, OffsetAccess, ValueOf
1 parent 8ad3753 commit 42b2378

17 files changed

Lines changed: 907 additions & 13 deletions

src/PseudoTypes/Conditional.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/*
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @link http://phpdoc.org
9+
*
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Mixed_;
19+
20+
use function sprintf;
21+
22+
/**
23+
* Value Object representing the conditional type.
24+
*
25+
* @psalm-immutable
26+
*/
27+
final class Conditional implements PseudoType
28+
{
29+
/** @var bool */
30+
private $negated;
31+
/** @var Type */
32+
private $subjectType;
33+
/** @var Type */
34+
private $targetType;
35+
/** @var Type */
36+
private $if;
37+
/** @var Type */
38+
private $else;
39+
40+
public function __construct(bool $negated, Type $subjectType, Type $targetType, Type $if, Type $else)
41+
{
42+
$this->negated = $negated;
43+
$this->subjectType = $subjectType;
44+
$this->targetType = $targetType;
45+
$this->if = $if;
46+
$this->else = $else;
47+
}
48+
49+
public function isNegated(): bool
50+
{
51+
return $this->negated;
52+
}
53+
54+
public function getSubjectType(): Type
55+
{
56+
return $this->subjectType;
57+
}
58+
59+
public function getTargetType(): Type
60+
{
61+
return $this->targetType;
62+
}
63+
64+
public function getIf(): Type
65+
{
66+
return $this->if;
67+
}
68+
69+
public function getElse(): Type
70+
{
71+
return $this->else;
72+
}
73+
74+
public function underlyingType(): Type
75+
{
76+
return new Mixed_();
77+
}
78+
79+
public function __toString(): string
80+
{
81+
return sprintf(
82+
'(%s %s %s ? %s : %s)',
83+
$this->subjectType,
84+
$this->negated ? 'is not' : 'is',
85+
$this->targetType,
86+
$this->if,
87+
$this->else
88+
);
89+
}
90+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/*
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @link http://phpdoc.org
9+
*
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Mixed_;
19+
20+
use function sprintf;
21+
22+
/**
23+
* Value Object representing the conditional type for parameter.
24+
*
25+
* @psalm-immutable
26+
*/
27+
final class ConditionalForParameter implements PseudoType
28+
{
29+
/** @var bool */
30+
private $negated;
31+
/** @var string */
32+
private $parameterName;
33+
/** @var Type */
34+
private $targetType;
35+
/** @var Type */
36+
private $if;
37+
/** @var Type */
38+
private $else;
39+
40+
public function __construct(bool $negated, string $parameterName, Type $targetType, Type $if, Type $else)
41+
{
42+
$this->negated = $negated;
43+
$this->parameterName = $parameterName;
44+
$this->targetType = $targetType;
45+
$this->if = $if;
46+
$this->else = $else;
47+
}
48+
49+
public function isNegated(): bool
50+
{
51+
return $this->negated;
52+
}
53+
54+
public function getParameterName(): string
55+
{
56+
return $this->parameterName;
57+
}
58+
59+
public function getTargetType(): Type
60+
{
61+
return $this->targetType;
62+
}
63+
64+
public function getIf(): Type
65+
{
66+
return $this->if;
67+
}
68+
69+
public function getElse(): Type
70+
{
71+
return $this->else;
72+
}
73+
74+
public function underlyingType(): Type
75+
{
76+
return new Mixed_();
77+
}
78+
79+
public function __toString(): string
80+
{
81+
return sprintf(
82+
'(%s %s %s ? %s : %s)',
83+
'$' . $this->parameterName,
84+
$this->negated ? 'is not' : 'is',
85+
$this->targetType,
86+
$this->if,
87+
$this->else
88+
);
89+
}
90+
}

src/PseudoTypes/IntMask.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/*
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @link http://phpdoc.org
9+
*
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Integer;
19+
20+
/**
21+
* Value Object representing the `int-mask` type.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class IntMask implements PseudoType
26+
{
27+
/** @var Type[] */
28+
private $types;
29+
30+
public function __construct(Type ...$types)
31+
{
32+
$this->types = $types;
33+
}
34+
35+
/**
36+
* @return Type[]
37+
*/
38+
public function getTypes(): array
39+
{
40+
return $this->types;
41+
}
42+
43+
public function underlyingType(): Type
44+
{
45+
return new Integer();
46+
}
47+
48+
public function __toString(): string
49+
{
50+
return 'int-mask<' . implode(', ', $this->types) . '>';
51+
}
52+
}

src/PseudoTypes/IntMaskOf.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/*
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @link http://phpdoc.org
9+
*
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Integer;
19+
20+
/**
21+
* Value Object representing the `int-mask-of` type.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class IntMaskOf implements PseudoType
26+
{
27+
/** @var Type */
28+
private $type;
29+
30+
public function __construct(Type $type)
31+
{
32+
$this->type = $type;
33+
}
34+
35+
public function getType(): Type
36+
{
37+
return $this->type;
38+
}
39+
40+
public function underlyingType(): Type
41+
{
42+
return new Integer();
43+
}
44+
45+
public function __toString(): string
46+
{
47+
return "int-mask-of<{$this->type}>";
48+
}
49+
}

src/PseudoTypes/KeyOf.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/*
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @link http://phpdoc.org
9+
*
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\ArrayKey;
19+
20+
/**
21+
* Value Object representing the `key-of` type.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class KeyOf implements PseudoType
26+
{
27+
/** @var Type */
28+
private $type;
29+
30+
public function __construct(Type $type)
31+
{
32+
$this->type = $type;
33+
}
34+
35+
public function getType(): Type
36+
{
37+
return $this->type;
38+
}
39+
40+
public function underlyingType(): Type
41+
{
42+
return new ArrayKey();
43+
}
44+
45+
public function __toString(): string
46+
{
47+
return "key-of<{$this->type}>";
48+
}
49+
}

0 commit comments

Comments
 (0)