Skip to content

Commit

Permalink
Merge pull request #2160 from kylekatarnls/feature/issue-2119-absolut…
Browse files Browse the repository at this point in the history
…e-diff-flag

Fix #2119 absolute diff flag
  • Loading branch information
kylekatarnls authored Aug 16, 2020
2 parents f43ff0e + 1320852 commit 8dcaa5a
Show file tree
Hide file tree
Showing 50 changed files with 1,594 additions and 1,531 deletions.
10 changes: 1 addition & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,7 @@ branches:

matrix:
include:
- php: 7.1.8
- php: 7.1.28
- php: 7.1
- php: 7.1
env: setup=lowest
- php: 7.1
env: setup=stable

- php: 7.2.0
- php: 7.2.5
- php: 7.2.15
- php: 7.2
- php: 7.2
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
"minimum-stability": "dev",
"bin": ["bin/carbon"],
"require": {
"php": "^7.1.8 || ^8.0",
"php": "^7.2.5 || ^8.0",
"ext-json": "*",
"symfony/polyfill-mbstring": "^1.0",
"symfony/translation": "^3.4 || ^4.0 || ^5.0"
"symfony/translation": "^5.0"
},
"require-dev": {
"doctrine/orm": "^2.7",
Expand Down
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
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ 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)\.$#'
- '#^Unary operation "\~" on mixed results in an error\.$#'
- '#^Call to an undefined method Carbon\\Carbon(Interface|Immutable)?::(super|noThis)\(\)\.$#'
- '#Class Symfony\\Component\\Translation\\IdentityTranslator does not have a constructor and must be instantiated without any parameters\.#'
- '#Call to an undefined method DateTimeInterface::setTimezone\(\)\.#'
- '#should return (\S*)static\(Carbon\\CarbonPeriod\) but returns Carbon\\CarbonPeriod\.$#'
- '#should return (\S*)static\(Carbon\\Carbon\) but returns Carbon\\Carbon(Interface)?\.$#'
Expand Down
Loading

0 comments on commit 8dcaa5a

Please sign in to comment.