Skip to content

Commit

Permalink
Merge pull request #1420 from kylekatarnls/local-options
Browse files Browse the repository at this point in the history
Local options
  • Loading branch information
kylekatarnls authored Aug 13, 2018
2 parents 44df715 + 0227527 commit 0a3aecf
Show file tree
Hide file tree
Showing 19 changed files with 830 additions and 127 deletions.
91 changes: 68 additions & 23 deletions phpdoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,37 +409,45 @@ function dumpValue($value)
}
}

$autoDoc = '';
$columnsMaxLengths = [];
foreach ($autoDocLines as $line) {
if (is_array($line)) {
foreach ($line as $column => $text) {
$length = strlen($text);
$max = $columnsMaxLengths[$column] ?? 0;
if ($length > $max) {
$columnsMaxLengths[$column] = $length;
function compileDoc($autoDocLines)
{
$autoDoc = '';
$columnsMaxLengths = [];
foreach ($autoDocLines as $line) {
if (is_array($line)) {
foreach ($line as $column => $text) {
$length = strlen($text);
$max = $columnsMaxLengths[$column] ?? 0;
if ($length > $max) {
$columnsMaxLengths[$column] = $length;
}
}
}
}
}
foreach ($autoDocLines as $line) {
$autoDoc .= "\n *";
if (is_string($line)) {
if (!empty($line)) {
$autoDoc .= " $line";

foreach ($autoDocLines as $line) {
$autoDoc .= "\n *";
if (is_string($line)) {
if (!empty($line)) {
$autoDoc .= " $line";
}

continue;
}

continue;
}
$computedLine = ' ';
foreach ($line as $column => $text) {
$computedLine .= str_pad($text, $columnsMaxLengths[$column] + 1, ' ', STR_PAD_RIGHT);
}

$computedLine = ' ';
foreach ($line as $column => $text) {
$computedLine .= str_pad($text, $columnsMaxLengths[$column] + 1, ' ', STR_PAD_RIGHT);
$autoDoc .= rtrim($computedLine);
}

$autoDoc .= rtrim($computedLine);
return $autoDoc;
}

$autoDoc = compileDoc($autoDocLines);

$files = new stdClass();

foreach ([$trait, $carbon, $immutable, $interface] as $file) {
Expand All @@ -449,6 +457,8 @@ function dumpValue($value)
}, $content, 1);
}

$staticMethods = [];
$staticImmutableMethods = [];
$methods = '';
$carbonMethods = get_class_methods(\Carbon\Carbon::class);
sort($carbonMethods);
Expand Down Expand Up @@ -477,6 +487,28 @@ function dumpValue($value)

return $output;
}, $function->getParameters()));
if (substr($method, 0, 2) !== '__' && $function->isStatic()) {
$doc = preg_replace('/^\/\*+\n([\s\S]+)\s*\*\//', '$1', $function->getDocComment());
$doc = preg_replace('/^\s*\*\s?/m', '', $doc);
$doc = explode("\n@", $doc, 2);
$doc = preg_split('/(\r\n|\r|\n)/', trim($doc[0]));
$staticMethods[] = [
'@method',
$function->getReturnType() ?: 'Carbon',
"$method($parameters)",
$doc[0],
];
$staticImmutableMethods[] = [
'@method',
$function->getReturnType() ?: 'CarbonImmutable',
"$method($parameters)",
$doc[0],
];
for ($i = 1; $i < count($doc); $i++) {
$staticMethods[] = ['', '', '', $doc[$i]];
$staticImmutableMethods[] = ['', '', '', $doc[$i]];
}
}
$return = $function->getReturnType() ? ': '.$function->getReturnType()->getName() : '';
$methods .= "\n\n public$static function $method($parameters)$return;";
}
Expand All @@ -486,6 +518,19 @@ function dumpValue($value)
return $matches[1]."$methods\n\n // ".$matches[3];
}, $files->$interface, 1);

