Skip to content

Commit

Permalink
Support PHP 8.0 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
markuspoerschke committed Apr 13, 2021
1 parent b875d34 commit 0c999a7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Expand Up @@ -14,6 +14,7 @@ jobs:
php-version:
- "7.3"
- "7.4"
- "8.0"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 0.3.1

* Support PHP 8

## 0.3.0

### Added
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -19,14 +19,14 @@
}
],
"require": {
"php": ">=7.3",
"php": "~7.3.0 || ~7.4.0 || ~8.0.0",
"phpdocumentor/reflection-docblock": "^5",
"twig/twig": "^3.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.3",
"friendsofphp/php-cs-fixer": "^2.16.3",
"phpunit/phpunit": "^8",
"phpunit/phpunit": "^9",
"symfony/var-dumper": "^3 || ^4",
"vimeo/psalm": "^4.7.0"
},
Expand Down
36 changes: 30 additions & 6 deletions src/Describer/AbstractDescriber.php
Expand Up @@ -19,6 +19,8 @@
use phpDocumentor\Reflection\DocBlockFactoryInterface;
use ReflectionClass;
use ReflectionFunction;
use ReflectionNamedType;
use ReflectionParameter;

abstract class AbstractDescriber
{
Expand Down Expand Up @@ -108,6 +110,9 @@ private function describeDocBlock(Description $description, DocBlock $docBlock):
return $description;
}

/**
* @param ReflectionParameter[] $reflectionParameters
*/
private function describeParameters(Description $description, ?DocBlock $docBlock, array $reflectionParameters, int $skipParameters): Description
{
if (count($reflectionParameters) <= $skipParameters) {
Expand All @@ -129,29 +134,48 @@ private function describeParameters(Description $description, ?DocBlock $docBloc
}

foreach ($reflectionParameters as $parameter) {
$paramterDescription = new ParameterDescription($parameter->getName());
$parameterDescription = new ParameterDescription($parameter->getName());

if ($parameter->hasType()) {
$paramterDescription = $paramterDescription->withType($parameter->getType()->getName());
$type = $parameter->getType();

/**
* @psalm-suppress TypeDoesNotContainType
* @psalm-suppress UndefinedClass
*/
if ($type instanceof \ReflectionUnionType) {
$typeName = implode(
'|',
array_map(
static function (ReflectionNamedType $namedType) { return $namedType->getName(); },
$type->getTypes()
)
);
} else {
assert($type instanceof ReflectionNamedType);
$typeName = $type->getName();
}

$parameterDescription = $parameterDescription->withType($typeName);
}

if ($parameter->isDefaultValueAvailable()) {
if ($parameter->isDefaultValueConstant()) {
$paramterDescription = $paramterDescription->withDefaultValue($parameter->getDefaultValueConstantName());
$parameterDescription = $parameterDescription->withDefaultValue((string) $parameter->getDefaultValueConstantName());
} else {
$paramterDescription = $paramterDescription->withDefaultValue($this->formatDefaultValue($parameter->getDefaultValue()));
$parameterDescription = $parameterDescription->withDefaultValue($this->formatDefaultValue($parameter->getDefaultValue()));
}
}

if (isset($paramTags[$parameter->getName()])) {
$tag = $paramTags[$parameter->getName()];
$tagDescription = $tag->getDescription();
if ($tagDescription !== null) {
$paramterDescription = $paramterDescription->withSummary($tagDescription->__toString());
$parameterDescription = $parameterDescription->withSummary($tagDescription->__toString());
}
}

$description = $description->withParameter($paramterDescription);
$description = $description->withParameter($parameterDescription);
}

return $description;
Expand Down

0 comments on commit 0c999a7

Please sign in to comment.