Skip to content

Commit

Permalink
Type: constants are PascalCase
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 4, 2022
1 parent 7100868 commit d31782f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
51 changes: 35 additions & 16 deletions src/PhpGenerator/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,41 @@
class Type
{
public const
STRING = 'string',
INT = 'int',
FLOAT = 'float',
BOOL = 'bool',
ARRAY = 'array',
OBJECT = 'object',
CALLABLE = 'callable',
ITERABLE = 'iterable',
VOID = 'void',
NEVER = 'never',
MIXED = 'mixed',
FALSE = 'false',
NULL = 'null',
SELF = 'self',
PARENT = 'parent',
STATIC = 'static';
String = 'string',
Int = 'int',
Float = 'float',
Bool = 'bool',
Array = 'array',
Object = 'object',
Callable = 'callable',
Iterable = 'iterable',
Void = 'void',
Never = 'never',
Mixed = 'mixed',
False = 'false',
Null = 'null',
Self = 'self',
Parent = 'parent',
Static = 'static';

/** @deprecated */
public const
STRING = self::String,
INT = self::Int,
FLOAT = self::Float,
BOOL = self::Bool,
ARRAY = self::Array,
OBJECT = self::Object,
CALLABLE = self::Callable,
ITERABLE = self::Iterable,
VOID = self::Void,
NEVER = self::Never,
MIXED = self::Mixed,
FALSE = self::False,
NULL = self::Null,
SELF = self::Self,
PARENT = self::Parent,
STATIC = self::Static;


public static function nullable(string $type, bool $state = true): string
Expand Down
8 changes: 4 additions & 4 deletions tests/PhpGenerator/ClassType.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ $class->addProperty('order')
->setValue(new Literal('RecursiveIteratorIterator::SELF_FIRST'));

$class->addProperty('typed1')
->setType(Type::ARRAY)
->setType(Type::Array)
->setReadOnly();

$class->addProperty('typed2')
->setType(Type::ARRAY)
->setType(Type::Array)
->setNullable()
->setInitialized();

$class->addProperty('typed3')
->setType(Type::ARRAY)
->setType(Type::Array)
->setValue(null);

$p = $class->addProperty('sections', ['first' => true])
Expand Down Expand Up @@ -126,7 +126,7 @@ $method->addParameter('item');

$method->addParameter('res', null)
->setReference(true)
->setType(Type::union(Type::ARRAY, 'null'));
->setType(Type::union(Type::Array, 'null'));

$method->addParameter('bar', null)
->setType('stdClass|string')
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpGenerator/Method.scalarParameters.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Assert::same('float', $method->getParameters()['d']->getType());

$method = (new Method('create'))
->setBody('return null;');
$method->addParameter('a')->setType(Type::STRING);
$method->addParameter('b')->setType(Type::BOOL);
$method->addParameter('a')->setType(Type::String);
$method->addParameter('b')->setType(Type::Bool);

same(
'function create(string $a, bool $b)
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpGenerator/Type.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use Tester\Assert;
require __DIR__ . '/../bootstrap.php';


Assert::same('A|string', Type::union(A::class, Type::STRING));
Assert::same('A|string', Type::union(A::class, Type::String));

Assert::same('?A', Type::nullable(A::class));
Assert::same('?A', Type::nullable(A::class, true));
Expand Down

0 comments on commit d31782f

Please sign in to comment.