https://github.com/dneustadt/type-checker
Simple implementation for asserting PHP7 scalar type declarations and return types
https://github.com/dneustadt/type-checker
assert check class equals hints instance name php7 return scalar test type
Last synced: 6 months ago
JSON representation
Simple implementation for asserting PHP7 scalar type declarations and return types
- Host: GitHub
- URL: https://github.com/dneustadt/type-checker
- Owner: dneustadt
- License: mit
- Created: 2018-11-22T10:28:21.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-22T10:48:43.000Z (almost 7 years ago)
- Last Synced: 2024-11-09T09:20:13.483Z (11 months ago)
- Topics: assert, check, class, equals, hints, instance, name, php7, return, scalar, test, type
- Language: PHP
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE.MD
Awesome Lists containing this project
README
TypeChecker
=====Simple implementation for asserting PHP7 scalar type declarations and return types.
`composer require dneustadt/type-checker`
## Example
```php
function test_function(string $foo): string
{
return '';
}class TestClass extends ReflectionClass
{
protected function return_string(): string
{
return '';
}protected function return_class(): TestClass
{
return $this;
}protected function test_parameters(
string $foo,
TestClass $bar
): bool {
unset($foo, $bar);return false;
}
}\TypeChecker\TypeChecker::reflectFunction('test_function')
->returnTypeIsEqual('string');
// true\TypeChecker\TypeChecker::reflectMethod('return_string', TestClass::class)
->returnTypeIsEqual('string');
// true\TypeChecker\TypeChecker::reflectMethod('return_class', TestClass::class)
->returnTypeIsInstanceOf('ReflectionClass');
// true\TypeChecker\TypeChecker::reflectFunction('test_function')
->getArgument(0)
->typeIsEqual('bool');
// false\TypeChecker\TypeChecker::reflectMethod('test_parameters', TestClass::class)
->getArgument(1)
->typeIsInstanceOf('ReflectionClass');
// true
```