Skip to content

Commit

Permalink
Merge pull request #2155 from kylekatarnls/feature/issue-2119-single-…
Browse files Browse the repository at this point in the history
…dff-methods-set

#2119 Dedupe the dff methods set
  • Loading branch information
kylekatarnls authored Aug 12, 2020
2 parents 8d1d67f + 77dc26f commit c935008
Show file tree
Hide file tree
Showing 45 changed files with 1,295 additions and 1,336 deletions.
21 changes: 17 additions & 4 deletions phpdoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ function compileDoc($autoDocLines, $file)

$autoDoc = '';
$columnsMaxLengths = [];

foreach ($autoDocLines as &$editableLine) {
if (is_array($editableLine)) {
if (($editableLine[1] ?? '') === 'self') {
Expand Down Expand Up @@ -521,8 +522,20 @@ function compileDoc($autoDocLines, $file)
$methods = '';
$carbonMethods = get_class_methods(\Carbon\Carbon::class);
sort($carbonMethods);

function getMethodReturnType(ReflectionMethod $method)
{
$type = $method->getReturnType();

if (!$type || $type->getName() === 'self') {
return '';
}

return ': '.preg_replace('/^Carbon\\\\/', '', $type->getName());
}

foreach ($carbonMethods as $method) {
if (method_exists(\Carbon\CarbonImmutable::class, $method) && !method_exists(DateTimeInterface::class, $method)) {
if ($method === 'diff' || method_exists(\Carbon\CarbonImmutable::class, $method) && !method_exists(DateTimeInterface::class, $method)) {
$function = new ReflectionMethod(\Carbon\Carbon::class, $method);
$static = $function->isStatic() ? ' static' : '';
$parameters = implode(', ', array_map(function (ReflectionParameter $parameter) use ($method) {
Expand All @@ -548,13 +561,13 @@ function compileDoc($autoDocLines, $file)
$returnType = str_replace('static|CarbonInterface', 'static', $returnType ?: 'static');
$staticMethods[] = [
'@method',
str_replace('static', 'Carbon', $returnType),
str_replace(['self', 'static'], 'Carbon', $returnType),
"$method($parameters)",
$doc[0],
];
$staticImmutableMethods[] = [
'@method',
str_replace('static', 'CarbonImmutable', $returnType),
str_replace(['self', 'static'], 'CarbonImmutable', $returnType),
"$method($parameters)",
$doc[0],
];
Expand All @@ -565,7 +578,7 @@ function compileDoc($autoDocLines, $file)
}
}

$return = $function->getReturnType() ? ': '.$function->getReturnType()->getName() : '';
$return = getMethodReturnType($function);

if (!empty($methodDocBlock)) {
$methodDocBlock = "\n $methodDocBlock";
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ parameters:
ignoreErrors:
- '#^Call to an undefined static method#'
- '#^Call to an undefined method .*::(foo|foobar|this)\(\)\.$#'
- '#^Call to an undefined method Carbon\\Carbon(Immutable)?::floatDiffIn([A-Za-z]+)\(\)\.$#'
- '#^Call to an undefined method Carbon\\Carbon(Immutable)?::diffInReal([A-Za-z]+)\(\)\.$#'
- '#^Unsafe usage of new static\(\)\.#'
- '#^Method Carbon\\Carbon(Interface|Immutable)?::(add|sub)[A-Z][A-Za-z]+\(\) invoked with 1 parameter, 0 required\.#'
- '#^Variable \$this in isset\(\) (always exists and is not nullable|is never defined)\.$#'
Expand Down
Loading

0 comments on commit c935008

Please sign in to comment.