Skip to content

Commit e21c0bd

Browse files
authored
Merge pull request #113 from phpDocumentor/add-pseudo-type-support-and-use-true-and-false
Add true and false as PseudoTypes
2 parents 11a18d0 + c5c9889 commit e21c0bd

File tree

12 files changed

+251
-65
lines changed

12 files changed

+251
-65
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ phpcs:
1919
phpcbf:
2020
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpcs-ga:latest phpcbf
2121

22-
2322
.PHONY: phpstan
2423
phpstan:
2524
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpstan-ga:latest analyse src --no-progress --configuration phpstan.neon
2625

27-
.PHONY: psaml
26+
.PHONY: psalm
2827
psalm:
2928
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.2 tools/psalm
29+
3030
.PHONY: test
3131
test:
3232
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.2 tools/phpunit

phpcs.xml.dist

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<ruleset name="phpDocumentor">
3-
<description>The coding standard for phpDocumentor.</description>
3+
<description>The coding standard for phpDocumentor.</description>
44

55
<file>src</file>
66
<file>tests/unit</file>
@@ -13,4 +13,9 @@
1313
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix">
1414
<exclude-pattern>*/src/*/Abstract*.php</exclude-pattern>
1515
</rule>
16+
17+
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
18+
<exclude-pattern>*/src/PseudoTypes/False_.php</exclude-pattern>
19+
<exclude-pattern>*/src/PseudoTypes/True_.php</exclude-pattern>
20+
</rule>
1621
</ruleset>

src/PseudoType.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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;
15+
16+
interface PseudoType extends Type
17+
{
18+
public function underlyingType() : Type;
19+
}

src/PseudoTypes/False_.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 https://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\Boolean;
19+
use function class_alias;
20+
21+
/**
22+
* Value Object representing the PseudoType 'False', which is a Boolean type.
23+
*
24+
* @psalm-immutable
25+
*/
26+
final class False_ extends Boolean implements PseudoType
27+
{
28+
public function underlyingType() : Type
29+
{
30+
return new Boolean();
31+
}
32+
33+
public function __toString() : string
34+
{
35+
return 'false';
36+
}
37+
}
38+
39+
class_alias('\phpDocumentor\Reflection\PseudoTypes\False_', 'phpDocumentor\Reflection\Types\False_', false);

src/PseudoTypes/True_.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 https://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\Boolean;
19+
use function class_alias;
20+
21+
/**
22+
* Value Object representing the PseudoType 'False', which is a Boolean type.
23+
*
24+
* @psalm-immutable
25+
*/
26+
final class True_ extends Boolean implements PseudoType
27+
{
28+
public function underlyingType() : Type
29+
{
30+
return new Boolean();
31+
}
32+
33+
public function __toString() : string
34+
{
35+
return 'true';
36+
}
37+
}
38+
39+
class_alias('\phpDocumentor\Reflection\PseudoTypes\True_', 'phpDocumentor\Reflection\Types\True_', false);

src/TypeResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ final class TypeResolver
8787
'scalar' => Types\Scalar::class,
8888
'callback' => Types\Callable_::class,
8989
'callable' => Types\Callable_::class,
90-
'false' => Types\False_::class,
91-
'true' => Types\True_::class,
90+
'false' => PseudoTypes\False_::class,
91+
'true' => PseudoTypes\True_::class,
9292
'self' => Types\Self_::class,
9393
'$this' => Types\This::class,
9494
'static' => Types\Static_::class,

src/Types/False_.php

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

src/Types/True_.php

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

tests/unit/PseudoTypes/FalseTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* @coversDefaultClass \phpDocumentor\Reflection\PseudoTypes\False_
21+
*/
22+
final class FalseTest extends TestCase
23+
{
24+
/**
25+
* @covers ::underlyingType
26+
*/
27+
public function testExposesUnderlyingType() : void
28+
{
29+
$false = new False_();
30+
31+
$this->assertInstanceOf(Boolean::class, $false->underlyingType());
32+
}
33+
34+
/**
35+
* @covers ::__toString
36+
*/
37+
public function testFalseStringifyCorrectly() : void
38+
{
39+
$false = new False_();
40+
41+
$this->assertSame('false', (string) $false);
42+
}
43+
44+
/**
45+
* @covers \phpDocumentor\Reflection\PseudoTypes\False_
46+
*/
47+
public function testCanBeInstantiatedUsingDeprecatedFqsen() : void
48+
{
49+
$false = new \phpDocumentor\Reflection\Types\False_();
50+
51+
$this->assertSame('false', (string) $false);
52+
$this->assertInstanceOf(False_::class, $false);
53+
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\False_::class, $false);
54+
}
55+
}

tests/unit/PseudoTypes/TrueTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* @coversDefaultClass \phpDocumentor\Reflection\PseudoTypes\True_
21+
*/
22+
class TrueTest extends TestCase
23+
{
24+
/**
25+
* @covers ::underlyingType
26+
*/
27+
public function testExposesUnderlyingType() : void
28+
{
29+
$true = new True_();
30+
31+
$this->assertInstanceOf(Boolean::class, $true->underlyingType());
32+
}
33+
34+
/**
35+
* @covers ::__toString
36+
*/
37+
public function testTrueStringifyCorrectly() : void
38+
{
39+
$true = new True_();
40+
41+
$this->assertSame('true', (string) $true);
42+
}
43+
44+
/**
45+
* @covers \phpDocumentor\Reflection\PseudoTypes\True_
46+
*/
47+
public function testCanBeInstantiatedUsingDeprecatedFqsen() : void
48+
{
49+
$true = new \phpDocumentor\Reflection\Types\True_();
50+
51+
$this->assertSame('true', (string) $true);
52+
$this->assertInstanceOf(True_::class, $true);
53+
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\True_::class, $true);
54+
}
55+
}

tests/unit/TypeResolverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,9 @@ public function provideKeywords() : array
705705
['bool', Types\Boolean::class],
706706
['boolean', Types\Boolean::class],
707707
['true', Types\Boolean::class],
708-
['true', Types\True_::class],
708+
['true', PseudoTypes\True_::class],
709709
['false', Types\Boolean::class],
710-
['false', Types\False_::class],
710+
['false', PseudoTypes\False_::class],
711711
['resource', Types\Resource_::class],
712712
['null', Types\Null_::class],
713713
['callable', Types\Callable_::class],

tests/unit/Types/BooleanTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* @coversDefaultClass \phpDocumentor\Reflection\Types\Boolean
20+
*/
21+
final class BooleanTest extends TestCase
22+
{
23+
/**
24+
* @covers ::__toString
25+
*/
26+
public function testBooleanStringifyCorrectly() : void
27+
{
28+
$type = new Boolean();
29+
30+
$this->assertSame('bool', (string) $type);
31+
}
32+
}

0 commit comments

Comments
 (0)