Skip to content

Commit

Permalink
Add generic unitOfUnit setter
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Nov 19, 2023
1 parent 04faa67 commit e49fabe
Show file tree
Hide file tree
Showing 6 changed files with 502 additions and 440 deletions.
27 changes: 22 additions & 5 deletions phpdoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ function dumpParameter(string $method, ReflectionParameter $parameter): string
}

$deprecated = [];
$unitOfUnit = [];

foreach ($tags as $tag) {
if (\is_array($tag)) {
Expand All @@ -179,6 +178,7 @@ function dumpParameter(string $method, ReflectionParameter $parameter): string
continue;
}

$unitOfUnit = [];
preg_match_all('/\/\/ @'.$tag.'\s+(?<type>'.$pattern.')(?:\s+\$(?<name>\S+)(?:[^\S\n](?<description>.*))?\n|(?:[^\S\n](?<description2>.*))?\n(?<comments>(?:[ \t]+\/\/[^\n]*\n)*)[^\']*\'(?<name2>[^\']+)\')/', $code, $matches, PREG_SET_ORDER);

foreach ($matches as $match) {
Expand Down Expand Up @@ -521,10 +521,10 @@ function dumpParameter(string $method, ReflectionParameter $parameter): string

if (
\in_array($tag, ['property', 'property-read'], true) &&
preg_match('/^([a-z]{2,})(In|Of)([A-Z][a-z]+)$/', $vars->name)
preg_match('/^[a-z]{2,}(?<operator>In|Of)[A-Z][a-z]+$/', $vars->name, $match)
) {
$unitOfUnit[$vars->name] = [
'@'.$tag,
'@'.($match['operator'] === 'Of' ? 'property' : 'property-read'),
$vars->type,
'$'.$variable,
$description ?: '',
Expand All @@ -541,7 +541,7 @@ function dumpParameter(string $method, ReflectionParameter $parameter): string
];
}

if ($tag === 'property-read') {
if ($tag === 'property') {
$units = ['microseconds', 'milliseconds', 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'quarters', 'years', 'decades', 'centuries', 'millennia'];

foreach ($units as $small) {
Expand All @@ -557,9 +557,26 @@ function dumpParameter(string $method, ReflectionParameter $parameter): string
'$'.$name,
'The value of the '.$singularSmall.' starting from the beginning of the current '.$singularBig,
];
}
}

ksort($unitOfUnit);

array_push($autoDocLines, ...array_values($unitOfUnit));
}

if ($tag === 'property-read') {
$units = ['microseconds', 'milliseconds', 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'quarters', 'years', 'decades', 'centuries', 'millennia'];

foreach ($units as $small) {
array_shift($units);

foreach ($units as $big) {
$singularSmall = Carbon::singularUnit($small);
$singularBig = Carbon::singularUnit($big);
$name = $small.'In'.ucfirst($singularBig);
$unitOfUnit[$name] ??= [
'@property',
'@property-read',
'int',
'$'.$name,
'The number of '.$small.' contained in the current '.$singularBig,
Expand Down
Loading

0 comments on commit e49fabe

Please sign in to comment.