composer vendor update and .env file fixes, remove debug echo

No more echo for any debug logging
Update .env file sample data
This commit is contained in:
Clemens Schwaighofer
2022-03-16 16:59:12 +09:00
parent b075ee3dc5
commit 35a7229158
38 changed files with 646 additions and 288 deletions
+27
View File
@@ -2,6 +2,31 @@
All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
## [4.0.0] - 2022-MM-DD
### Removed
* This component is no longer supported on PHP 7.3 and PHP 7.4
## [3.0.0] - 2022-03-15
### Added
* Support for intersection types introduced in PHP 8.1
* Support for the `never` return type introduced in PHP 8.1
* Added `Type::isCallable()`, `Type::isGenericObject()`, `Type::isIterable()`, `Type::isMixed()`, `Type::isNever()`, `Type::isNull()`, `Type::isObject()`, `Type::isSimple()`, `Type::isStatic()`, `Type::isUnion()`, `Type::isUnknown()`, and `Type::isVoid()`
### Changed
* Renamed `ReflectionMapper::fromMethodReturnType(ReflectionMethod $method)` to `ReflectionMapper::fromReturnType(ReflectionFunctionAbstract $functionOrMethod)`
### Removed
* Removed `Type::getReturnTypeDeclaration()` (use `Type::asString()` instead and prefix its result with `': '`)
* Removed `TypeName::getNamespaceName()` (use `TypeName::namespaceName()` instead)
* Removed `TypeName::getSimpleName()` (use `TypeName::simpleName()` instead)
* Removed `TypeName::getQualifiedName()` (use `TypeName::qualifiedName()` instead)
## [2.3.4] - 2021-06-15
* Fixed regression introduced in 2.3.3
@@ -105,6 +130,8 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
* Initial release based on [code contributed by Michel Hartmann to PHPUnit](https://github.com/sebastianbergmann/phpunit/pull/3673)
[4.0.0]: https://github.com/sebastianbergmann/type/compare/3.0...master
[3.0.0]: https://github.com/sebastianbergmann/type/compare/2.3.4...3.0.0
[2.3.4]: https://github.com/sebastianbergmann/type/compare/ca39369c41313ed12c071ed38ecda8fcdb248859...2.3.4
[2.3.3]: https://github.com/sebastianbergmann/type/compare/2.3.2...ca39369c41313ed12c071ed38ecda8fcdb248859
[2.3.2]: https://github.com/sebastianbergmann/type/compare/2.3.1...2.3.2
+1 -1
View File
@@ -1,6 +1,6 @@
sebastian/type
Copyright (c) 2019-2020, Sebastian Bergmann <sebastian@phpunit.de>.
Copyright (c) 2019-2022, Sebastian Bergmann <sebastian@phpunit.de>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
+4 -3
View File
@@ -19,7 +19,7 @@
"php": ">=7.3"
},
"require-dev": {
"phpunit/phpunit": "^9.3"
"phpunit/phpunit": "^9.5"
},
"config": {
"platform": {
@@ -38,12 +38,13 @@
"tests/_fixture"
],
"files": [
"tests/_fixture/callback_function.php"
"tests/_fixture/callback_function.php",
"tests/_fixture/functions_that_declare_return_types.php"
]
},
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
"dev-master": "3.0-dev"
}
}
}
+29 -41
View File
@@ -10,7 +10,8 @@
namespace SebastianBergmann\Type;
use function assert;
use function sprintf;
use ReflectionFunctionAbstract;
use ReflectionIntersectionType;
use ReflectionMethod;
use ReflectionNamedType;
use ReflectionType;
@@ -18,27 +19,27 @@ use ReflectionUnionType;
final class ReflectionMapper
{
public function fromMethodReturnType(ReflectionMethod $method): Type
public function fromReturnType(ReflectionFunctionAbstract $functionOrMethod): Type
{
if (!$this->reflectionMethodHasReturnType($method)) {
if (!$this->hasReturnType($functionOrMethod)) {
return new UnknownType;
}
$returnType = $this->reflectionMethodGetReturnType($method);
$returnType = $this->returnType($functionOrMethod);
assert($returnType instanceof ReflectionNamedType || $returnType instanceof ReflectionUnionType);
assert($returnType instanceof ReflectionNamedType || $returnType instanceof ReflectionUnionType || $returnType instanceof ReflectionIntersectionType);
if ($returnType instanceof ReflectionNamedType) {
if ($returnType->getName() === 'self') {
if ($functionOrMethod instanceof ReflectionMethod && $returnType->getName() === 'self') {
return ObjectType::fromName(
$method->getDeclaringClass()->getName(),
$functionOrMethod->getDeclaringClass()->getName(),
$returnType->allowsNull()
);
}
if ($returnType->getName() === 'static') {
if ($functionOrMethod instanceof ReflectionMethod && $returnType->getName() === 'static') {
return new StaticType(
TypeName::fromReflection($method->getDeclaringClass()),
TypeName::fromReflection($functionOrMethod->getDeclaringClass()),
$returnType->allowsNull()
);
}
@@ -47,24 +48,9 @@ final class ReflectionMapper
return new MixedType;
}
if ($returnType->getName() === 'parent') {
$parentClass = $method->getDeclaringClass()->getParentClass();
// @codeCoverageIgnoreStart
if ($parentClass === false) {
throw new RuntimeException(
sprintf(
'%s::%s() has a "parent" return type declaration but %s does not have a parent class',
$method->getDeclaringClass()->getName(),
$method->getName(),
$method->getDeclaringClass()->getName()
)
);
}
// @codeCoverageIgnoreEnd
if ($functionOrMethod instanceof ReflectionMethod && $returnType->getName() === 'parent') {
return ObjectType::fromName(
$parentClass->getName(),
$functionOrMethod->getDeclaringClass()->getParentClass()->getName(),
$returnType->allowsNull()
);
}
@@ -75,16 +61,14 @@ final class ReflectionMapper
);
}
assert($returnType instanceof ReflectionUnionType);
assert($returnType instanceof ReflectionUnionType || $returnType instanceof ReflectionIntersectionType);
$types = [];
foreach ($returnType->getTypes() as $type) {
assert($type instanceof ReflectionNamedType);
if ($type->getName() === 'self') {
if ($functionOrMethod instanceof ReflectionMethod && $type->getName() === 'self') {
$types[] = ObjectType::fromName(
$method->getDeclaringClass()->getName(),
$functionOrMethod->getDeclaringClass()->getName(),
false
);
} else {
@@ -92,32 +76,36 @@ final class ReflectionMapper
}
}
return new UnionType(...$types);
if ($returnType instanceof ReflectionUnionType) {
return new UnionType(...$types);
}
return new IntersectionType(...$types);
}
private function reflectionMethodHasReturnType(ReflectionMethod $method): bool
private function hasReturnType(ReflectionFunctionAbstract $functionOrMethod): bool
{
if ($method->hasReturnType()) {
if ($functionOrMethod->hasReturnType()) {
return true;
}
if (!method_exists($method, 'hasTentativeReturnType')) {
if (!method_exists($functionOrMethod, 'hasTentativeReturnType')) {
return false;
}
return $method->hasTentativeReturnType();
return $functionOrMethod->hasTentativeReturnType();
}
private function reflectionMethodGetReturnType(ReflectionMethod $method): ?ReflectionType
private function returnType(ReflectionFunctionAbstract $functionOrMethod): ?ReflectionType
{
if ($method->hasReturnType()) {
return $method->getReturnType();
if ($functionOrMethod->hasReturnType()) {
return $functionOrMethod->getReturnType();
}
if (!method_exists($method, 'getTentativeReturnType')) {
if (!method_exists($functionOrMethod, 'getTentativeReturnType')) {
return null;
}
return $method->getTentativeReturnType();
return $functionOrMethod->getTentativeReturnType();
}
}
-30
View File
@@ -76,36 +76,6 @@ final class TypeName
: $this->namespaceName . '\\' . $this->simpleName;
}
/**
* @deprecated Use namespaceName() instead
*
* @codeCoverageIgnore
*/
public function getNamespaceName(): ?string
{
return $this->namespaceName();
}
/**
* @deprecated Use simpleName() instead
*
* @codeCoverageIgnore
*/
public function getSimpleName(): string
{
return $this->simpleName();
}
/**
* @deprecated Use qualifiedName() instead
*
* @codeCoverageIgnore
*/
public function getQualifiedName(): string
{
return $this->qualifiedName();
}
public function isNamespaced(): bool
{
return $this->namespaceName !== null;
@@ -1,14 +0,0 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/type.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Type;
final class LogicException extends \LogicException implements Exception
{
}
@@ -17,7 +17,6 @@ use function function_exists;
use function is_array;
use function is_object;
use function is_string;
use function strpos;
use Closure;
use ReflectionClass;
use ReflectionException;
@@ -85,6 +84,11 @@ final class CallableType extends Type
return $this->allowsNull;
}
public function isCallable(): bool
{
return true;
}
private function isClosure(ObjectType $type): bool
{
return !$type->className()->isNamespaced() && $type->className()->simpleName() === Closure::class;
@@ -32,15 +32,8 @@ final class FalseType extends Type
return false;
}
/**
* @deprecated
*
* @codeCoverageIgnore
*
* @throws LogicException
*/
public function getReturnTypeDeclaration(): string
public function isFalse(): bool
{
throw new LogicException;
return true;
}
}
@@ -43,4 +43,9 @@ final class GenericObjectType extends Type
{
return $this->allowsNull;
}
public function isGenericObject(): bool
{
return true;
}
}
+115
View File
@@ -0,0 +1,115 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/type.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Type;
use function array_unique;
use function assert;
use function count;
use function implode;
use function sort;
final class IntersectionType extends Type
{
/**
* @psalm-var list<Type>
*/
private $types;
/**
* @throws RuntimeException
*/
public function __construct(Type ...$types)
{
$this->ensureMinimumOfTwoTypes(...$types);
$this->ensureOnlyValidTypes(...$types);
$this->ensureNoDuplicateTypes(...$types);
$this->types = $types;
}
public function isAssignable(Type $other): bool
{
return $other->isObject();
}
public function asString(): string
{
return $this->name();
}
public function name(): string
{
$types = [];
foreach ($this->types as $type) {
$types[] = $type->name();
}
sort($types);
return implode('&', $types);
}
public function allowsNull(): bool
{
return false;
}
public function isIntersection(): bool
{
return true;
}
/**
* @throws RuntimeException
*/
private function ensureMinimumOfTwoTypes(Type ...$types): void
{
if (count($types) < 2) {
throw new RuntimeException(
'An intersection type must be composed of at least two types'
);
}
}
/**
* @throws RuntimeException
*/
private function ensureOnlyValidTypes(Type ...$types): void
{
foreach ($types as $type) {
if (!$type->isObject()) {
throw new RuntimeException(
'An intersection type can only be composed of interfaces and classes'
);
}
}
}
/**
* @throws RuntimeException
*/
private function ensureNoDuplicateTypes(Type ...$types): void
{
$names = [];
foreach ($types as $type) {
assert($type instanceof ObjectType);
$names[] = $type->className()->qualifiedName();
}
if (count(array_unique($names)) < count($names)) {
throw new RuntimeException(
'An intersection type must not contain duplicate types'
);
}
}
}
@@ -73,4 +73,9 @@ final class IterableType extends Type
{
return $this->allowsNull;
}
public function isIterable(): bool
{
return true;
}
}
@@ -30,4 +30,9 @@ final class MixedType extends Type
{
return true;
}
public function isMixed(): bool
{
return true;
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);
/*
* This file is part of sebastian/type.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\Type;
final class NeverType extends Type
{
public function isAssignable(Type $other): bool
{
return $other instanceof self;
}
public function name(): string
{
return 'never';
}
public function allowsNull(): bool
{
return false;
}
public function isNever(): bool
{
return true;
}
}
@@ -26,18 +26,13 @@ final class NullType extends Type
return 'null';
}
/**
* @deprecated
*
* @codeCoverageIgnore
*/
public function getReturnTypeDeclaration(): string
{
return '';
}
public function allowsNull(): bool
{
return true;
}
public function isNull(): bool
{
return true;
}
}
@@ -63,4 +63,9 @@ final class ObjectType extends Type
{
return $this->className;
}
public function isObject(): bool
{
return true;
}
}
@@ -67,6 +67,11 @@ final class SimpleType extends Type
return $this->value;
}
public function isSimple(): bool
{
return true;
}
private function normalize(string $name): string
{
$name = strtolower($name);
@@ -57,4 +57,9 @@ final class StaticType extends Type
{
return $this->allowsNull;
}
public function isStatic(): bool
{
return true;
}
}
@@ -9,9 +9,11 @@
*/
namespace SebastianBergmann\Type;
use const PHP_VERSION;
use function get_class;
use function gettype;
use function strtolower;
use function version_compare;
abstract class Type
{
@@ -38,6 +40,10 @@ abstract class Type
public static function fromName(string $typeName, bool $allowsNull): self
{
if (version_compare(PHP_VERSION, '8.1.0-dev', '>=') && strtolower($typeName) === 'never') {
return new NeverType;
}
switch (strtolower($typeName)) {
case 'callable':
return new CallableType($allowsNull);
@@ -83,17 +89,77 @@ abstract class Type
return ($this->allowsNull() ? '?' : '') . $this->name();
}
/**
* @deprecated
*
* @codeCoverageIgnore
*/
public function getReturnTypeDeclaration(): string
public function isCallable(): bool
{
return ': ' . $this->asString();
return false;
}
abstract public function isAssignable(Type $other): bool;
public function isFalse(): bool
{
return false;
}
public function isGenericObject(): bool
{
return false;
}
public function isIntersection(): bool
{
return false;
}
public function isIterable(): bool
{
return false;
}
public function isMixed(): bool
{
return false;
}
public function isNever(): bool
{
return false;
}
public function isNull(): bool
{
return false;
}
public function isObject(): bool
{
return false;
}
public function isSimple(): bool
{
return false;
}
public function isStatic(): bool
{
return false;
}
public function isUnion(): bool
{
return false;
}
public function isUnknown(): bool
{
return false;
}
public function isVoid(): bool
{
return false;
}
abstract public function isAssignable(self $other): bool;
abstract public function name(): string;
@@ -47,16 +47,6 @@ final class UnionType extends Type
return $this->name();
}
/**
* @deprecated
*
* @codeCoverageIgnore
*/
public function getReturnTypeDeclaration(): string
{
return ': ' . $this->name();
}
public function name(): string
{
$types = [];
@@ -81,6 +71,11 @@ final class UnionType extends Type
return false;
}
public function isUnion(): bool
{
return true;
}
/**
* @throws RuntimeException
*/
@@ -26,18 +26,13 @@ final class UnknownType extends Type
return '';
}
/**
* @deprecated
*
* @codeCoverageIgnore
*/
public function getReturnTypeDeclaration(): string
{
return '';
}
public function allowsNull(): bool
{
return true;
}
public function isUnknown(): bool
{
return true;
}
}
@@ -25,4 +25,9 @@ final class VoidType extends Type
{
return false;
}
public function isVoid(): bool
{
return true;
}
}