chore(*.php): use pint for php formatting

This commit is contained in:
Cory Dransfeldt 2025-06-14 16:55:03 -07:00
parent 029caaaa9e
commit cf1ee4c97f
No known key found for this signature in database
40 changed files with 2261 additions and 1900 deletions

View file

@ -1,82 +1,94 @@
<?php
use Kaoken\MarkdownIt\MarkdownIt;
use Kaoken\MarkdownIt\Plugins\MarkdownItFootnote;
use Kaoken\MarkdownIt\MarkdownIt;
use Kaoken\MarkdownIt\Plugins\MarkdownItFootnote;
if (!function_exists('truncateText')) {
function truncateText($text, $limit = 50, $ellipsis = "...")
if (! function_exists('truncateText')) {
function truncateText($text, $limit = 50, $ellipsis = '...')
{
if (mb_strwidth($text, "UTF-8") <= $limit) return $text;
$truncated = mb_substr($text, 0, $limit, "UTF-8");
$lastSpace = mb_strrpos($truncated, " ", 0, "UTF-8");
if ($lastSpace !== false) $truncated = mb_substr($truncated, 0, $lastSpace, "UTF-8");
return $truncated . $ellipsis;
}
}
if (!function_exists('parseMarkdown')) {
function parseMarkdown($markdown)
{
if (empty($markdown)) return '';
$md = new MarkdownIt([
"html" => true,
"linkify" => true,
]);
$md->plugin(new MarkdownItFootnote());
return $md->render($markdown);
}
}
if (!function_exists('parseCountryField')) {
function parseCountryField($countryField)
{
if (empty($countryField)) return null;
$delimiters = [',', '/', '&', ' and '];
$countries = [$countryField];
foreach ($delimiters as $delimiter) {
$tempCountries = [];
foreach ($countries as $country) {
$tempCountries = array_merge($tempCountries, explode($delimiter, $country));
if (mb_strwidth($text, 'UTF-8') <= $limit) {
return $text;
}
$countries = $tempCountries;
}
$truncated = mb_substr($text, 0, $limit, 'UTF-8');
$lastSpace = mb_strrpos($truncated, ' ', 0, 'UTF-8');
$countries = array_map('trim', $countries);
$countries = array_map('getCountryName', $countries);
$countries = array_filter($countries);
if ($lastSpace !== false) {
$truncated = mb_substr($truncated, 0, $lastSpace, 'UTF-8');
}
return implode(', ', array_unique($countries));
return $truncated.$ellipsis;
}
}
}
if (!function_exists('getCountryName')) {
if (! function_exists('parseMarkdown')) {
function parseMarkdown($markdown)
{
if (empty($markdown)) {
return '';
}
$md = new MarkdownIt([
'html' => true,
'linkify' => true,
]);
$md->plugin(new MarkdownItFootnote());
return $md->render($markdown);
}
}
if (! function_exists('parseCountryField')) {
function parseCountryField($countryField)
{
if (empty($countryField)) {
return null;
}
$delimiters = [',', '/', '&', ' and '];
$countries = [$countryField];
foreach ($delimiters as $delimiter) {
$tempCountries = [];
foreach ($countries as $country) {
$tempCountries = array_merge($tempCountries, explode($delimiter, $country));
}
$countries = $tempCountries;
}
$countries = array_map('trim', $countries);
$countries = array_map('getCountryName', $countries);
$countries = array_filter($countries);
return implode(', ', array_unique($countries));
}
}
if (! function_exists('getCountryName')) {
function getCountryName($countryName)
{
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
$countries = $isoCodes->getCountries();
$country = $countries->getByAlpha2($countryName);
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
$countries = $isoCodes->getCountries();
$country = $countries->getByAlpha2($countryName);
if ($country) return $country->getName();
if ($country) {
return $country->getName();
}
return ucfirst(strtolower($countryName));
return ucfirst(strtolower($countryName));
}
}
}
if (!function_exists('pluralize')) {
if (! function_exists('pluralize')) {
function pluralize($count, $string, $trailing = '')
{
if ((int)$count === 1) return $string;
if ((int) $count === 1) {
return $string;
}
return $string . 's' . ($trailing ? $trailing : '');
return $string.'s'.($trailing ? $trailing : '');
}
}
}