From d31782f7bd2ae84ad06f863391ec3fb77ca4d0a6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 4 Oct 2022 02:20:22 +0200 Subject: [PATCH] Type: constants are PascalCase --- src/PhpGenerator/Type.php | 51 +++++++++++++------ tests/PhpGenerator/ClassType.phpt | 8 +-- .../PhpGenerator/Method.scalarParameters.phpt | 4 +- tests/PhpGenerator/Type.phpt | 2 +- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/PhpGenerator/Type.php b/src/PhpGenerator/Type.php index f7568550..2bfef1e0 100644 --- a/src/PhpGenerator/Type.php +++ b/src/PhpGenerator/Type.php @@ -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 diff --git a/tests/PhpGenerator/ClassType.phpt b/tests/PhpGenerator/ClassType.phpt index b29ac616..cf2fcbb5 100644 --- a/tests/PhpGenerator/ClassType.phpt +++ b/tests/PhpGenerator/ClassType.phpt @@ -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]) @@ -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') diff --git a/tests/PhpGenerator/Method.scalarParameters.phpt b/tests/PhpGenerator/Method.scalarParameters.phpt index fac07279..3a1d5965 100644 --- a/tests/PhpGenerator/Method.scalarParameters.phpt +++ b/tests/PhpGenerator/Method.scalarParameters.phpt @@ -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) diff --git a/tests/PhpGenerator/Type.phpt b/tests/PhpGenerator/Type.phpt index d487f18b..e49f2c82 100644 --- a/tests/PhpGenerator/Type.phpt +++ b/tests/PhpGenerator/Type.phpt @@ -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));