Skip to content

Add true and false as PseudoTypes #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Sep 2, 2020
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ phpcs:
phpcbf:
docker run -it --rm -v${PWD}:/opt/project -w /opt/project phpdoc/phpcs-ga:latest phpcbf


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

.PHONY: psaml
.PHONY: psalm
psalm:
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.2 tools/psalm

.PHONY: test
test:
docker run -it --rm -v${PWD}:/opt/project -w /opt/project php:7.2 tools/phpunit
Expand Down
7 changes: 6 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset name="phpDocumentor">
<description>The coding standard for phpDocumentor.</description>
<description>The coding standard for phpDocumentor.</description>

<file>src</file>
<file>tests/unit</file>
Expand All @@ -13,4 +13,9 @@
<rule ref="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix">
<exclude-pattern>*/src/*/Abstract*.php</exclude-pattern>
</rule>

<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>*/src/PseudoTypes/False_.php</exclude-pattern>
<exclude-pattern>*/src/PseudoTypes/True_.php</exclude-pattern>
</rule>
</ruleset>
19 changes: 19 additions & 0 deletions src/PseudoType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

/**
* 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
*/

namespace phpDocumentor\Reflection;

interface PseudoType extends Type
{
public function underlyingType() : Type;
}
39 changes: 39 additions & 0 deletions src/PseudoTypes/False_.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/**
* 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 https://phpdoc.org
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Boolean;
use function class_alias;

/**
* Value Object representing the PseudoType 'False', which is a Boolean type.
*
* @psalm-immutable
*/
final class False_ extends Boolean implements PseudoType
{
public function underlyingType() : Type
{
return new Boolean();
}

public function __toString() : string
{
return 'false';
}
}

class_alias('\phpDocumentor\Reflection\PseudoTypes\False_', 'phpDocumentor\Reflection\Types\False_', false);
39 changes: 39 additions & 0 deletions src/PseudoTypes/True_.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/**
* 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 https://phpdoc.org
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\PseudoType;
use phpDocumentor\Reflection\Type;
use phpDocumentor\Reflection\Types\Boolean;
use function class_alias;

/**
* Value Object representing the PseudoType 'False', which is a Boolean type.
*
* @psalm-immutable
*/
final class True_ extends Boolean implements PseudoType
{
public function underlyingType() : Type
{
return new Boolean();
}

public function __toString() : string
{
return 'true';
}
}

class_alias('\phpDocumentor\Reflection\PseudoTypes\True_', 'phpDocumentor\Reflection\Types\True_', false);
4 changes: 2 additions & 2 deletions src/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ final class TypeResolver
'scalar' => Types\Scalar::class,
'callback' => Types\Callable_::class,
'callable' => Types\Callable_::class,
'false' => Types\False_::class,
'true' => Types\True_::class,
'false' => PseudoTypes\False_::class,
'true' => PseudoTypes\True_::class,
'self' => Types\Self_::class,
'$this' => Types\This::class,
'static' => Types\Static_::class,
Expand Down
29 changes: 0 additions & 29 deletions src/Types/False_.php

This file was deleted.

29 changes: 0 additions & 29 deletions src/Types/True_.php

This file was deleted.

55 changes: 55 additions & 0 deletions tests/unit/PseudoTypes/FalseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

/**
* 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
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Boolean;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \phpDocumentor\Reflection\PseudoTypes\False_
*/
final class FalseTest extends TestCase
{
/**
* @covers ::underlyingType
*/
public function testExposesUnderlyingType() : void
{
$false = new False_();

$this->assertInstanceOf(Boolean::class, $false->underlyingType());
}

/**
* @covers ::__toString
*/
public function testFalseStringifyCorrectly() : void
{
$false = new False_();

$this->assertSame('false', (string) $false);
}

/**
* @covers \phpDocumentor\Reflection\PseudoTypes\False_
*/
public function testCanBeInstantiatedUsingDeprecatedFqsen() : void
{
$false = new \phpDocumentor\Reflection\Types\False_();

$this->assertSame('false', (string) $false);
$this->assertInstanceOf(False_::class, $false);
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\False_::class, $false);
}
}
55 changes: 55 additions & 0 deletions tests/unit/PseudoTypes/TrueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

/**
* 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
*/

namespace phpDocumentor\Reflection\PseudoTypes;

use phpDocumentor\Reflection\Types\Boolean;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \phpDocumentor\Reflection\PseudoTypes\True_
*/
class TrueTest extends TestCase
{
/**
* @covers ::underlyingType
*/
public function testExposesUnderlyingType() : void
{
$true = new True_();

$this->assertInstanceOf(Boolean::class, $true->underlyingType());
}

/**
* @covers ::__toString
*/
public function testTrueStringifyCorrectly() : void
{
$true = new True_();

$this->assertSame('true', (string) $true);
}

/**
* @covers \phpDocumentor\Reflection\PseudoTypes\True_
*/
public function testCanBeInstantiatedUsingDeprecatedFqsen() : void
{
$true = new \phpDocumentor\Reflection\Types\True_();

$this->assertSame('true', (string) $true);
$this->assertInstanceOf(True_::class, $true);
$this->assertInstanceOf(\phpDocumentor\Reflection\Types\True_::class, $true);
}
}
4 changes: 2 additions & 2 deletions tests/unit/TypeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,9 +704,9 @@ public function provideKeywords() : array
['bool', Types\Boolean::class],
['boolean', Types\Boolean::class],
['true', Types\Boolean::class],
['true', Types\True_::class],
['true', PseudoTypes\True_::class],
['false', Types\Boolean::class],
['false', Types\False_::class],
['false', PseudoTypes\False_::class],
['resource', Types\Resource_::class],
['null', Types\Null_::class],
['callable', Types\Callable_::class],
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/Types/BooleanTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

/**
* 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
*/

namespace phpDocumentor\Reflection\Types;

use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \phpDocumentor\Reflection\Types\Boolean
*/
final class BooleanTest extends TestCase
{
/**
* @covers ::__toString
*/
public function testBooleanStringifyCorrectly() : void
{
$type = new Boolean();

$this->assertSame('bool', (string) $type);
}
}