Skip to content

Commit 672783c

Browse files
authored
Refactor types (#261)
* Fix description for `Intersection` * Refactor the `Scalar` type
1 parent 6920f4a commit 672783c

File tree

6 files changed

+55
-31
lines changed

6 files changed

+55
-31
lines changed
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,28 @@
1111
* @link http://phpdoc.org
1212
*/
1313

14-
namespace phpDocumentor\Reflection\Types;
14+
namespace phpDocumentor\Reflection\PseudoTypes;
1515

16+
use phpDocumentor\Reflection\PseudoType;
1617
use phpDocumentor\Reflection\Type;
18+
use phpDocumentor\Reflection\Types\Boolean;
19+
use phpDocumentor\Reflection\Types\Compound;
20+
use phpDocumentor\Reflection\Types\Float_;
21+
use phpDocumentor\Reflection\Types\Integer;
22+
use phpDocumentor\Reflection\Types\String_;
1723

1824
/**
1925
* Value Object representing the 'scalar' pseudo-type, which is either a string, integer, float or boolean.
2026
*
2127
* @psalm-immutable
2228
*/
23-
final class Scalar implements Type
29+
final class Scalar implements PseudoType
2430
{
31+
public function underlyingType(): Type
32+
{
33+
return new Compound([new String_(), new Integer(), new Float_(), new Boolean()]);
34+
}
35+
2536
/**
2637
* Returns a rendered output of the Type as it would be used in a DocBlock.
2738
*/

src/TypeResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use phpDocumentor\Reflection\PseudoTypes\ObjectShapeItem;
5151
use phpDocumentor\Reflection\PseudoTypes\OffsetAccess;
5252
use phpDocumentor\Reflection\PseudoTypes\PositiveInteger;
53+
use phpDocumentor\Reflection\PseudoTypes\Scalar;
5354
use phpDocumentor\Reflection\PseudoTypes\StringValue;
5455
use phpDocumentor\Reflection\PseudoTypes\TraitString;
5556
use phpDocumentor\Reflection\PseudoTypes\True_;
@@ -73,7 +74,6 @@
7374
use phpDocumentor\Reflection\Types\Object_;
7475
use phpDocumentor\Reflection\Types\Parent_;
7576
use phpDocumentor\Reflection\Types\Resource_;
76-
use phpDocumentor\Reflection\Types\Scalar;
7777
use phpDocumentor\Reflection\Types\Self_;
7878
use phpDocumentor\Reflection\Types\Static_;
7979
use phpDocumentor\Reflection\Types\String_;

src/Types/Intersection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use phpDocumentor\Reflection\Type;
1616

1717
/**
18-
* Value Object representing a Compound Type.
18+
* Value Object representing a Intersection Type.
1919
*
2020
* A Intersection Type is not so much a special keyword or object reference but is a series of Types that are separated
2121
* using an AND operator (`&`). This combination of types signifies that whatever is associated with this Intersection
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\Types\Boolean;
17+
use phpDocumentor\Reflection\Types\Compound;
18+
use phpDocumentor\Reflection\Types\Float_;
19+
use phpDocumentor\Reflection\Types\Integer;
20+
use phpDocumentor\Reflection\Types\String_;
21+
use PHPUnit\Framework\TestCase;
22+
23+
final class ScalarTest extends TestCase
24+
{
25+
public function testCreate(): void
26+
{
27+
$type = new Scalar();
28+
29+
$expectedUnderlyingType = new Compound([new String_(), new Integer(), new Float_(), new Boolean()]);
30+
$this->assertEquals($expectedUnderlyingType, $type->underlyingType());
31+
}
32+
33+
public function testToString(): void
34+
{
35+
$type = new Scalar();
36+
37+
$this->assertSame('scalar', (string) $type);
38+
}
39+
}

tests/unit/TypeResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
use phpDocumentor\Reflection\PseudoTypes\ObjectShapeItem;
5151
use phpDocumentor\Reflection\PseudoTypes\OffsetAccess;
5252
use phpDocumentor\Reflection\PseudoTypes\PositiveInteger;
53+
use phpDocumentor\Reflection\PseudoTypes\Scalar;
5354
use phpDocumentor\Reflection\PseudoTypes\StringValue;
5455
use phpDocumentor\Reflection\PseudoTypes\TraitString;
5556
use phpDocumentor\Reflection\PseudoTypes\True_;
@@ -72,7 +73,6 @@
7273
use phpDocumentor\Reflection\Types\Object_;
7374
use phpDocumentor\Reflection\Types\Parent_;
7475
use phpDocumentor\Reflection\Types\Resource_;
75-
use phpDocumentor\Reflection\Types\Scalar;
7676
use phpDocumentor\Reflection\Types\Self_;
7777
use phpDocumentor\Reflection\Types\Static_;
7878
use phpDocumentor\Reflection\Types\String_;

tests/unit/Types/ScalarTest.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)