foreach ([$trait, $carbon, $immutable, $interface] as $file) {
file_put_contents($file, $files->$file);
$factories = [
__DIR__.'/src/Carbon/Factory.php' => $staticMethods,
__DIR__.'/src/Carbon/FactoryImmutable.php' => $staticImmutableMethods,
];

foreach ($factories as $file => $methods) {
$autoDoc = compileDoc($methods);
$content = file_get_contents($file);
$files->$file = preg_replace_callback('/(<autodoc[\s\S]*>)([\s\S]+)(<\/autodoc>)/mU', function ($matches) use ($file, $autoDoc) {
return $matches[1]."\n *$autoDoc\n *\n * ".$matches[3];
}, $content, 1);
}

foreach ($files as $file => $contents) {
file_put_contents($file, $contents);
}
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
<testsuite name="laravel">
<directory>tests/Laravel</directory>
</testsuite>
<testsuite name="factory">
<directory>tests/Factory</directory>
</testsuite>
</testsuites>
</phpunit>
36 changes: 18 additions & 18 deletions src/Carbon/Carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,6 @@
* @method bool isThursday() Checks if the instance day is thursday.
* @method bool isFriday() Checks if the instance day is friday.
* @method bool isSaturday() Checks if the instance day is saturday.
* @method bool isCurrentMonth() Checks if the instance is in the same month as the current moment.
* @method bool isNextMonth() Checks if the instance is in the same month as the current moment next month.
* @method bool isLastMonth() Checks if the instance is in the same month as the current moment last month.
* @method bool isCurrentQuarter() Checks if the instance is in the same quarter as the current moment.
* @method bool isNextQuarter() Checks if the instance is in the same quarter as the current moment next quarter.
* @method bool isLastQuarter() Checks if the instance is in the same quarter as the current moment last quarter.
* @method bool isSameDecade(\DateTimeInterface $date = null) Checks if the given date is in the same decade as the instance. If null passed, compare to now (with the same timezone).
* @method bool isCurrentDecade() Checks if the instance is in the same decade as the current moment.
* @method bool isNextDecade() Checks if the instance is in the same decade as the current moment next decade.
* @method bool isLastDecade() Checks if the instance is in the same decade as the current moment last decade.
* @method bool isSameCentury(\DateTimeInterface $date = null) Checks if the given date is in the same century as the instance. If null passed, compare to now (with the same timezone).
* @method bool isCurrentCentury() Checks if the instance is in the same century as the current moment.
* @method bool isNextCentury() Checks if the instance is in the same century as the current moment next century.
* @method bool isLastCentury() Checks if the instance is in the same century as the current moment last century.
* @method bool isSameMillennium(\DateTimeInterface $date = null) Checks if the given date is in the same millennium as the instance. If null passed, compare to now (with the same timezone).
* @method bool isCurrentMillennium() Checks if the instance is in the same millennium as the current moment.
* @method bool isNextMillennium() Checks if the instance is in the same millennium as the current moment next millennium.
* @method bool isLastMillennium() Checks if the instance is in the same millennium as the current moment last millennium.
* @method bool isSameYear(\DateTimeInterface $date = null) Checks if the given date is in the same year as the instance. If null passed, compare to now (with the same timezone).
* @method bool isCurrentYear() Checks if the instance is in the same year as the current moment.
* @method bool isNextYear() Checks if the instance is in the same year as the current moment next year.
Expand Down Expand Up @@ -163,6 +145,24 @@
* @method bool isCurrentMicrosecond() Checks if the instance is in the same microsecond as the current moment.
* @method bool isNextMicrosecond() Checks if the instance is in the same microsecond as the current moment next microsecond.
* @method bool isLastMicrosecond() Checks if the instance is in the same microsecond as the current moment last microsecond.
* @method bool isCurrentMonth() Checks if the instance is in the same month as the current moment.
* @method bool isNextMonth() Checks if the instance is in the same month as the current moment next month.
* @method bool isLastMonth() Checks if the instance is in the same month as the current moment last month.
* @method bool isCurrentQuarter() Checks if the instance is in the same quarter as the current moment.
* @method bool isNextQuarter() Checks if the instance is in the same quarter as the current moment next quarter.
* @method bool isLastQuarter() Checks if the instance is in the same quarter as the current moment last quarter.
* @method bool isSameDecade(\DateTimeInterface $date = null) Checks if the given date is in the same decade as the instance. If null passed, compare to now (with the same timezone).
* @method bool isCurrentDecade() Checks if the instance is in the same decade as the current moment.
* @method bool isNextDecade() Checks if the instance is in the same decade as the current moment next decade.
* @method bool isLastDecade() Checks if the instance is in the same decade as the current moment last decade.
* @method bool isSameCentury(\DateTimeInterface $date = null) Checks if the given date is in the same century as the instance. If null passed, compare to now (with the same timezone).
* @method bool isCurrentCentury() Checks if the instance is in the same century as the current moment.
* @method bool isNextCentury() Checks if the instance is in the same century as the current moment next century.
* @method bool isLastCentury() Checks if the instance is in the same century as the current moment last century.
* @method bool isSameMillennium(\DateTimeInterface $date = null) Checks if the given date is in the same millennium as the instance. If null passed, compare to now (with the same timezone).
* @method bool isCurrentMillennium() Checks if the instance is in the same millennium as the current moment.
* @method bool isNextMillennium() Checks if the instance is in the same millennium as the current moment next millennium.
* @method bool isLastMillennium() Checks if the instance is in the same millennium as the current moment last millennium.
* @method $this years(int $value) Set current instance year to the given value.
* @method $this year(int $value) Set current instance year to the given value.
* @method $this setYears(int $value) Set current instance year to the given value.
Expand Down
Loading

0 comments on commit 0a3aecf

Please sign in to comment.