diff --git a/tools/check.php b/tools/check.php index 0cf5570dcaf448db8eaf4a3a21d2f3273f55671b..aa7753c5f2920b765a26ec721458f4c8bc331ac7 100644 --- a/tools/check.php +++ b/tools/check.php @@ -19,8 +19,8 @@ require __DIR__.'/../tools/methods.php'; $documentation = implode("\n", array_map( file_get_contents(...), [ - ...glob(__DIR__ . '/../docs/guide/**/*.md'), - ...glob(__DIR__ . '/../docs/parts/**/*.md'), + ...glob(__DIR__.'/../docs/guide/**/*.md'), + ...glob(__DIR__.'/../docs/parts/**/*.md'), ], )); diff --git a/tools/generate-api.php b/tools/generate-api.php index a634f0970b060cb3acce4926987ab75b39d03795..ece7e71776c5548834f259bab14849ceca53a315 100644 --- a/tools/generate-api.php +++ b/tools/generate-api.php @@ -14,24 +14,24 @@ use Symfony\Component\Translation\Translator as SymfonyTranslator; use function Carbon\Doc\Methods\methods; -require __DIR__ . '/../vendor/autoload.php'; -require __DIR__ . '/methods.php'; +require __DIR__.'/../vendor/autoload.php'; +require __DIR__.'/methods.php'; -$destination_file = __DIR__ . '/../docs/develop/reference.md'; +$destination_file = __DIR__.'/../docs/develop/reference.md'; trait MacroExposer { - public function getMacros() - { - $class = get_called_class(); + public function getMacros() + { + $class = get_called_class(); - return $class::$global_macros ?? FactoryImmutable::getDefaultInstance()->getSettings()['macros']; - } + return $class::$global_macros ?? FactoryImmutable::getDefaultInstance()->getSettings()['macros']; + } } class BusinessTimeCarbon extends Carbon { - use MacroExposer; + use MacroExposer; } function history_line($event, $version, $ref): array @@ -57,11 +57,11 @@ function table_markdown(array $table, ?array $header = null): string ); return implode("\n", array_map( - static fn (array $row) => '|' . (str_starts_with($row[0], '--') ? ':' : ' ') . implode(' | ', array_map( + static fn (array $row) => '|'.(str_starts_with($row[0], '--') ? ':' : ' ').implode(' | ', array_map( static fn (string $cell, int $size) => str_pad($cell, $size), $row, $sizes, - )) . ' |', + )).' |', [ $header, array_map(static fn (int $size) => str_repeat('-', $size), $sizes), @@ -72,73 +72,72 @@ function table_markdown(array $table, ?array $header = null): string function get_classes(): Generator { - if (class_exists(Carbon::class)) { - yield [ - new Carbon(), - new DateTime(), + if (class_exists(Carbon::class)) { + yield [ + new Carbon(), + new DateTime(), ]; - if (class_exists(BusinessTime::class)) { - yield [ - BusinessTime::enable(BusinessTimeCarbon::class), - new Carbon(), - Carbon::class, - 'Requires cmixin/business-time', - new BusinessTimeCarbon(), + if (class_exists(BusinessTime::class)) { + yield [ + BusinessTime::enable(BusinessTimeCarbon::class), + new Carbon(), + Carbon::class, + 'Requires cmixin/business-time', + new BusinessTimeCarbon(), ]; - } - - if (trait_exists(SeasonMixin::class)) { - BusinessTimeCarbon::mixin(SeasonMixin::class); - - yield [ - new BusinessTimeCarbon(), - new Carbon(), - Carbon::class, - 'Requires cmixin/season', - new class() extends BusinessTimeCarbon - { - use SeasonMixin; - }, - SeasonMixin::class, + } + + if (trait_exists(SeasonMixin::class)) { + BusinessTimeCarbon::mixin(SeasonMixin::class); + + yield [ + new BusinessTimeCarbon(), + new Carbon(), + Carbon::class, + 'Requires cmixin/season', + new class() extends BusinessTimeCarbon { + use SeasonMixin; + }, + SeasonMixin::class, ]; - } - } + } + } - if (class_exists(CarbonInterval::class)) { - yield [ - new CarbonInterval(0, 0, 0, 1), - new DateInterval('P1D'), + if (class_exists(CarbonInterval::class)) { + yield [ + new CarbonInterval(0, 0, 0, 1), + new DateInterval('P1D'), ]; - } + } - if (class_exists(CarbonPeriod::class)) { - yield [ - new CarbonPeriod(), - new stdClass(), + if (class_exists(CarbonPeriod::class)) { + yield [ + new CarbonPeriod(), + new stdClass(), ]; - } + } - if (class_exists(CarbonTimeZone::class)) { - yield [ - new CarbonTimeZone('Europe/Paris'), - new DateTimeZone('Europe/Paris'), + if (class_exists(CarbonTimeZone::class)) { + yield [ + new CarbonTimeZone('Europe/Paris'), + new DateTimeZone('Europe/Paris'), ]; - } + } - if (class_exists(Translator::class)) { - yield [ - new Translator('en'), - new SymfonyTranslator('en'), + if (class_exists(Translator::class)) { + yield [ + new Translator('en'), + new SymfonyTranslator('en'), ]; - } + } - if (class_exists(Language::class)) { - yield [ - new Language('en'), - new stdClass(), + if (class_exists(Language::class)) { + yield [ + new Language('en'), + new stdClass(), ]; - } + } } function get_doc_blocks(): array @@ -154,7 +153,7 @@ function get_doc_blocks(): array foreach (methods(false, false) as [$carbon_object, $class_name, $method, $parameters, $return, $description, $dateTimeObject, $info]) { $classes[$class_name] ??= new ReflectionClass($class_name); - $name = $classes[$class_name]->getShortName() . '::' . $method; + $name = $classes[$class_name]->getShortName().'::'.$method; try { $doc_comment = $classes[$class_name]->getMethod($method)->getDocComment(); @@ -177,7 +176,7 @@ $markdown = "# Reference\n\n"; $global_history = @json_decode(file_get_contents('history.json'), true); foreach (get_doc_blocks() as $name => $docblock) { - $markdown .= "#### $name\n\n"; + $markdown .= "#### $name\n\n"; if (is_array($docblock)) { [$description, $parameters, $return, $info] = $docblock; @@ -217,55 +216,55 @@ foreach (get_doc_blocks() as $name => $docblock) { } } - $deprecated = $docblock->getTagsByName('deprecated'); + $deprecated = $docblock->getTagsByName('deprecated'); foreach ($deprecated as $tag) { $markdown .= "::: warning Deprectated \n$tag\n:::\n"; } - $parameters = $docblock->getTagsByName('param'); + $parameters = $docblock->getTagsByName('param'); - if ($parameters !== []) { - $markdown .= "##### Parameters\n"; + if ($parameters !== []) { + $markdown .= "##### Parameters\n"; - foreach ($parameters as $tag) { - $markdown .= "- \${$tag->getVariableName()} `{$tag->getType()}`"; - $description = trim($tag->getDescription()); + foreach ($parameters as $tag) { + $markdown .= "- \${$tag->getVariableName()} `{$tag->getType()}`"; + $description = trim($tag->getDescription()); - // if description is multiline, indent lines + // if description is multiline, indent lines $description = str_contains($description, "\n") - ? "\n " . str_replace("\n", "\n ", $description) + ? "\n ".str_replace("\n", "\n ", $description) : " $description"; - $markdown .= "$description\n"; - } + $markdown .= "$description\n"; + } $markdown .= "\n"; - } + } - $return = $docblock->getTagsByName('return'); + $return = $docblock->getTagsByName('return'); foreach ($return as $tag) { $markdown .= "returns `$tag`\n\n"; } - $examples = $docblock->getTagsByName('example'); + $examples = $docblock->getTagsByName('example'); - if ($examples !== []) { - $markdown .= "##### Examples\n"; + if ($examples !== []) { + $markdown .= "##### Examples\n"; - foreach ($examples as $tag) { - $value = trim($tag->__toString()); + foreach ($examples as $tag) { + $value = trim($tag->__toString()); - // add ```php` if not specified - $markdown .= preg_replace('/^```(?!\w)/m', '```php', $value, 1) . "\n"; - } + // add ```php` if not specified + $markdown .= preg_replace('/^```(?!\w)/m', '```php', $value, 1)."\n"; + } $markdown .= "\n"; - } + } $history = []; [$class_name, $method] = explode('::', $name); - $fqcn = 'Carbon\\' . $class_name; + $fqcn = 'Carbon\\'.$class_name; $key = class_exists($fqcn) ? "$fqcn::$method" : $name; $parameters = implode(', ', $parameters ?: []); @@ -290,7 +289,7 @@ foreach (get_doc_blocks() as $name => $docblock) { } if ($history !== []) { - $markdown .= table_markdown($history, ['History', 'Version', 'Description']) . "\n\n"; + $markdown .= table_markdown($history, ['History', 'Version', 'Description'])."\n\n"; } $markdown .= "----------\n\n"; diff --git a/tools/generate-backers.php b/tools/generate-backers.php index c2bf814a7d746d7f82e9a13342c79e81ed855be7..bf74701d4cdeaf8a115dfdee5cf9d9b161957ffc 100644 --- a/tools/generate-backers.php +++ b/tools/generate-backers.php @@ -6,99 +6,99 @@ namespace Carbon\Doc\Sponsors; use Carbon\CarbonImmutable; -require __DIR__ . '/../vendor/autoload.php'; +require __DIR__.'/../vendor/autoload.php'; -$destination_file = __DIR__ . '/../docs/public/data/backers.json'; +$destination_file = __DIR__.'/../docs/public/data/backers.json'; function get_custom_sponsor_override(): array { - return [ + return [ - // For consistency and equity among sponsors, as of now, we kindly ask our sponsors - // to provide an image having a width/height ratio between 1/1 and 2/1. - // By default, we'll show the member picture from OpenCollective, and will resize it if bigger - 662698 => [ + // For consistency and equity among sponsors, as of now, we kindly ask our sponsors + // to provide an image having a width/height ratio between 1/1 and 2/1. + // By default, we'll show the member picture from OpenCollective, and will resize it if bigger + 662698 => [ - // alt attribute - 'name' => 'Non Gamstop Casinos', + // alt attribute + 'name' => 'Non Gamstop Casinos', - // title attribute - 'description' => 'Casinos not on Gamstop', + // title attribute + 'description' => 'Casinos not on Gamstop', - // src attribute - 'image' => 'https://camo.githubusercontent.com/bdb8b8112771c6c3c6a86f5dfd789749542488474d767e5296f75d0c91d6d8e3/68747470733a2f2f6c67636e6577732e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031382f30312f4c47432d6c6f676f2d76382d74656d702e706e67', + // src attribute + 'image' => 'https://camo.githubusercontent.com/bdb8b8112771c6c3c6a86f5dfd789749542488474d767e5296f75d0c91d6d8e3/68747470733a2f2f6c67636e6577732e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031382f30312f4c47432d6c6f676f2d76382d74656d702e706e67', - // href attribute - 'website' => 'https://lgcnews.com/', + // href attribute + 'website' => 'https://lgcnews.com/', ], - 663069 => [ + 663069 => [ - // alt attribute - 'name' => 'Ставки на спорт Favbet', + // alt attribute + 'name' => 'Ставки на спорт Favbet', - // href attribute - 'website' => 'https://www.favbet.ua/uk/', + // href attribute + 'website' => 'https://www.favbet.ua/uk/', ], - 676798 => [ + 676798 => [ - // alt attribute - 'name' => 'Top Casinos Canada', + // alt attribute + 'name' => 'Top Casinos Canada', - // title attribute - 'description' => 'Top Casinos Canada', + // title attribute + 'description' => 'Top Casinos Canada', - // href attribute - 'website' => 'https://topcasino.net/', + // href attribute + 'website' => 'https://topcasino.net/', ], ]; } function get_all_backers(): array { - $custom_sponsor_override = get_custom_sponsor_override(); - - $members = json_decode(file_get_contents('https://opencollective.com/carbon/members/all.json'), true); - - foreach ($members as &$member) { - $member = array_merge($member, $custom_sponsor_override[$member['MemberId']] ?? []); - } - - $members[] = [ - 'MemberId' => 1, - 'createdAt' => '2019-01-01 02:00', - 'type' => 'ORGANIZATION', - 'role' => 'BACKER', - 'tier' => 'backer+', - 'isActive' => true, - 'totalAmountDonated' => 1000, - 'currency' => 'USD', - 'lastTransactionAt' => CarbonImmutable::now()->format('Y-m-d') . ' 02:00', - 'lastTransactionAmount' => 25, - 'profile' => 'https://tidelift.com/', - 'name' => 'Tidelift', - 'description' => 'Get professional support for Carbon', - 'image' => '/sponsors/tidelift-brand.png', - 'website' => 'https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=docs', + $custom_sponsor_override = get_custom_sponsor_override(); + + $members = json_decode(file_get_contents('https://opencollective.com/carbon/members/all.json'), true); + + foreach ($members as &$member) { + $member = array_merge($member, $custom_sponsor_override[$member['MemberId']] ?? []); + } + + $members[] = [ + 'MemberId' => 1, + 'createdAt' => '2019-01-01 02:00', + 'type' => 'ORGANIZATION', + 'role' => 'BACKER', + 'tier' => 'backer+', + 'isActive' => true, + 'totalAmountDonated' => 1000, + 'currency' => 'USD', + 'lastTransactionAt' => CarbonImmutable::now()->format('Y-m-d').' 02:00', + 'lastTransactionAmount' => 25, + 'profile' => 'https://tidelift.com/', + 'name' => 'Tidelift', + 'description' => 'Get professional support for Carbon', + 'image' => '/sponsors/tidelift-brand.png', + 'website' => 'https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=docs', ]; - $members[] = [ - 'MemberId' => 2, - 'createdAt' => '2024-11-14 02:00', - 'type' => 'ORGANIZATION', - 'role' => 'BACKER', - 'tier' => 'backer+ yearly', - 'isActive' => true, - 'totalAmountDonated' => 170, - 'currency' => 'USD', - 'lastTransactionAt' => '2024-11-14 02:00', - 'lastTransactionAmount' => 170, - 'profile' => 'https://www.slotozilla.com/nz/free-spins', - 'name' => 'Slotozilla', - 'description' => 'Slotozilla website', - 'image' => '/sponsors/slotozilla.png', - 'website' => 'https://www.slotozilla.com/nz/free-spins', + $members[] = [ + 'MemberId' => 2, + 'createdAt' => '2024-11-14 02:00', + 'type' => 'ORGANIZATION', + 'role' => 'BACKER', + 'tier' => 'backer+ yearly', + 'isActive' => true, + 'totalAmountDonated' => 170, + 'currency' => 'USD', + 'lastTransactionAt' => '2024-11-14 02:00', + 'lastTransactionAmount' => 170, + 'profile' => 'https://www.slotozilla.com/nz/free-spins', + 'name' => 'Slotozilla', + 'description' => 'Slotozilla website', + 'image' => '/sponsors/slotozilla.png', + 'website' => 'https://www.slotozilla.com/nz/free-spins', ]; - return array_map(static function(array $member) { + return array_map(static function (array $member) { $created_at = CarbonImmutable::parse($member['createdAt']); $last_transaction_at = CarbonImmutable::parse($member['lastTransactionAt']); @@ -114,7 +114,7 @@ function get_all_backers(): array ? ($member['lastTransactionAmount'] / 11.2) // 11.2 instead of 12 to include the discount for yearly subscription : ($member['totalAmountDonated'] / ceil($created_at->floatDiffInMonths())) - ); + ); if (!$is_yearly) { if ( @@ -134,7 +134,7 @@ function get_all_backers(): array $is_yearly ? (12 * $monthly_contribution) : ($member['totalAmountDonated'] / max(1, $created_at->floatDiffInYears())) - ); + ); $status = null; $rank = 0; @@ -168,54 +168,54 @@ function get_all_backers(): array file_put_contents($destination_file, json_encode(get_all_backers(), JSON_UNESCAPED_SLASHES)); function get_open_collective(string $status): string { - static $content = []; - static $members = null; + static $content = []; + static $members = null; - $members = $members ?? getAllBackers(); + $members = $members ?? getAllBackers(); - if (!isset($content[$status])) { - $list = array_filter($members, static fn ($item) => ($item['status'] ?? null) === $status); + if (!isset($content[$status])) { + $list = array_filter($members, static fn ($item) => ($item['status'] ?? null) === $status); - usort($list, static fn (array $a, array $b) => ( - ($b['star'] <=> $a['star']) - ?: ($b['rank'] <=> $a['rank']) - ?: ($b['monthlyContribution'] <=> $a['monthlyContribution']) - ?: ($b['totalAmountDonated'] <=> $a['totalAmountDonated']) - )); + usort($list, static fn (array $a, array $b) => ( + ($b['star'] <=> $a['star']) + ?: ($b['rank'] <=> $a['rank']) + ?: ($b['monthlyContribution'] <=> $a['monthlyContribution']) + ?: ($b['totalAmountDonated'] <=> $a['totalAmountDonated']) + )); - $content[$status] = implode('', array_map(static function(array $member) use ($status) { + $content[$status] = implode('', array_map(static function (array $member) use ($status) { $href = htmlspecialchars($member['website'] ?? $member['profile']); - $src = $member['image'] ?? (strtr($member['profile'], ['https://opencollective.com/' => 'https://images.opencollective.com/']) . '/avatar/256.png'); + $src = $member['image'] ?? (strtr($member['profile'], ['https://opencollective.com/' => 'https://images.opencollective.com/']).'/avatar/256.png'); [$x, $y] = @getimagesize($src) ?: [0, 0]; $valid_image = ($x && $y); $src = $valid_image ? htmlspecialchars($src) : 'https://opencollective.com/static/images/default-guest-logo.svg'; $height = match ($status) { - 'sponsor' => 64, - 'backerPlus' => 42, - 'backer' => 32, - default => 24, - }; + 'sponsor' => 64, + 'backerPlus' => 42, + 'backer' => 32, + default => 24, + }; $margin = match ($status) { - 'sponsor' => 10, - 'backerPlus' => 6, - 'backer' => 5, - default => 3, - }; + 'sponsor' => 10, + 'backerPlus' => 6, + 'backer' => 5, + default => 3, + }; $width = $valid_image ? round($x * $height / $y) : $height; if (!str_contains($href, 'utm_source') && !preg_match('/^https?:\/\/(?:www\.)?(?:onlinekasyno-polis\.pl|zonaminecraft\.net|slotozilla\.com)(\/.*)?$/', $href)) { - $href .= (!str_contains($href, '?') ? '?' : '&') . 'utm_source=opencollective&utm_medium=github&utm_campaign=Carbon'; + $href .= (!str_contains($href, '?') ? '?' : '&').'utm_source=opencollective&utm_medium=github&utm_campaign=Carbon'; } $title = htmlspecialchars(($member['description'] ?? null) ?: $member['name']); $alt = htmlspecialchars($member['name']); - return "\n" . ' ' . - '' . $alt . '' . - ($member['star'] ? '' : '') . + return "\n".' '. + ''.$alt.''. + ($member['star'] ? '' : ''). ''; - }, $list)) . "\n"; - } + }, $list))."\n"; + } - return $content[$status]; + return $content[$status]; } diff --git a/tools/generate-changelog.php b/tools/generate-changelog.php index eac4922875ac78c6936a4d91ad6ca7b895dab54a..e9418708fb7b988241771da98ff20df381e28a59 100644 --- a/tools/generate-changelog.php +++ b/tools/generate-changelog.php @@ -1,5 +1,5 @@ start('Fetching releases from GitHub API...'); + $output = new ConsoleOutput(); + $progress_indicator = new ProgressIndicator($output); + $progress_indicator->start('Fetching releases from GitHub API...'); - $releases = []; - $page = 0; + $releases = []; + $page = 0; - do { - $page++; - $data = get_data("https://api.github.com/repos/briannesbitt/Carbon/releases?page=$page"); + do { + $page++; + $data = get_data("https://api.github.com/repos/briannesbitt/Carbon/releases?page=$page"); - foreach ($data as $release) { - $properties = [ - 'tag_name' => $release['tag_name'], - 'created_at' => $release['created_at'], + foreach ($data as $release) { + $properties = [ + 'tag_name' => $release['tag_name'], + 'created_at' => $release['created_at'], 'body' => format_release_notes($release['body']), ]; - if (isset($release['assets'][0]['asset_url'])) { - $properties['asset_url'] = $release['assets'][0]['asset_url']; - } + if (isset($release['assets'][0]['asset_url'])) { + $properties['asset_url'] = $release['assets'][0]['asset_url']; + } - $releases[] = $properties; - } - } while (count($data) > 0); + $releases[] = $properties; + } + } while (count($data) > 0); - $progress_indicator->finish('Fetched releases from GitHub API.'); + $progress_indicator->finish('Fetched releases from GitHub API.'); - return $releases; + return $releases; } function init_releases() { $releases = get_releases_from_api(); - file_put_contents(__DIR__ . '/../releases.json', json_encode($releases, JSON_PRETTY_PRINT)); + file_put_contents(__DIR__.'/../releases.json', json_encode($releases, JSON_PRETTY_PRINT)); return $releases; } function get_releases() { - $releases = init_releases(); + $releases = init_releases(); - // sort releases by version descending - usort($releases, static fn (array $a, array $b) => version_compare($b['tag_name'], $a['tag_name'])); + // sort releases by version descending + usort($releases, static fn (array $a, array $b) => version_compare($b['tag_name'], $a['tag_name'])); - // group by major version - $grouped_releases = []; + // group by major version + $grouped_releases = []; - foreach ($releases as $release) { - $version = preg_replace('/^v/', '', $release['tag_name']); - $major_version = explode('.', $version) [0]; - $grouped_releases[$major_version][] = $release; - } + foreach ($releases as $release) { + $version = preg_replace('/^v/', '', $release['tag_name']); + $major_version = explode('.', $version) [0]; + $grouped_releases[$major_version][] = $release; + } - return $grouped_releases; + return $grouped_releases; } function write_markdown() { - $destination_file = __DIR__ . '/../docs/develop/changelog.md'; - - $releases = get_releases(); - $releases_count = array_sum(array_map('count', $releases)); - $output = new ConsoleOutput(); - $progress_bar = new ProgressBar($output, $releases_count - 1); - $progress_bar->setFormat('debug'); - $progress_bar->start(); - $markdown = "\n\n"; - $markdown .= "# Changelog\n"; - - foreach ($releases as $major_version => $release_group) { - $markdown .= "\n## Version {$major_version}.x\n\n"; - - // only get commits for version 3.0.0 and above - if (version_compare($major_version, '3', '<')) { - $markdown .= "::: tip Info\n"; - $markdown .= "Only release dates are listed here.\n"; - $markdown .= ":::\n\n"; - - // display a list of releases without commits - foreach ($release_group as $release) { - $tag = $release['tag_name']; - $markdown .= "- $tag (" . Carbon::parse($release['created_at'])->format('j F Y') . ")\n"; - $progress_bar->advance(); - } - continue; - } - - foreach ($release_group as $release) { - $tag = $release['tag_name']; - - if (empty($previous_tag)) { - $previous_tag = $tag; - continue; - } - - $end = $previous_tag; + $destination_file = __DIR__.'/../docs/develop/changelog.md'; + + $releases = get_releases(); + $releases_count = array_sum(array_map('count', $releases)); + $output = new ConsoleOutput(); + $progress_bar = new ProgressBar($output, $releases_count - 1); + $progress_bar->setFormat('debug'); + $progress_bar->start(); + $markdown = "\n\n"; + $markdown .= "# Changelog\n"; + + foreach ($releases as $major_version => $release_group) { + $markdown .= "\n## Version {$major_version}.x\n\n"; + + // only get commits for version 3.0.0 and above + if (version_compare($major_version, '3', '<')) { + $markdown .= "::: tip Info\n"; + $markdown .= "Only release dates are listed here.\n"; + $markdown .= ":::\n\n"; + + // display a list of releases without commits + foreach ($release_group as $release) { + $tag = $release['tag_name']; + $markdown .= "- $tag (".Carbon::parse($release['created_at'])->format('j F Y').")\n"; + $progress_bar->advance(); + } + continue; + } + + foreach ($release_group as $release) { + $tag = $release['tag_name']; + + if (empty($previous_tag)) { + $previous_tag = $tag; + continue; + } + + $end = $previous_tag; $date = Carbon::parse($release['created_at'])->format('j F Y'); - $markdown .= "#### $end ($date)\n{$release['body']}\n\n"; - $progress_bar->advance(); - $previous_tag = $tag; - } - } - $progress_bar->finish(); - - file_put_contents($destination_file, $markdown); + $markdown .= "#### $end ($date)\n{$release['body']}\n\n"; + $progress_bar->advance(); + $previous_tag = $tag; + } + } + $progress_bar->finish(); + + file_put_contents($destination_file, $markdown); } try { - write_markdown(); + write_markdown(); } catch (Exception $exception) { - echo 'Error: ' . $exception->getMessage() . "\n"; - exit(1); + echo 'Error: '.$exception->getMessage()."\n"; + exit(1); } diff --git a/tools/generate-translations.php b/tools/generate-translations.php index f8572b3e86ff17e4ea982393cc848ceee6337b32..592679848e44695ac5fc7e82f241424c8a63df17 100644 --- a/tools/generate-translations.php +++ b/tools/generate-translations.php @@ -4,137 +4,137 @@ use Carbon\Carbon; use Carbon\Language; use Carbon\Translator; -require __DIR__ . '/../vendor/autoload.php'; -$destination_base = __DIR__ . '/../docs/public/data'; +require __DIR__.'/../vendor/autoload.php'; +$destination_base = __DIR__.'/../docs/public/data'; // Create translations directory if not exists if (!is_dir("{$destination_base}/translations")) { - mkdir("{$destination_base}/translations", 0777, true); + mkdir("{$destination_base}/translations", 0777, true); } $translations = [ - ['CarbonInterval::years(2)', '->forHumans()'], - ['CarbonInterval::years(2)', '->forHumans(["short" => true])'], - ['CarbonInterval::year()', '->forHumans()'], - ['CarbonInterval::year()', '->forHumans(["aUnit" => true])'], - ['CarbonInterval::months(2)', '->forHumans()'], - ['CarbonInterval::months(2)', '->forHumans(["short" => true])'], - ['CarbonInterval::month()', '->forHumans()'], - ['CarbonInterval::month()', '->forHumans(["aUnit" => true])'], - ['CarbonInterval::weeks(2)', '->forHumans()'], - ['CarbonInterval::weeks(2)', '->forHumans(["short" => true])'], - ['CarbonInterval::week()', '->forHumans()'], - ['CarbonInterval::week()', '->forHumans(["aUnit" => true])'], - ['CarbonInterval::days(2)', '->forHumans()'], - ['CarbonInterval::days(2)', '->forHumans(["short" => true])'], - ['CarbonInterval::day()', '->forHumans()'], - ['CarbonInterval::day()', '->forHumans(["aUnit" => true])'], - ['CarbonInterval::hours(2)', '->forHumans()'], - ['CarbonInterval::hours(2)', '->forHumans(["short" => true])'], - ['CarbonInterval::hour()', '->forHumans()'], - ['CarbonInterval::hour()', '->forHumans(["aUnit" => true])'], - ['CarbonInterval::minutes(2)', '->forHumans()'], - ['CarbonInterval::minutes(2)', '->forHumans(["short" => true])'], - ['CarbonInterval::minute()', '->forHumans()'], - ['CarbonInterval::minute()', '->forHumans(["aUnit" => true])'], - ['CarbonInterval::seconds(2)', '->forHumans()'], - ['CarbonInterval::seconds(2)', '->forHumans(["short" => true])'], - ['CarbonInterval::second()', '->forHumans()'], - ['CarbonInterval::second()', '->forHumans(["aUnit" => true])'], - ['Carbon::parse("monday")', '->dayName'], - ['Carbon::parse("monday")', '->shortDayName'], - ['Carbon::parse("monday")', '->minDayName'], - ['Carbon::parse("tuesday")', '->dayName'], - ['Carbon::parse("tuesday")', '->shortDayName'], - ['Carbon::parse("tuesday")', '->minDayName'], - ['Carbon::parse("wednesday")', '->dayName'], - ['Carbon::parse("wednesday")', '->shortDayName'], - ['Carbon::parse("wednesday")', '->minDayName'], - ['Carbon::parse("thursday")', '->dayName'], - ['Carbon::parse("thursday")', '->shortDayName'], - ['Carbon::parse("thursday")', '->minDayName'], - ['Carbon::parse("friday")', '->dayName'], - ['Carbon::parse("friday")', '->shortDayName'], - ['Carbon::parse("friday")', '->minDayName'], - ['Carbon::parse("saturday")', '->dayName'], - ['Carbon::parse("saturday")', '->shortDayName'], - ['Carbon::parse("saturday")', '->minDayName'], - ['Carbon::parse("sunday")', '->dayName'], - ['Carbon::parse("sunday")', '->shortDayName'], - ['Carbon::parse("sunday")', '->minDayName'], - ['Carbon::parse("january 2023")', '->monthName'], - ['Carbon::parse("january 2023")', '->shortMonthName'], - ['Carbon::parse("february 2023")', '->monthName'], - ['Carbon::parse("february 2023")', '->shortMonthName'], - ['Carbon::parse("march 2023")', '->monthName'], - ['Carbon::parse("march 2023")', '->shortMonthName'], - ['Carbon::parse("april 2023")', '->monthName'], - ['Carbon::parse("april 2023")', '->shortMonthName'], - ['Carbon::parse("may 2023")', '->monthName'], - ['Carbon::parse("may 2023")', '->shortMonthName'], - ['Carbon::parse("june 2023")', '->monthName'], - ['Carbon::parse("june 2023")', '->shortMonthName'], - ['Carbon::parse("july 2023")', '->monthName'], - ['Carbon::parse("july 2023")', '->shortMonthName'], - ['Carbon::parse("august 2023")', '->monthName'], - ['Carbon::parse("august 2023")', '->shortMonthName'], - ['Carbon::parse("september 2023")', '->monthName'], - ['Carbon::parse("september 2023")', '->shortMonthName'], - ['Carbon::parse("october 2023")', '->monthName'], - ['Carbon::parse("october 2023")', '->shortMonthName'], - ['Carbon::parse("november 2023")', '->monthName'], - ['Carbon::parse("november 2023")', '->shortMonthName'], - ['Carbon::parse("december 2023")', '->monthName'], - ['Carbon::parse("december 2023")', '->shortMonthName'], - ['Carbon::now()->subHours(2)', '->diffForHumans()'], - ['Carbon::now()->addHours(2)->addMinute()', '->diffForHumans(["part" => 1])'], - ['($d = Carbon::now())->copy()->subHours(2)', '->diffForHumans($d)'], - ['($d = Carbon::now())->copy()->addHours(2)->addMinute()', '->diffForHumans($d)'], + ['CarbonInterval::years(2)', '->forHumans()'], + ['CarbonInterval::years(2)', '->forHumans(["short" => true])'], + ['CarbonInterval::year()', '->forHumans()'], + ['CarbonInterval::year()', '->forHumans(["aUnit" => true])'], + ['CarbonInterval::months(2)', '->forHumans()'], + ['CarbonInterval::months(2)', '->forHumans(["short" => true])'], + ['CarbonInterval::month()', '->forHumans()'], + ['CarbonInterval::month()', '->forHumans(["aUnit" => true])'], + ['CarbonInterval::weeks(2)', '->forHumans()'], + ['CarbonInterval::weeks(2)', '->forHumans(["short" => true])'], + ['CarbonInterval::week()', '->forHumans()'], + ['CarbonInterval::week()', '->forHumans(["aUnit" => true])'], + ['CarbonInterval::days(2)', '->forHumans()'], + ['CarbonInterval::days(2)', '->forHumans(["short" => true])'], + ['CarbonInterval::day()', '->forHumans()'], + ['CarbonInterval::day()', '->forHumans(["aUnit" => true])'], + ['CarbonInterval::hours(2)', '->forHumans()'], + ['CarbonInterval::hours(2)', '->forHumans(["short" => true])'], + ['CarbonInterval::hour()', '->forHumans()'], + ['CarbonInterval::hour()', '->forHumans(["aUnit" => true])'], + ['CarbonInterval::minutes(2)', '->forHumans()'], + ['CarbonInterval::minutes(2)', '->forHumans(["short" => true])'], + ['CarbonInterval::minute()', '->forHumans()'], + ['CarbonInterval::minute()', '->forHumans(["aUnit" => true])'], + ['CarbonInterval::seconds(2)', '->forHumans()'], + ['CarbonInterval::seconds(2)', '->forHumans(["short" => true])'], + ['CarbonInterval::second()', '->forHumans()'], + ['CarbonInterval::second()', '->forHumans(["aUnit" => true])'], + ['Carbon::parse("monday")', '->dayName'], + ['Carbon::parse("monday")', '->shortDayName'], + ['Carbon::parse("monday")', '->minDayName'], + ['Carbon::parse("tuesday")', '->dayName'], + ['Carbon::parse("tuesday")', '->shortDayName'], + ['Carbon::parse("tuesday")', '->minDayName'], + ['Carbon::parse("wednesday")', '->dayName'], + ['Carbon::parse("wednesday")', '->shortDayName'], + ['Carbon::parse("wednesday")', '->minDayName'], + ['Carbon::parse("thursday")', '->dayName'], + ['Carbon::parse("thursday")', '->shortDayName'], + ['Carbon::parse("thursday")', '->minDayName'], + ['Carbon::parse("friday")', '->dayName'], + ['Carbon::parse("friday")', '->shortDayName'], + ['Carbon::parse("friday")', '->minDayName'], + ['Carbon::parse("saturday")', '->dayName'], + ['Carbon::parse("saturday")', '->shortDayName'], + ['Carbon::parse("saturday")', '->minDayName'], + ['Carbon::parse("sunday")', '->dayName'], + ['Carbon::parse("sunday")', '->shortDayName'], + ['Carbon::parse("sunday")', '->minDayName'], + ['Carbon::parse("january 2023")', '->monthName'], + ['Carbon::parse("january 2023")', '->shortMonthName'], + ['Carbon::parse("february 2023")', '->monthName'], + ['Carbon::parse("february 2023")', '->shortMonthName'], + ['Carbon::parse("march 2023")', '->monthName'], + ['Carbon::parse("march 2023")', '->shortMonthName'], + ['Carbon::parse("april 2023")', '->monthName'], + ['Carbon::parse("april 2023")', '->shortMonthName'], + ['Carbon::parse("may 2023")', '->monthName'], + ['Carbon::parse("may 2023")', '->shortMonthName'], + ['Carbon::parse("june 2023")', '->monthName'], + ['Carbon::parse("june 2023")', '->shortMonthName'], + ['Carbon::parse("july 2023")', '->monthName'], + ['Carbon::parse("july 2023")', '->shortMonthName'], + ['Carbon::parse("august 2023")', '->monthName'], + ['Carbon::parse("august 2023")', '->shortMonthName'], + ['Carbon::parse("september 2023")', '->monthName'], + ['Carbon::parse("september 2023")', '->shortMonthName'], + ['Carbon::parse("october 2023")', '->monthName'], + ['Carbon::parse("october 2023")', '->shortMonthName'], + ['Carbon::parse("november 2023")', '->monthName'], + ['Carbon::parse("november 2023")', '->shortMonthName'], + ['Carbon::parse("december 2023")', '->monthName'], + ['Carbon::parse("december 2023")', '->shortMonthName'], + ['Carbon::now()->subHours(2)', '->diffForHumans()'], + ['Carbon::now()->addHours(2)->addMinute()', '->diffForHumans(["part" => 1])'], + ['($d = Carbon::now())->copy()->subHours(2)', '->diffForHumans($d)'], + ['($d = Carbon::now())->copy()->addHours(2)->addMinute()', '->diffForHumans($d)'], ]; function get_languages(): array { - return array_map( - static function (string $code): array { - $lang = new Language($code); + return array_map( + static function (string $code): array { + $lang = new Language($code); - return array_merge($lang->getNames(), [ + return array_merge($lang->getNames(), [ 'id' => $lang->getId(), 'code' => $lang->getCode(), 'region' => $lang->getRegion(), 'regionName' => $lang->getRegionName(), 'variant' => $lang->getVariantName(), ]); - }, - Carbon::getAvailableLocales() - ); + }, + Carbon::getAvailableLocales() + ); } function get_translations() { - global $translations, $destination_base; + global $translations, $destination_base; - $languages = get_languages(); + $languages = get_languages(); - foreach ($languages as $language) { - $locale = $language['id']; - $output = []; + foreach ($languages as $language) { + $locale = $language['id']; + $output = []; - foreach ($translations as [$start, $end]) { - $output[] = [ - 'code' => "$start$end", - 'result' => eval("use Carbon\Carbon; use Carbon\CarbonInterval; return {$start}->locale('{$locale}'){$end};"), + foreach ($translations as [$start, $end]) { + $output[] = [ + 'code' => "$start$end", + 'result' => eval("use Carbon\Carbon; use Carbon\CarbonInterval; return {$start}->locale('{$locale}'){$end};"), ]; - } + } - file_put_contents($destination_base . "/translations/{$locale}.json", json_encode($output, JSON_UNESCAPED_SLASHES)); - } + file_put_contents($destination_base."/translations/{$locale}.json", json_encode($output, JSON_UNESCAPED_SLASHES)); + } } file_put_contents("{$destination_base}/languages.json", json_encode(get_languages(), JSON_UNESCAPED_SLASHES)); get_translations(); -$authors = array_keys(array_reduce(glob(Translator::get()->getDirectories()[0] . '/*.php'), static function ($authors, $file) { +$authors = array_keys(array_reduce(glob(Translator::get()->getDirectories()[0].'/*.php'), static function ($authors, $file) { if (preg_match('/\* Authors:([\s\S]+)\*\//U', file_get_contents($file), $match)) { foreach (explode('* -', $match[1]) as $line) { $line = trim($line); @@ -149,7 +149,7 @@ $authors = array_keys(array_reduce(glob(Translator::get()->getDirectories()[0] . }, [])); sort($authors); -file_put_contents(__DIR__ . '/../docs/develop/translations/translators.md', "--- +file_put_contents(__DIR__.'/../docs/develop/translations/translators.md', '--- outline: false aside: false prev: false @@ -159,7 +159,7 @@ next: false Thanks to people helping us to translate Carbon in so many languages. -- " . implode("\n- ", $authors) . " +- '.implode("\n- ", $authors).' Is someone missing? [Please tell us](https://github.com/briannesbitt/Carbon/issues/new). -"); +'); diff --git a/tools/methods.php b/tools/methods.php index de2cc27a926a5363b3066387ea921fdd38b9f5fe..ec7a2f914b6e8f5aa26e0ef2059fc82828582999 100644 --- a/tools/methods.php +++ b/tools/methods.php @@ -269,7 +269,7 @@ function methods(bool $excludeNatives = false, bool $excludeMixins = true): Gene method_exists(CarbonImmutable::class, $method) ? (new ReflectionMethod(CarbonImmutable::class, $method))->getDocComment() : null - ) + ) ) ?: null; $docReturn = preg_match('/@return (\S+)/', $docComment ?? '', $returnMatch)