pax_global_header00006660000000000000000000000064135066105470014521gustar00rootroot0000000000000052 comment=3aaaa15fa71d27650d62a948be022fe3b48541a3 type-1.1.3/000077500000000000000000000000001350661054700125045ustar00rootroot00000000000000type-1.1.3/.gitattributes000066400000000000000000000000261350661054700153750ustar00rootroot00000000000000/tools export-ignore type-1.1.3/.github/000077500000000000000000000000001350661054700140445ustar00rootroot00000000000000type-1.1.3/.github/FUNDING.yml000066400000000000000000000000241350661054700156550ustar00rootroot00000000000000patreon: s_bergmann type-1.1.3/.gitignore000066400000000000000000000027321350661054700145000ustar00rootroot00000000000000/.php_cs /.php_cs.cache /.phpunit.result.cache /composer.lock /vendor # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff .idea/**/workspace.xml .idea/**/tasks.xml .idea/**/usage.statistics.xml .idea/**/dictionaries .idea/**/shelf # Generated files .idea/**/contentModel.xml # Sensitive or high-churn files .idea/**/dataSources/ .idea/**/dataSources.ids .idea/**/dataSources.local.xml .idea/**/sqlDataSources.xml .idea/**/dynamic.xml .idea/**/uiDesigner.xml .idea/**/dbnavigator.xml # Gradle .idea/**/gradle.xml .idea/**/libraries # Gradle and Maven with auto-import # When using Gradle or Maven with auto-import, you should exclude module files, # since they will be recreated, and may cause churn. Uncomment if using # auto-import. # .idea/modules.xml # .idea/*.iml # .idea/modules # CMake cmake-build-*/ # Mongo Explorer plugin .idea/**/mongoSettings.xml # File-based project format *.iws # IntelliJ out/ # mpeltonen/sbt-idea plugin .idea_modules/ # JIRA plugin atlassian-ide-plugin.xml # Cursive Clojure plugin .idea/replstate.xml # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties fabric.properties # Editor-based Rest Client .idea/httpRequests # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser type-1.1.3/.idea/000077500000000000000000000000001350661054700134645ustar00rootroot00000000000000type-1.1.3/.idea/inspectionProfiles/000077500000000000000000000000001350661054700173435ustar00rootroot00000000000000type-1.1.3/.idea/inspectionProfiles/Project_Default.xml000066400000000000000000001301561350661054700231450ustar00rootroot00000000000000 type-1.1.3/.idea/misc.xml000066400000000000000000000002561350661054700151440ustar00rootroot00000000000000 type-1.1.3/.idea/modules.xml000066400000000000000000000004041350661054700156540ustar00rootroot00000000000000 type-1.1.3/.idea/php-inspections-ea-ultimate.xml000066400000000000000000000014461350661054700215430ustar00rootroot00000000000000 type-1.1.3/.idea/php.xml000066400000000000000000000045101350661054700147750ustar00rootroot00000000000000 type-1.1.3/.idea/type.iml000066400000000000000000000052761350661054700151620ustar00rootroot00000000000000 type-1.1.3/.idea/vcs.xml000066400000000000000000000002641350661054700150030ustar00rootroot00000000000000 type-1.1.3/.php_cs.dist000066400000000000000000000176231350661054700147340ustar00rootroot00000000000000 For the full copyright and license information, please view the LICENSE file that was distributed with this source code. EOF; return PhpCsFixer\Config::create() ->setRiskyAllowed(true) ->setRules( [ 'align_multiline_comment' => true, 'array_indentation' => true, 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => [ 'operators' => [ '=' => 'align', '=>' => 'align', ], ], 'blank_line_after_namespace' => true, 'blank_line_before_statement' => [ 'statements' => [ 'break', 'continue', 'declare', 'do', 'for', 'foreach', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', ], ], 'braces' => true, 'cast_spaces' => true, 'class_attributes_separation' => ['elements' => ['const', 'method', 'property']], 'combine_consecutive_issets' => true, 'combine_consecutive_unsets' => true, 'compact_nullable_typehint' => true, 'concat_space' => ['spacing' => 'one'], 'declare_equal_normalize' => ['space' => 'none'], 'declare_strict_types' => true, 'dir_constant' => true, 'elseif' => true, 'encoding' => true, 'full_opening_tag' => true, 'function_declaration' => true, 'header_comment' => ['header' => $header, 'separate' => 'none'], 'indentation_type' => true, 'is_null' => true, 'line_ending' => true, 'list_syntax' => ['syntax' => 'short'], 'logical_operators' => true, 'lowercase_cast' => true, 'lowercase_constants' => true, 'lowercase_keywords' => true, 'lowercase_static_reference' => true, 'magic_constant_casing' => true, 'method_argument_space' => ['ensure_fully_multiline' => true], 'modernize_types_casting' => true, 'multiline_comment_opening_closing' => true, 'multiline_whitespace_before_semicolons' => true, 'native_constant_invocation' => true, 'native_function_casing' => true, 'native_function_invocation' => true, 'new_with_braces' => false, 'no_alias_functions' => true, 'no_alternative_syntax' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, 'no_blank_lines_before_namespace' => true, 'no_closing_tag' => true, 'no_empty_comment' => true, 'no_empty_phpdoc' => true, 'no_empty_statement' => true, 'no_extra_blank_lines' => true, 'no_homoglyph_names' => true, 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_mixed_echo_print' => ['use' => 'print'], 'no_multiline_whitespace_around_double_arrow' => true, 'no_null_property_initialization' => true, 'no_php4_constructor' => true, 'no_short_bool_cast' => true, 'no_short_echo_tag' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_after_function_name' => true, 'no_spaces_inside_parenthesis' => true, 'no_superfluous_elseif' => true, 'no_superfluous_phpdoc_tags' => true, 'no_trailing_comma_in_list_call' => true, 'no_trailing_comma_in_singleline_array' => true, 'no_trailing_whitespace' => true, 'no_trailing_whitespace_in_comment' => true, 'no_unneeded_control_parentheses' => true, 'no_unneeded_curly_braces' => true, 'no_unneeded_final_method' => true, 'no_unreachable_default_argument_value' => true, 'no_unset_on_property' => true, 'no_unused_imports' => true, 'no_useless_else' => true, 'no_useless_return' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_line' => true, 'non_printable_character' => true, 'normalize_index_brace' => true, 'object_operator_without_whitespace' => true, 'ordered_class_elements' => [ 'order' => [ 'use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property_public_static', 'property_protected_static', 'property_private_static', 'property_public', 'property_protected', 'property_private', 'method_public_static', 'construct', 'destruct', 'magic', 'phpunit', 'method_public', 'method_protected', 'method_private', 'method_protected_static', 'method_private_static', ], ], 'ordered_imports' => true, 'ordered_interfaces' => [ 'direction' => 'ascend', 'order' => 'alpha', ], 'phpdoc_add_missing_param_annotation' => true, 'phpdoc_align' => true, 'phpdoc_annotation_without_dot' => true, 'phpdoc_indent' => true, 'phpdoc_no_access' => true, 'phpdoc_no_empty_return' => true, 'phpdoc_no_package' => true, 'phpdoc_order' => true, 'phpdoc_return_self_reference' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_single_line_var_spacing' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'phpdoc_trim_consecutive_blank_line_separation' => true, 'phpdoc_types' => ['groups' => ['simple', 'meta']], 'phpdoc_types_order' => true, 'phpdoc_var_without_name' => true, 'pow_to_exponentiation' => true, 'protected_to_private' => true, 'return_assignment' => true, 'return_type_declaration' => ['space_before' => 'none'], 'semicolon_after_instruction' => true, 'set_type_to_cast' => true, 'short_scalar_cast' => true, 'simplified_null_return' => true, 'single_blank_line_at_eof' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, 'single_quote' => true, 'standardize_not_equals' => true, 'ternary_to_null_coalescing' => true, 'trailing_comma_in_multiline_array' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => true, 'visibility_required' => [ 'elements' => [ 'const', 'method', 'property', ], ], 'void_return' => true, 'whitespace_after_comma_in_array' => true, ] ) ->setFinder( PhpCsFixer\Finder::create() ->files() ->in(__DIR__ . '/src') ->in(__DIR__ . '/tests') ); type-1.1.3/.travis.yml000066400000000000000000000023261350661054700146200ustar00rootroot00000000000000language: php php: - 7.2 - 7.3 - 7.4snapshot - nightly matrix: allow_failures: - php: master fast_finish: true env: matrix: - DEPENDENCIES="high" - DEPENDENCIES="low" global: - DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest" before_install: - ./tools/composer clear-cache install: - if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry ./tools/composer update $DEFAULT_COMPOSER_FLAGS; fi - if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry ./tools/composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi script: - ./vendor/bin/phpunit --coverage-clover=coverage.xml after_success: - bash <(curl -s https://codecov.io/bash) notifications: email: false jobs: include: - stage: "Static Code Analysis" php: 7.3 env: php-cs-fixer install: - phpenv config-rm xdebug.ini script: - ./tools/php-cs-fixer fix --dry-run -v --show-progress=dots --diff-format=udiff - stage: "Static Code Analysis" php: 7.3 env: psalm install: - phpenv config-rm xdebug.ini script: - travis_retry ./tools/composer update $DEFAULT_COMPOSER_FLAGS - ./tools/psalm --shepherd --stats type-1.1.3/ChangeLog.md000066400000000000000000000020601350661054700146530ustar00rootroot00000000000000# ChangeLog All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. ## [1.1.3] - 2019-07-02 ### Fixed * Fixed class name comparison in `ObjectType` to be case insensitive ## [1.1.2] - 2019-06-19 ### Fixed * Fixed handling of `object` type ## [1.1.1] - 2019-06-08 ### Fixed * Fixed autoloading of `callback_function.php` fixture file ## [1.1.0] - 2019-06-07 ### Added * Added support for `callable` type * Added support for `iterable` type ## [1.0.0] - 2019-06-06 * Initial release based on [code contributed by Michel Hartmann to PHPUnit](https://github.com/sebastianbergmann/phpunit/pull/3673) [1.1.3]: https://github.com/sebastianbergmann/type/compare/1.1.2...1.1.3 [1.1.2]: https://github.com/sebastianbergmann/type/compare/1.1.1...1.1.2 [1.1.1]: https://github.com/sebastianbergmann/type/compare/1.1.0...1.1.1 [1.1.0]: https://github.com/sebastianbergmann/type/compare/1.0.0...1.1.0 [1.0.0]: https://github.com/sebastianbergmann/type/compare/ff74aa41746bd8d10e931843ebf37d42da513ede...1.0.0 type-1.1.3/LICENSE000066400000000000000000000030101350661054700135030ustar00rootroot00000000000000sebastian/type Copyright (c) 2019, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sebastian Bergmann nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. type-1.1.3/README.md000066400000000000000000000007341350661054700137670ustar00rootroot00000000000000# sebastian/type Collection of value objects that represent the types of the PHP type system. ## Installation You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/): ``` composer require sebastian/type ``` If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency: ``` composer require --dev sebastian/type ``` type-1.1.3/build.xml000066400000000000000000000020031350661054700143200ustar00rootroot00000000000000 type-1.1.3/composer.json000066400000000000000000000021431350661054700152260ustar00rootroot00000000000000{ "name": "sebastian/type", "description": "Collection of value objects that represent the types of the PHP type system", "type": "library", "homepage": "https://github.com/sebastianbergmann/type", "license": "BSD-3-Clause", "authors": [ { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de", "role": "lead" } ], "support": { "issues": "https://github.com/sebastianbergmann/type/issues" }, "prefer-stable": true, "require": { "php": "^7.2" }, "require-dev": { "phpunit/phpunit": "^8.2" }, "config": { "platform": { "php": "7.2.0" }, "optimize-autoloader": true, "sort-packages": true }, "autoload": { "classmap": [ "src/" ] }, "autoload-dev": { "classmap": [ "tests/_fixture" ], "files": [ "tests/_fixture/callback_function.php" ] }, "extra": { "branch-alias": { "dev-master": "1.1-dev" } } } type-1.1.3/phive.xml000066400000000000000000000004401350661054700143370ustar00rootroot00000000000000 type-1.1.3/phpunit.xml000066400000000000000000000014661350661054700147240ustar00rootroot00000000000000 tests/unit src type-1.1.3/psalm.xml000066400000000000000000000034331350661054700143450ustar00rootroot00000000000000 type-1.1.3/src/000077500000000000000000000000001350661054700132735ustar00rootroot00000000000000type-1.1.3/src/CallableType.php000066400000000000000000000106321350661054700163470ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; final class CallableType extends Type { /** * @var bool */ private $allowsNull; public function __construct(bool $nullable) { $this->allowsNull = $nullable; } /** * @throws RuntimeException */ public function isAssignable(Type $other): bool { if ($this->allowsNull && $other instanceof NullType) { return true; } if ($other instanceof self) { return true; } if ($other instanceof ObjectType) { if ($this->isClosure($other)) { return true; } if ($this->hasInvokeMethod($other)) { return true; } } if ($other instanceof SimpleType) { if ($this->isFunction($other)) { return true; } if ($this->isClassCallback($other)) { return true; } if ($this->isObjectCallback($other)) { return true; } } return false; } public function getReturnTypeDeclaration(): string { return ': ' . ($this->allowsNull ? '?' : '') . 'callable'; } public function allowsNull(): bool { return $this->allowsNull; } private function isClosure(ObjectType $type): bool { return !$type->className()->isNamespaced() && $type->className()->getSimpleName() === \Closure::class; } /** * @throws RuntimeException */ private function hasInvokeMethod(ObjectType $type): bool { try { $class = new \ReflectionClass($type->className()->getQualifiedName()); // @codeCoverageIgnoreStart } catch (\ReflectionException $e) { throw new RuntimeException( $e->getMessage(), (int) $e->getCode(), $e ); // @codeCoverageIgnoreEnd } if ($class->hasMethod('__invoke')) { return true; } return false; } private function isFunction(SimpleType $type): bool { if (!\is_string($type->value())) { return false; } return \function_exists($type->value()); } private function isObjectCallback(SimpleType $type): bool { if (!\is_array($type->value())) { return false; } if (\count($type->value()) !== 2) { return false; } if (!\is_object($type->value()[0]) || !\is_string($type->value()[1])) { return false; } [$object, $methodName] = $type->value(); $reflector = new \ReflectionObject($object); return $reflector->hasMethod($methodName); } private function isClassCallback(SimpleType $type): bool { if (!\is_string($type->value()) && !\is_array($type->value())) { return false; } if (\is_string($type->value())) { if (\strpos($type->value(), '::') === false) { return false; } [$className, $methodName] = \explode('::', $type->value()); } if (\is_array($type->value())) { if (\count($type->value()) !== 2) { return false; } if (!\is_string($type->value()[0]) || !\is_string($type->value()[1])) { return false; } [$className, $methodName] = $type->value(); } \assert(isset($className) && \is_string($className)); \assert(isset($methodName) && \is_string($methodName)); try { $class = new \ReflectionClass($className); if ($class->hasMethod($methodName)) { $method = $class->getMethod($methodName); return $method->isPublic() && $method->isStatic(); } // @codeCoverageIgnoreStart } catch (\ReflectionException $e) { throw new RuntimeException( $e->getMessage(), (int) $e->getCode(), $e ); // @codeCoverageIgnoreEnd } return false; } } type-1.1.3/src/GenericObjectType.php000066400000000000000000000017321350661054700173540ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; final class GenericObjectType extends Type { /** * @var bool */ private $allowsNull; public function __construct(bool $nullable) { $this->allowsNull = $nullable; } public function isAssignable(Type $other): bool { if ($this->allowsNull && $other instanceof NullType) { return true; } if (!$other instanceof ObjectType) { return false; } return true; } public function getReturnTypeDeclaration(): string { return ': ' . ($this->allowsNull ? '?' : '') . 'object'; } public function allowsNull(): bool { return $this->allowsNull; } } type-1.1.3/src/IterableType.php000066400000000000000000000031211350661054700163720ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; final class IterableType extends Type { /** * @var bool */ private $allowsNull; public function __construct(bool $nullable) { $this->allowsNull = $nullable; } /** * @throws RuntimeException */ public function isAssignable(Type $other): bool { if ($this->allowsNull && $other instanceof NullType) { return true; } if ($other instanceof self) { return true; } if ($other instanceof SimpleType) { return \is_iterable($other->value()); } if ($other instanceof ObjectType) { try { return (new \ReflectionClass($other->className()->getQualifiedName()))->isIterable(); // @codeCoverageIgnoreStart } catch (\ReflectionException $e) { throw new RuntimeException( $e->getMessage(), (int) $e->getCode(), $e ); // @codeCoverageIgnoreEnd } } return false; } public function getReturnTypeDeclaration(): string { return ': ' . ($this->allowsNull ? '?' : '') . 'iterable'; } public function allowsNull(): bool { return $this->allowsNull; } } type-1.1.3/src/NullType.php000066400000000000000000000011331350661054700155560ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; final class NullType extends Type { public function isAssignable(Type $other): bool { return !($other instanceof VoidType); } public function getReturnTypeDeclaration(): string { return ''; } public function allowsNull(): bool { return true; } } type-1.1.3/src/ObjectType.php000066400000000000000000000027451350661054700160640ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; final class ObjectType extends Type { /** * @var TypeName */ private $className; /** * @var bool */ private $allowsNull; public function __construct(TypeName $className, bool $allowsNull) { $this->className = $className; $this->allowsNull = $allowsNull; } public function isAssignable(Type $other): bool { if ($this->allowsNull && $other instanceof NullType) { return true; } if ($other instanceof self) { if (0 === \strcasecmp($this->className->getQualifiedName(), $other->className->getQualifiedName())) { return true; } if (\is_subclass_of($other->className->getQualifiedName(), $this->className->getQualifiedName(), true)) { return true; } } return false; } public function getReturnTypeDeclaration(): string { return ': ' . ($this->allowsNull ? '?' : '') . $this->className->getQualifiedName(); } public function allowsNull(): bool { return $this->allowsNull; } public function className(): TypeName { return $this->className; } } type-1.1.3/src/SimpleType.php000066400000000000000000000033221350661054700160770ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; final class SimpleType extends Type { /** * @var string */ private $name; /** * @var bool */ private $allowsNull; /** * @var mixed */ private $value; public function __construct(string $name, bool $nullable, $value = null) { $this->name = $this->normalize($name); $this->allowsNull = $nullable; $this->value = $value; } public function isAssignable(Type $other): bool { if ($this->allowsNull && $other instanceof NullType) { return true; } if ($other instanceof self) { return $this->name === $other->name; } return false; } public function getReturnTypeDeclaration(): string { return ': ' . ($this->allowsNull ? '?' : '') . $this->name; } public function allowsNull(): bool { return $this->allowsNull; } public function value() { return $this->value; } private function normalize(string $name): string { $name = \strtolower($name); switch ($name) { case 'boolean': return 'bool'; case 'real': case 'double': return 'float'; case 'integer': return 'int'; case '[]': return 'array'; default: return $name; } } } type-1.1.3/src/Type.php000066400000000000000000000037731350661054700147370ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; abstract class Type { public static function fromValue($value, bool $allowsNull): self { $typeName = \gettype($value); if ($typeName === 'object') { return new ObjectType(TypeName::fromQualifiedName(\get_class($value)), $allowsNull); } $type = self::fromName($typeName, $allowsNull); if ($type instanceof SimpleType) { $type = new SimpleType($typeName, $allowsNull, $value); } return $type; } public static function fromName(string $typeName, bool $allowsNull): self { switch (\strtolower($typeName)) { case 'callable': return new CallableType($allowsNull); case 'iterable': return new IterableType($allowsNull); case 'null': return new NullType; case 'object': return new GenericObjectType($allowsNull); case 'unknown type': return new UnknownType; case 'void': return new VoidType; case 'array': case 'bool': case 'boolean': case 'double': case 'float': case 'int': case 'integer': case 'real': case 'resource': case 'resource (closed)': case 'string': return new SimpleType($typeName, $allowsNull); default: return new ObjectType(TypeName::fromQualifiedName($typeName), $allowsNull); } } abstract public function isAssignable(Type $other): bool; abstract public function getReturnTypeDeclaration(): string; abstract public function allowsNull(): bool; } type-1.1.3/src/TypeName.php000066400000000000000000000034301350661054700155260ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; final class TypeName { /** * @var ?string */ private $namespaceName; /** * @var string */ private $simpleName; public static function fromQualifiedName(string $fullClassName): self { if ($fullClassName[0] === '\\') { $fullClassName = \substr($fullClassName, 1); } $classNameParts = \explode('\\', $fullClassName); $simpleName = \array_pop($classNameParts); $namespaceName = \implode('\\', $classNameParts); return new self($namespaceName, $simpleName); } public static function fromReflection(\ReflectionClass $type): self { return new self( $type->getNamespaceName(), $type->getShortName() ); } public function __construct(?string $namespaceName, string $simpleName) { if ($namespaceName === '') { $namespaceName = null; } $this->namespaceName = $namespaceName; $this->simpleName = $simpleName; } public function getNamespaceName(): ?string { return $this->namespaceName; } public function getSimpleName(): string { return $this->simpleName; } public function getQualifiedName(): string { return $this->namespaceName === null ? $this->simpleName : $this->namespaceName . '\\' . $this->simpleName; } public function isNamespaced(): bool { return $this->namespaceName !== null; } } type-1.1.3/src/UnknownType.php000066400000000000000000000011051350661054700163020ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; final class UnknownType extends Type { public function isAssignable(Type $other): bool { return true; } public function getReturnTypeDeclaration(): string { return ''; } public function allowsNull(): bool { return true; } } type-1.1.3/src/VoidType.php000066400000000000000000000011331350661054700155450ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; final class VoidType extends Type { public function isAssignable(Type $other): bool { return $other instanceof self; } public function getReturnTypeDeclaration(): string { return ': void'; } public function allowsNull(): bool { return false; } } type-1.1.3/src/exception/000077500000000000000000000000001350661054700152715ustar00rootroot00000000000000type-1.1.3/src/exception/Exception.php000066400000000000000000000004771350661054700177500ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; interface Exception { } type-1.1.3/src/exception/RuntimeException.php000066400000000000000000000005671350661054700213140ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; final class RuntimeException extends \RuntimeException implements Exception { } type-1.1.3/tests/000077500000000000000000000000001350661054700136465ustar00rootroot00000000000000type-1.1.3/tests/_fixture/000077500000000000000000000000001350661054700154735ustar00rootroot00000000000000type-1.1.3/tests/_fixture/ChildClass.php000066400000000000000000000005341350661054700202170ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type\TestFixture; class ChildClass extends ParentClass { } type-1.1.3/tests/_fixture/ClassWithCallbackMethods.php000066400000000000000000000007251350661054700230520ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type\TestFixture; final class ClassWithCallbackMethods { public static function staticCallback(): void { } public function nonStaticCallback(): void { } } type-1.1.3/tests/_fixture/ClassWithInvokeMethod.php000066400000000000000000000006121350661054700224210ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type\TestFixture; final class ClassWithInvokeMethod { public function __invoke(): void { } } type-1.1.3/tests/_fixture/Iterator.php000066400000000000000000000011131350661054700177710ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type\TestFixture; final class Iterator implements \Iterator { public function current(): void { } public function next(): void { } public function key(): void { } public function valid(): void { } public function rewind(): void { } } type-1.1.3/tests/_fixture/ParentClass.php000066400000000000000000000005651350661054700204310ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type\TestFixture; class ParentClass { public function foo(): void { } } type-1.1.3/tests/_fixture/callback_function.php000066400000000000000000000005321350661054700216450ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type\TestFixture; function callback_function(): void { } type-1.1.3/tests/unit/000077500000000000000000000000001350661054700146255ustar00rootroot00000000000000type-1.1.3/tests/unit/CallableTypeTest.php000066400000000000000000000100471350661054700205410ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; use PHPUnit\Framework\TestCase; use SebastianBergmann\Type\TestFixture\ClassWithCallbackMethods; use SebastianBergmann\Type\TestFixture\ClassWithInvokeMethod; /** * @covers \SebastianBergmann\Type\CallableType * * @uses \SebastianBergmann\Type\Type * @uses \SebastianBergmann\Type\ObjectType * @uses \SebastianBergmann\Type\SimpleType * @uses \SebastianBergmann\Type\TypeName */ final class CallableTypeTest extends TestCase { /** * @var CallableType */ private $type; protected function setUp(): void { $this->type = new CallableType(false); } public function testMayDisallowNull(): void { $this->assertFalse($this->type->allowsNull()); } public function testCanGenerateReturnTypeDeclaration(): void { $this->assertEquals(': callable', $this->type->getReturnTypeDeclaration()); } public function testMayAllowNull(): void { $type = new CallableType(true); $this->assertTrue($type->allowsNull()); } public function testCanGenerateNullableReturnTypeDeclaration(): void { $type = new CallableType(true); $this->assertEquals(': ?callable', $type->getReturnTypeDeclaration()); } public function testNullCanBeAssignedToNullableCallable(): void { $type = new CallableType(true); $this->assertTrue($type->isAssignable(new NullType)); } public function testCallableCanBeAssignedToCallable(): void { $this->assertTrue($this->type->isAssignable(new CallableType(false))); } public function testClosureCanBeAssignedToCallable(): void { $this->assertTrue( $this->type->isAssignable( new ObjectType( TypeName::fromQualifiedName(\Closure::class), false ) ) ); } public function testInvokableCanBeAssignedToCallable(): void { $this->assertTrue( $this->type->isAssignable( new ObjectType( TypeName::fromQualifiedName(ClassWithInvokeMethod::class), false ) ) ); } public function testStringWithFunctionNameCanBeAssignedToCallable(): void { $this->assertTrue( $this->type->isAssignable( Type::fromValue('SebastianBergmann\Type\TestFixture\callback_function', false) ) ); } public function testStringWithClassNameAndStaticMethodNameCanBeAssignedToCallable(): void { $this->assertTrue( $this->type->isAssignable( Type::fromValue(ClassWithCallbackMethods::class . '::staticCallback', false) ) ); } public function testArrayWithClassNameAndStaticMethodNameCanBeAssignedToCallable(): void { $this->assertTrue( $this->type->isAssignable( Type::fromValue([ClassWithCallbackMethods::class, 'staticCallback'], false) ) ); } public function testArrayWithClassNameAndInstanceMethodNameCanBeAssignedToCallable(): void { $this->assertTrue( $this->type->isAssignable( Type::fromValue([new ClassWithCallbackMethods, 'nonStaticCallback'], false) ) ); } public function testSomethingThatIsNotCallableCannotBeAssignedToCallable(): void { $this->assertFalse( $this->type->isAssignable( Type::fromValue(null, false) ) ); } public function testObjectWithoutInvokeMethodCannotBeAssignedToCallable(): void { $this->assertFalse( $this->type->isAssignable( Type::fromValue(new class { }, false) ) ); } } type-1.1.3/tests/unit/GenericObjectTypeTest.php000066400000000000000000000041411350661054700215430ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\Type\GenericObjectType * * @uses \SebastianBergmann\Type\Type * @uses \SebastianBergmann\Type\ObjectType * @uses \SebastianBergmann\Type\SimpleType * @uses \SebastianBergmann\Type\TypeName */ final class GenericObjectTypeTest extends TestCase { /** * @var GenericObjectType */ private $type; protected function setUp(): void { $this->type = new GenericObjectType(false); } public function testMayDisallowNull(): void { $this->assertFalse($this->type->allowsNull()); } public function testCanGenerateReturnTypeDeclaration(): void { $this->assertEquals(': object', $this->type->getReturnTypeDeclaration()); } public function testMayAllowNull(): void { $type = new GenericObjectType(true); $this->assertTrue($type->allowsNull()); } public function testCanGenerateNullableReturnTypeDeclaration(): void { $type = new GenericObjectType(true); $this->assertEquals(': ?object', $type->getReturnTypeDeclaration()); } public function testObjectCanBeAssignedToGenericObject(): void { $this->assertTrue( $this->type->isAssignable( new ObjectType(TypeName::fromQualifiedName(\stdClass::class), false) ) ); } public function testNullCanBeAssignedToNullableGenericObject(): void { $type = new GenericObjectType(true); $this->assertTrue( $type->isAssignable( new NullType ) ); } public function testNonObjectCannotBeAssignedToGenericObject(): void { $this->assertFalse( $this->type->isAssignable( new SimpleType('bool', false) ) ); } } type-1.1.3/tests/unit/IterableTypeTest.php000066400000000000000000000046161350661054700205760ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; use PHPUnit\Framework\TestCase; use SebastianBergmann\Type\TestFixture\Iterator; /** * @covers \SebastianBergmann\Type\IterableType * * @uses \SebastianBergmann\Type\Type * @uses \SebastianBergmann\Type\TypeName * @uses \SebastianBergmann\Type\ObjectType * @uses \SebastianBergmann\Type\SimpleType */ final class IterableTypeTest extends TestCase { /** * @var IterableType */ private $type; protected function setUp(): void { $this->type = new IterableType(false); } public function testMayDisallowNull(): void { $this->assertFalse($this->type->allowsNull()); } public function testCanGenerateReturnTypeDeclaration(): void { $this->assertEquals(': iterable', $this->type->getReturnTypeDeclaration()); } public function testMayAllowNull(): void { $type = new IterableType(true); $this->assertTrue($type->allowsNull()); } public function testCanGenerateNullableReturnTypeDeclaration(): void { $type = new IterableType(true); $this->assertEquals(': ?iterable', $type->getReturnTypeDeclaration()); } public function testNullCanBeAssignedToNullableIterable(): void { $type = new IterableType(true); $this->assertTrue($type->isAssignable(new NullType)); } public function testIterableCanBeAssignedToIterable(): void { $this->assertTrue($this->type->isAssignable(new IterableType(false))); } public function testArrayCanBeAssignedToIterable(): void { $this->assertTrue( $this->type->isAssignable( Type::fromValue([], false) ) ); } public function testIteratorCanBeAssignedToIterable(): void { $this->assertTrue( $this->type->isAssignable( Type::fromValue(new Iterator, false) ) ); } public function testSomethingThatIsNotIterableCannotBeAssignedToIterable(): void { $this->assertFalse( $this->type->isAssignable( Type::fromValue(null, false) ) ); } } type-1.1.3/tests/unit/NullTypeTest.php000066400000000000000000000032631350661054700177560ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\Type\NullType */ final class NullTypeTest extends TestCase { /** * @var NullType */ private $type; protected function setUp(): void { $this->type = new NullType; } /** * @dataProvider assignableTypes */ public function testIsAssignable(Type $assignableType): void { $this->assertTrue($this->type->isAssignable($assignableType)); } public function assignableTypes(): array { return [ [new SimpleType('int', false)], [new SimpleType('int', true)], [new ObjectType(TypeName::fromQualifiedName(self::class), false)], [new ObjectType(TypeName::fromQualifiedName(self::class), true)], [new UnknownType], ]; } /** * @dataProvider notAssignable */ public function testIsNotAssignable(Type $assignedType): void { $this->assertFalse($this->type->isAssignable($assignedType)); } public function notAssignable(): array { return [ 'void' => [new VoidType], ]; } public function testAllowsNull(): void { $this->assertTrue($this->type->allowsNull()); } public function testCanGenerateReturnTypeDeclaration(): void { $this->assertEquals('', $this->type->getReturnTypeDeclaration()); } } type-1.1.3/tests/unit/ObjectTypeTest.php000066400000000000000000000076701350661054700202600ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; use PHPUnit\Framework\TestCase; use SebastianBergmann\Type\TestFixture\ChildClass; use SebastianBergmann\Type\TestFixture\ParentClass; /** * @covers \SebastianBergmann\Type\ObjectType * * @uses \SebastianBergmann\Type\TypeName * @uses \SebastianBergmann\Type\Type * @uses \SebastianBergmann\Type\SimpleType */ final class ObjectTypeTest extends TestCase { /** * @var ObjectType */ private $childClass; /** * @var ObjectType */ private $parentClass; protected function setUp(): void { $this->childClass = new ObjectType( TypeName::fromQualifiedName(ChildClass::class), false ); $this->parentClass = new ObjectType( TypeName::fromQualifiedName(ParentClass::class), false ); } public function testParentIsNotAssignableToChild(): void { $this->assertFalse($this->childClass->isAssignable($this->parentClass)); } public function testChildIsAssignableToParent(): void { $this->assertTrue($this->parentClass->isAssignable($this->childClass)); } public function testClassIsAssignableToSelf(): void { $this->assertTrue($this->parentClass->isAssignable($this->parentClass)); } public function testSimpleTypeIsNotAssignableToClass(): void { $this->assertFalse($this->parentClass->isAssignable(new SimpleType('int', false))); } public function testClassFromOneNamespaceIsNotAssignableToClassInOtherNamespace(): void { $classFromNamespaceA = new ObjectType( TypeName::fromQualifiedName(\someNamespaceA\NamespacedClass::class), false ); $classFromNamespaceB = new ObjectType( TypeName::fromQualifiedName(\someNamespaceB\NamespacedClass::class), false ); $this->assertFalse($classFromNamespaceA->isAssignable($classFromNamespaceB)); } public function testClassIsAssignableToSelfCaseInsensitively(): void { $classLowercased = new ObjectType( TypeName::fromQualifiedName(\strtolower(ParentClass::class)), false ); $this->assertTrue($this->parentClass->isAssignable($classLowercased)); } public function testNullIsAssignableToNullableType(): void { $someClass = new ObjectType( TypeName::fromQualifiedName(ParentClass::class), true ); $this->assertTrue($someClass->isAssignable(Type::fromValue(null, true))); } public function testNullIsNotAssignableToNotNullableType(): void { $someClass = new ObjectType( TypeName::fromQualifiedName(ParentClass::class), false ); $this->assertFalse($someClass->isAssignable(Type::fromValue(null, true))); } public function testPreservesNullNotAllowed(): void { $someClass = new ObjectType( TypeName::fromQualifiedName(ParentClass::class), false ); $this->assertFalse($someClass->allowsNull()); } public function testPreservesNullAllowed(): void { $someClass = new ObjectType( TypeName::fromQualifiedName(ParentClass::class), true ); $this->assertTrue($someClass->allowsNull()); } public function testCanGenerateReturnTypeDeclaration(): void { $this->assertEquals(': SebastianBergmann\Type\TestFixture\ParentClass', $this->parentClass->getReturnTypeDeclaration()); } public function testHasClassName(): void { $this->assertEquals('SebastianBergmann\Type\TestFixture\ParentClass', $this->parentClass->className()->getQualifiedName()); } } type-1.1.3/tests/unit/SimpleTypeTest.php000066400000000000000000000116301350661054700202720ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\Type\SimpleType * * @uses \SebastianBergmann\Type\Type */ final class SimpleTypeTest extends TestCase { public function testCanBeBool(): void { $type = new SimpleType('bool', false); $this->assertSame(': bool', $type->getReturnTypeDeclaration()); } public function testCanBeBoolean(): void { $type = new SimpleType('boolean', false); $this->assertSame(': bool', $type->getReturnTypeDeclaration()); } public function testCanBeDouble(): void { $type = new SimpleType('double', false); $this->assertSame(': float', $type->getReturnTypeDeclaration()); } public function testCanBeFloat(): void { $type = new SimpleType('float', false); $this->assertSame(': float', $type->getReturnTypeDeclaration()); } public function testCanBeReal(): void { $type = new SimpleType('real', false); $this->assertSame(': float', $type->getReturnTypeDeclaration()); } public function testCanBeInt(): void { $type = new SimpleType('int', false); $this->assertSame(': int', $type->getReturnTypeDeclaration()); } public function testCanBeInteger(): void { $type = new SimpleType('integer', false); $this->assertSame(': int', $type->getReturnTypeDeclaration()); } public function testCanBeArray(): void { $type = new SimpleType('array', false); $this->assertSame(': array', $type->getReturnTypeDeclaration()); } public function testCanBeArray2(): void { $type = new SimpleType('[]', false); $this->assertSame(': array', $type->getReturnTypeDeclaration()); } public function testMayAllowNull(): void { $type = new SimpleType('bool', true); $this->assertTrue($type->allowsNull()); $this->assertSame(': ?bool', $type->getReturnTypeDeclaration()); } public function testMayNotAllowNull(): void { $type = new SimpleType('bool', false); $this->assertFalse($type->allowsNull()); } /** * @dataProvider assignablePairs */ public function testIsAssignable(Type $assignTo, Type $assignedType): void { $this->assertTrue($assignTo->isAssignable($assignedType)); } public function assignablePairs(): array { return [ 'nullable to not nullable' => [new SimpleType('int', false), new SimpleType('int', true)], 'not nullable to nullable' => [new SimpleType('int', true), new SimpleType('int', false)], 'nullable to nullable' => [new SimpleType('int', true), new SimpleType('int', true)], 'not nullable to not nullable' => [new SimpleType('int', false), new SimpleType('int', false)], 'null to not nullable' => [new SimpleType('int', true), new NullType], ]; } /** * @dataProvider notAssignablePairs */ public function testIsNotAssignable(Type $assignTo, Type $assignedType): void { $this->assertFalse($assignTo->isAssignable($assignedType)); } public function notAssignablePairs(): array { return [ 'null to not nullable' => [new SimpleType('int', false), new NullType], 'int to boolean' => [new SimpleType('boolean', false), new SimpleType('int', false)], 'object' => [new SimpleType('boolean', false), new ObjectType(TypeName::fromQualifiedName(\stdClass::class), true)], 'unknown type' => [new SimpleType('boolean', false), new UnknownType], 'void' => [new SimpleType('boolean', false), new VoidType], ]; } /** * @dataProvider returnTypes */ public function testReturnTypeDeclaration(Type $type, string $returnType): void { $this->assertEquals($type->getReturnTypeDeclaration(), $returnType); } public function returnTypes(): array { return [ '[]' => [new SimpleType('[]', false), ': array'], 'array' => [new SimpleType('array', false), ': array'], '?array' => [new SimpleType('array', true), ': ?array'], 'boolean' => [new SimpleType('boolean', false), ': bool'], 'real' => [new SimpleType('real', false), ': float'], 'double' => [new SimpleType('double', false), ': float'], 'integer' => [new SimpleType('integer', false), ': int'], ]; } public function testCanHaveValue(): void { $this->assertSame('string', Type::fromValue('string', false)->value()); } } type-1.1.3/tests/unit/TypeNameTest.php000066400000000000000000000041441350661054700177230ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\Type\TypeName */ final class TypeNameTest extends TestCase { public function testFromReflection(): void { $class = new \ReflectionClass(TypeName::class); $typeName = TypeName::fromReflection($class); $this->assertTrue($typeName->isNamespaced()); $this->assertEquals('SebastianBergmann\\Type', $typeName->getNamespaceName()); $this->assertEquals(TypeName::class, $typeName->getQualifiedName()); $this->assertEquals('TypeName', $typeName->getSimpleName()); } public function testFromQualifiedName(): void { $typeName = TypeName::fromQualifiedName('PHPUnit\\Framework\\MockObject\\TypeName'); $this->assertTrue($typeName->isNamespaced()); $this->assertEquals('PHPUnit\\Framework\\MockObject', $typeName->getNamespaceName()); $this->assertEquals('PHPUnit\\Framework\\MockObject\\TypeName', $typeName->getQualifiedName()); $this->assertEquals('TypeName', $typeName->getSimpleName()); } public function testFromQualifiedNameWithLeadingSeparator(): void { $typeName = TypeName::fromQualifiedName('\\Foo\\Bar'); $this->assertTrue($typeName->isNamespaced()); $this->assertEquals('Foo', $typeName->getNamespaceName()); $this->assertEquals('Foo\\Bar', $typeName->getQualifiedName()); $this->assertEquals('Bar', $typeName->getSimpleName()); } public function testFromQualifiedNameWithoutNamespace(): void { $typeName = TypeName::fromQualifiedName('Bar'); $this->assertFalse($typeName->isNamespaced()); $this->assertNull($typeName->getNamespaceName()); $this->assertEquals('Bar', $typeName->getQualifiedName()); $this->assertEquals('Bar', $typeName->getSimpleName()); } } type-1.1.3/tests/unit/TypeTest.php000066400000000000000000000077211350661054700171260ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\Type\Type * * @uses \SebastianBergmann\Type\SimpleType * @uses \SebastianBergmann\Type\GenericObjectType * @uses \SebastianBergmann\Type\ObjectType * @uses \SebastianBergmann\Type\TypeName * @uses \SebastianBergmann\Type\CallableType * @uses \SebastianBergmann\Type\IterableType */ final class TypeTest extends TestCase { /** * @dataProvider valuesToNullableType */ public function testTypeMappingFromValue($value, bool $allowsNull, Type $expectedType): void { $this->assertEquals($expectedType, Type::fromValue($value, $allowsNull)); } public function valuesToNullableType(): array { return [ '?null' => [null, true, new NullType], 'null' => [null, false, new NullType], '?integer' => [1, true, new SimpleType('int', true, 1)], 'integer' => [1, false, new SimpleType('int', false, 1)], '?boolean' => [true, true, new SimpleType('bool', true, true)], 'boolean' => [true, false, new SimpleType('bool', false, true)], '?object' => [new \stdClass, true, new ObjectType(TypeName::fromQualifiedName(\stdClass::class), true)], 'object' => [new \stdClass, false, new ObjectType(TypeName::fromQualifiedName(\stdClass::class), false)], ]; } /** * @dataProvider namesToTypes */ public function testTypeMappingFromName(string $typeName, bool $allowsNull, $expectedType): void { $this->assertEquals($expectedType, Type::fromName($typeName, $allowsNull)); } public function namesToTypes(): array { return [ '?void' => ['void', true, new VoidType], 'void' => ['void', false, new VoidType], '?null' => ['null', true, new NullType], 'null' => ['null', true, new NullType], '?int' => ['int', true, new SimpleType('int', true)], '?integer' => ['integer', true, new SimpleType('int', true)], 'int' => ['int', false, new SimpleType('int', false)], 'bool' => ['bool', false, new SimpleType('bool', false)], 'boolean' => ['boolean', false, new SimpleType('bool', false)], 'object' => ['object', false, new GenericObjectType(false)], 'real' => ['real', false, new SimpleType('float', false)], 'double' => ['double', false, new SimpleType('float', false)], 'float' => ['float', false, new SimpleType('float', false)], 'string' => ['string', false, new SimpleType('string', false)], 'array' => ['array', false, new SimpleType('array', false)], 'resource' => ['resource', false, new SimpleType('resource', false)], 'resource (closed)' => ['resource (closed)', false, new SimpleType('resource (closed)', false)], 'unknown type' => ['unknown type', false, new UnknownType], '?classname' => [\stdClass::class, true, new ObjectType(TypeName::fromQualifiedName(\stdClass::class), true)], 'classname' => [\stdClass::class, false, new ObjectType(TypeName::fromQualifiedName(\stdClass::class), false)], 'callable' => ['callable', false, new CallableType(false)], '?callable' => ['callable', true, new CallableType(true)], 'iterable' => ['iterable', false, new IterableType(false)], '?iterable' => ['iterable', true, new IterableType(true)], ]; } } type-1.1.3/tests/unit/UnknownTypeTest.php000066400000000000000000000026161350661054700205040ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\Type\UnknownType */ final class UnknownTypeTest extends TestCase { /** * @var UnknownType */ private $type; protected function setUp(): void { $this->type = new UnknownType; } /** * @dataProvider assignableTypes */ public function testIsAssignable(Type $assignableType): void { $this->assertTrue($this->type->isAssignable($assignableType)); } public function assignableTypes(): array { return [ [new SimpleType('int', false)], [new SimpleType('int', true)], [new VoidType], [new ObjectType(TypeName::fromQualifiedName(self::class), false)], [new ObjectType(TypeName::fromQualifiedName(self::class), true)], [new UnknownType], ]; } public function testAllowsNull(): void { $this->assertTrue($this->type->allowsNull()); } public function testReturnTypeDeclaration(): void { $this->assertEquals('', $this->type->getReturnTypeDeclaration()); } } type-1.1.3/tests/unit/VoidTypeTest.php000066400000000000000000000032251350661054700177430ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\Type; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\Type\VoidType */ final class VoidTypeTest extends TestCase { /** * @dataProvider assignableTypes */ public function testIsAssignable(Type $assignableType): void { $type = new VoidType; $this->assertTrue($type->isAssignable($assignableType)); } public function assignableTypes(): array { return [ [new VoidType], ]; } /** * @dataProvider notAssignableTypes */ public function testIsNotAssignable(Type $assignableType): void { $type = new VoidType; $this->assertFalse($type->isAssignable($assignableType)); } public function notAssignableTypes(): array { return [ [new SimpleType('int', false)], [new SimpleType('int', true)], [new ObjectType(TypeName::fromQualifiedName(self::class), false)], [new ObjectType(TypeName::fromQualifiedName(self::class), true)], [new UnknownType], ]; } public function testNotAllowNull(): void { $type = new VoidType; $this->assertFalse($type->allowsNull()); } public function testCanGenerateReturnTypeDeclaration(): void { $type = new VoidType; $this->assertEquals(': void', $type->getReturnTypeDeclaration()); } }