Skip to content

Commit b6a886b

Browse files
author
smoench
committed
support psalm scalar types
1 parent 6a467b8 commit b6a886b

14 files changed

+418
-8
lines changed

src/PseudoTypes/CallableString.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\String_;
19+
20+
/**
21+
* Value Object representing the type 'string'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class CallableString extends String_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new String_();
30+
}
31+
32+
/**
33+
* Returns a rendered output of the Type as it would be used in a DocBlock.
34+
*/
35+
public function __toString() : string
36+
{
37+
return 'callable-string';
38+
}
39+
}

src/PseudoTypes/HtmlEscapedString.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\String_;
19+
20+
/**
21+
* Value Object representing the type 'string'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class HtmlEscapedString extends String_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new String_();
30+
}
31+
32+
/**
33+
* Returns a rendered output of the Type as it would be used in a DocBlock.
34+
*/
35+
public function __toString() : string
36+
{
37+
return 'html-escaped-string';
38+
}
39+
}

src/PseudoTypes/LowercaseString.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\String_;
19+
20+
/**
21+
* Value Object representing the type 'string'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class LowercaseString extends String_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new String_();
30+
}
31+
32+
/**
33+
* Returns a rendered output of the Type as it would be used in a DocBlock.
34+
*/
35+
public function __toString() : string
36+
{
37+
return 'lowercase-string';
38+
}
39+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\String_;
19+
20+
/**
21+
* Value Object representing the type 'string'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NonEmptyLowercaseString extends String_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new String_();
30+
}
31+
32+
/**
33+
* Returns a rendered output of the Type as it would be used in a DocBlock.
34+
*/
35+
public function __toString() : string
36+
{
37+
return 'non-empty-lowercase-string';
38+
}
39+
}

src/PseudoTypes/NonEmptyString.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\String_;
19+
20+
/**
21+
* Value Object representing the type 'string'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NonEmptyString extends String_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new String_();
30+
}
31+
32+
/**
33+
* Returns a rendered output of the Type as it would be used in a DocBlock.
34+
*/
35+
public function __toString() : string
36+
{
37+
return 'non-empty-string';
38+
}
39+
}

src/PseudoTypes/NumericString.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\String_;
19+
20+
/**
21+
* Value Object representing the type 'string'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class NumericString extends String_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new String_();
30+
}
31+
32+
/**
33+
* Returns a rendered output of the Type as it would be used in a DocBlock.
34+
*/
35+
public function __toString() : string
36+
{
37+
return 'numeric-string';
38+
}
39+
}

src/PseudoTypes/PositiveInteger.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Integer;
19+
use phpDocumentor\Reflection\Types\String_;
20+
21+
/**
22+
* Value Object representing the type 'string'.
23+
*
24+
* @psalm-immutable
25+
*/
26+
final class PositiveInteger extends Integer implements PseudoType
27+
{
28+
public function underlyingType(): Type
29+
{
30+
return new Integer();
31+
}
32+
33+
/**
34+
* Returns a rendered output of the Type as it would be used in a DocBlock.
35+
*/
36+
public function __toString() : string
37+
{
38+
return 'positive-int';
39+
}
40+
}

src/PseudoTypes/TraitString.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\PseudoTypes;
15+
16+
use phpDocumentor\Reflection\PseudoType;
17+
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\String_;
19+
20+
/**
21+
* Value Object representing the type 'string'.
22+
*
23+
* @psalm-immutable
24+
*/
25+
final class TraitString extends String_ implements PseudoType
26+
{
27+
public function underlyingType(): Type
28+
{
29+
return new String_();
30+
}
31+
32+
/**
33+
* Returns a rendered output of the Type as it would be used in a DocBlock.
34+
*/
35+
public function __toString() : string
36+
{
37+
return 'trait-string';
38+
}
39+
}

src/TypeResolver.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,29 +71,38 @@ final class TypeResolver
7171
private $keywords = [
7272
'string' => Types\String_::class,
7373
'class-string' => Types\ClassString::class,
74+
'html-escaped-string' => PseudoTypes\HtmlEscapedString::class,
75+
'lowercase-string' => PseudoTypes\LowercaseString::class,
76+
'non-empty-lowercase-string' => PseudoTypes\NonEmptyLowercaseString::class,
77+
'non-empty-string' => PseudoTypes\NonEmptyString::class,
78+
'numeric-string' => PseudoTypes\NumericString::class,
79+
'trait-string' => PseudoTypes\TraitString::class,
7480
'int' => Types\Integer::class,
7581
'integer' => Types\Integer::class,
82+
'positive-int' => PseudoTypes\PositiveInteger::class,
7683
'bool' => Types\Boolean::class,
7784
'boolean' => Types\Boolean::class,
7885
'real' => Types\Float_::class,
7986
'float' => Types\Float_::class,
8087
'double' => Types\Float_::class,
81-
'object' => Object_::class,
88+
'object' => Types\Object_::class,
8289
'mixed' => Types\Mixed_::class,
83-
'array' => Array_::class,
90+
'array' => Types\Array_::class,
91+
'array-key' => Types\ArrayKey::class,
8492
'resource' => Types\Resource_::class,
8593
'void' => Types\Void_::class,
8694
'null' => Types\Null_::class,
8795
'scalar' => Types\Scalar::class,
8896
'callback' => Types\Callable_::class,
8997
'callable' => Types\Callable_::class,
98+
'callable-string' => PseudoTypes\CallableString::class,
9099
'false' => PseudoTypes\False_::class,
91100
'true' => PseudoTypes\True_::class,
92101
'self' => Types\Self_::class,
93102
'$this' => Types\This::class,
94103
'static' => Types\Static_::class,
95104
'parent' => Types\Parent_::class,
96-
'iterable' => Iterable_::class,
105+
'iterable' => Types\Iterable_::class,
97106
];
98107

99108
/**

src/Types/ArrayKey.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link http://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Reflection\Types;
15+
16+
/**
17+
* Value Object representing a array-key Type.
18+
*
19+
* A array-key Type is the supertype (but not a union) of int and string.
20+
*
21+
* @psalm-immutable
22+
*/
23+
final class ArrayKey extends AggregatedType
24+
{
25+
public function __construct()
26+
{
27+
parent::__construct([new String_(), new Integer()], '|');
28+
}
29+
30+
public function __toString() : string
31+
{
32+
return 'array-key';
33+
}
34+
}

0 commit comments

Comments
 (0)