Skip to content

Commit

Permalink
Merge pull request #2450 from lucasmichot/feat/imports
Browse files Browse the repository at this point in the history
Avoid FQCN and prefer imports
  • Loading branch information
kylekatarnls authored Sep 13, 2021
2 parents 6903cba + 58ed1c3 commit 005646e
Show file tree
Hide file tree
Showing 29 changed files with 147 additions and 65 deletions.
4 changes: 3 additions & 1 deletion bin/carbon
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php

use Carbon\Cli\Invoker;

$dir = __DIR__.'/..';

if (!file_exists($dir.'/autoload.php')) {
Expand All @@ -18,4 +20,4 @@ if (!file_exists($dir.'/autoload.php')) {

require $dir.'/autoload.php';

exit((new \Carbon\Cli\Invoker())(...$argv) ? 0 : 1);
exit((new Invoker())(...$argv) ? 0 : 1);
14 changes: 9 additions & 5 deletions phpdoc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Carbon\CarbonInterface;

$tags = [
'property',
'property-read',
Expand Down Expand Up @@ -72,7 +76,7 @@ function dumpValue($value)
return 'null';
}
if ($value === \Carbon\CarbonInterface::TRANSLATE_ALL) {
if ($value === CarbonInterface::TRANSLATE_ALL) {
return 'CarbonInterface::TRANSLATE_ALL';
}
Expand Down Expand Up @@ -199,7 +203,7 @@ function dumpParameter($method, ReflectionParameter $parameter)
$unitName = unitName($unit);
$method = 'isSame'.ucFirst($unit);

if (!method_exists(\Carbon\Carbon::class, $method)) {
if (!method_exists(Carbon::class, $method)) {
$autoDocLines[] = [
'@method',
'bool',
Expand Down Expand Up @@ -524,17 +528,17 @@ function compileDoc($autoDocLines, $file)
$staticMethods = [];
$staticImmutableMethods = [];
$methods = '';
$carbonMethods = get_class_methods(\Carbon\Carbon::class);
$carbonMethods = get_class_methods(Carbon::class);
sort($carbonMethods);
foreach ($carbonMethods as $method) {
if (!method_exists(\Carbon\CarbonImmutable::class, $method) ||
if (!method_exists(CarbonImmutable::class, $method) ||
method_exists(DateTimeInterface::class, $method) ||
$method === 'createFromInterface'
) {
continue;
}

$function = new ReflectionMethod(\Carbon\Carbon::class, $method);
$function = new ReflectionMethod(Carbon::class, $method);
$static = $function->isStatic() ? ' static' : '';
$parameters = implode(', ', array_map(function (ReflectionParameter $parameter) use ($method) {
return dumpParameter($method, $parameter);
Expand Down
9 changes: 5 additions & 4 deletions src/Carbon/CarbonInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use JsonSerializable;
use ReflectionException;
use ReturnTypeWillChange;
use Symfony\Component\Translation\TranslatorInterface;
use Throwable;

/**
Expand Down Expand Up @@ -3792,7 +3793,7 @@ public function setISODate($year, $week, $day = 1);
*
* @return $this
*/
public function setLocalTranslator(\Symfony\Component\Translation\TranslatorInterface $translator);
public function setLocalTranslator(TranslatorInterface $translator);

/**
* Set the current translator locale and indicate if the source locale file exists.
Expand Down Expand Up @@ -3917,7 +3918,7 @@ public static function setToStringFormat($format);
*
* @return void
*/
public static function setTranslator(\Symfony\Component\Translation\TranslatorInterface $translator);
public static function setTranslator(TranslatorInterface $translator);

/**
* Set specified unit to new given value.
Expand Down Expand Up @@ -4780,7 +4781,7 @@ public static function tomorrow($tz = null);
*
* @return string
*/
public function translate(string $key, array $parameters = [], $number = null, ?\Symfony\Component\Translation\TranslatorInterface $translator = null, bool $altNumbers = false): string;
public function translate(string $key, array $parameters = [], $number = null, ?TranslatorInterface $translator = null, bool $altNumbers = false): string;

/**
* Returns the alternative number for a given integer if available in the current locale.
Expand Down Expand Up @@ -4829,7 +4830,7 @@ public function translateTimeStringTo($timeString, $to = null);
*
* @return string
*/
public static function translateWith(\Symfony\Component\Translation\TranslatorInterface $translator, string $key, array $parameters = [], $number = null): string;
public static function translateWith(TranslatorInterface $translator, string $key, array $parameters = [], $number = null): string;

/**
* Format as ->format() do (using date replacements patterns from https://php.net/manual/en/function.date.php)
Expand Down
3 changes: 2 additions & 1 deletion src/Carbon/CarbonTimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Carbon\Exceptions\InvalidTimeZoneException;
use DateTimeInterface;
use DateTimeZone;
use Throwable;

class CarbonTimeZone extends DateTimeZone
{
Expand Down Expand Up @@ -198,7 +199,7 @@ public function toRegionName(DateTimeInterface $date = null, $isDst = 1)
// @codeCoverageIgnoreStart
try {
$offset = @$this->getOffset($date) ?: 0;
} catch (\Throwable $e) {
} catch (Throwable $e) {
$offset = 0;
}
// @codeCoverageIgnoreEnd
Expand Down
8 changes: 6 additions & 2 deletions src/Carbon/Lang/be.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
* file that was distributed with this source code.
*/
// @codeCoverageIgnoreStart

use Carbon\CarbonInterface;
use Symfony\Component\Translation\PluralizationRules;

if (class_exists('Symfony\\Component\\Translation\\PluralizationRules')) {
\Symfony\Component\Translation\PluralizationRules::set(function ($number) {
PluralizationRules::set(function ($number) {
return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
}, 'be');
}
Expand Down Expand Up @@ -113,7 +117,7 @@
'nextDay' => '[Заўтра ў] LT',
'nextWeek' => '[У] dddd [ў] LT',
'lastDay' => '[Учора ў] LT',
'lastWeek' => function (\Carbon\CarbonInterface $current) {
'lastWeek' => function (CarbonInterface $current) {
switch ($current->dayOfWeek) {
case 1:
case 2:
Expand Down
5 changes: 4 additions & 1 deletion src/Carbon/Lang/bg.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* - JD Isaacks
* - Glavić
*/

use Carbon\CarbonInterface;

return [
'year' => ':count година|:count години',
'a_year' => 'година|:count години',
Expand Down Expand Up @@ -63,7 +66,7 @@
'nextDay' => '[Утре в] LT',
'nextWeek' => 'dddd [в] LT',
'lastDay' => '[Вчера в] LT',
'lastWeek' => function (\Carbon\CarbonInterface $current) {
'lastWeek' => function (CarbonInterface $current) {
switch ($current->dayOfWeek) {
case 0:
case 3:
Expand Down
7 changes: 5 additions & 2 deletions src/Carbon/Lang/bs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
* - Serhan Apaydın
* - JD Isaacks
*/

use Carbon\CarbonInterface;

return [
'year' => ':count godina|:count godine|:count godina',
'y' => ':count godina|:count godine|:count godina',
Expand Down Expand Up @@ -55,7 +58,7 @@
'calendar' => [
'sameDay' => '[danas u] LT',
'nextDay' => '[sutra u] LT',
'nextWeek' => function (\Carbon\CarbonInterface $current) {
'nextWeek' => function (CarbonInterface $current) {
switch ($current->dayOfWeek) {
case 0:
return '[u] [nedjelju] [u] LT';
Expand All @@ -68,7 +71,7 @@
}
},
'lastDay' => '[jučer u] LT',
'lastWeek' => function (\Carbon\CarbonInterface $current) {
'lastWeek' => function (CarbonInterface $current) {
switch ($current->dayOfWeek) {
case 0:
case 3:
Expand Down
13 changes: 8 additions & 5 deletions src/Carbon/Lang/ca.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
* - Xavi
* - qcardona
*/

use Carbon\CarbonInterface;

return [
'year' => ':count any|:count anys',
'a_year' => 'un any|:count anys',
Expand Down Expand Up @@ -69,19 +72,19 @@
'LLLL' => 'dddd D MMMM [de] YYYY [a les] H:mm',
],
'calendar' => [
'sameDay' => function (\Carbon\CarbonInterface $current) {
'sameDay' => function (CarbonInterface $current) {
return '[avui a '.($current->hour !== 1 ? 'les' : 'la').'] LT';
},
'nextDay' => function (\Carbon\CarbonInterface $current) {
'nextDay' => function (CarbonInterface $current) {
return '[demà a '.($current->hour !== 1 ? 'les' : 'la').'] LT';
},
'nextWeek' => function (\Carbon\CarbonInterface $current) {
'nextWeek' => function (CarbonInterface $current) {
return 'dddd [a '.($current->hour !== 1 ? 'les' : 'la').'] LT';
},
'lastDay' => function (\Carbon\CarbonInterface $current) {
'lastDay' => function (CarbonInterface $current) {
return '[ahir a '.($current->hour !== 1 ? 'les' : 'la').'] LT';
},
'lastWeek' => function (\Carbon\CarbonInterface $current) {
'lastWeek' => function (CarbonInterface $current) {
return '[el] dddd [passat a '.($current->hour !== 1 ? 'les' : 'la').'] LT';
},
'sameElse' => 'L',
Expand Down
5 changes: 4 additions & 1 deletion src/Carbon/Lang/el.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* - yiannisdesp
* - Ilias Kasmeridis (iliaskasm)
*/

use Carbon\CarbonInterface;

return [
'year' => ':count χρόνος|:count χρόνια',
'a_year' => 'ένας χρόνος|:count χρόνια',
Expand Down Expand Up @@ -65,7 +68,7 @@
'nextDay' => '[Αύριο {}] LT',
'nextWeek' => 'dddd [{}] LT',
'lastDay' => '[Χθες {}] LT',
'lastWeek' => function (\Carbon\CarbonInterface $current) {
'lastWeek' => function (CarbonInterface $current) {
switch ($current->dayOfWeek) {
case 6:
return '[το προηγούμενο] dddd [{}] LT';
Expand Down
13 changes: 8 additions & 5 deletions src/Carbon/Lang/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
* - Daniel Commesse Liévanos (danielcommesse)
* - Pete Scopes (pdscopes)
*/

use Carbon\CarbonInterface;

return [
'year' => ':count año|:count años',
'a_year' => 'un año|:count años',
Expand Down Expand Up @@ -77,19 +80,19 @@
'LLLL' => 'dddd, D [de] MMMM [de] YYYY H:mm',
],
'calendar' => [
'sameDay' => function (\Carbon\CarbonInterface $current) {
'sameDay' => function (CarbonInterface $current) {
return '[hoy a la'.($current->hour !== 1 ? 's' : '').'] LT';
},
'nextDay' => function (\Carbon\CarbonInterface $current) {
'nextDay' => function (CarbonInterface $current) {
return '[mañana a la'.($current->hour !== 1 ? 's' : '').'] LT';
},
'nextWeek' => function (\Carbon\CarbonInterface $current) {
'nextWeek' => function (CarbonInterface $current) {
return 'dddd [a la'.($current->hour !== 1 ? 's' : '').'] LT';
},
'lastDay' => function (\Carbon\CarbonInterface $current) {
'lastDay' => function (CarbonInterface $current) {
return '[ayer a la'.($current->hour !== 1 ? 's' : '').'] LT';
},
'lastWeek' => function (\Carbon\CarbonInterface $current) {
'lastWeek' => function (CarbonInterface $current) {
return '[el] dddd [pasado a la'.($current->hour !== 1 ? 's' : '').'] LT';
},
'sameElse' => 'L',
Expand Down
13 changes: 8 additions & 5 deletions src/Carbon/Lang/gl.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* - Diego Vilariño
* - Sebastian Thierer
*/

use Carbon\CarbonInterface;

return [
'year' => ':count ano|:count anos',
'a_year' => 'un ano|:count anos',
Expand Down Expand Up @@ -65,19 +68,19 @@
'LLLL' => 'dddd, D [de] MMMM [de] YYYY H:mm',
],
'calendar' => [
'sameDay' => function (\Carbon\CarbonInterface $current) {
'sameDay' => function (CarbonInterface $current) {
return '[hoxe '.($current->hour !== 1 ? 'ás' : 'á').'] LT';
},
'nextDay' => function (\Carbon\CarbonInterface $current) {
'nextDay' => function (CarbonInterface $current) {
return '[mañá '.($current->hour !== 1 ? 'ás' : 'á').'] LT';
},
'nextWeek' => function (\Carbon\CarbonInterface $current) {
'nextWeek' => function (CarbonInterface $current) {
return 'dddd ['.($current->hour !== 1 ? 'ás' : 'á').'] LT';
},
'lastDay' => function (\Carbon\CarbonInterface $current) {
'lastDay' => function (CarbonInterface $current) {
return '[onte '.($current->hour !== 1 ? 'á' : 'a').'] LT';
},
'lastWeek' => function (\Carbon\CarbonInterface $current) {
'lastWeek' => function (CarbonInterface $current) {
return '[o] dddd [pasado '.($current->hour !== 1 ? 'ás' : 'á').'] LT';
},
'sameElse' => 'L',
Expand Down
7 changes: 5 additions & 2 deletions src/Carbon/Lang/hr.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
* - Stjepan Majdak
* - Vanja Retkovac (vr00)
*/

use Carbon\CarbonInterface;

return [
'year' => ':count godinu|:count godine|:count godina',
'y' => ':count god.|:count god.|:count god.',
Expand Down Expand Up @@ -67,7 +70,7 @@
'calendar' => [
'sameDay' => '[danas u] LT',
'nextDay' => '[sutra u] LT',
'nextWeek' => function (\Carbon\CarbonInterface $date) {
'nextWeek' => function (CarbonInterface $date) {
switch ($date->dayOfWeek) {
case 0:
return '[u] [nedjelju] [u] LT';
Expand All @@ -80,7 +83,7 @@
}
},
'lastDay' => '[jučer u] LT',
'lastWeek' => function (\Carbon\CarbonInterface $date) {
'lastWeek' => function (CarbonInterface $date) {
switch ($date->dayOfWeek) {
case 0:
case 3:
Expand Down
7 changes: 5 additions & 2 deletions src/Carbon/Lang/hu.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* - Brett Johnson
* - balping
*/

use Carbon\CarbonInterface;

$huWeekEndings = ['vasárnap', 'hétfőn', 'kedden', 'szerdán', 'csütörtökön', 'pénteken', 'szombaton'];

return [
Expand Down Expand Up @@ -99,11 +102,11 @@
'calendar' => [
'sameDay' => '[ma] LT[-kor]',
'nextDay' => '[holnap] LT[-kor]',
'nextWeek' => function (\Carbon\CarbonInterface $date) use ($huWeekEndings) {
'nextWeek' => function (CarbonInterface $date) use ($huWeekEndings) {
return '['.$huWeekEndings[$date->dayOfWeek].'] LT[-kor]';
},
'lastDay' => '[tegnap] LT[-kor]',
'lastWeek' => function (\Carbon\CarbonInterface $date) use ($huWeekEndings) {
'lastWeek' => function (CarbonInterface $date) use ($huWeekEndings) {
return '[múlt '.$huWeekEndings[$date->dayOfWeek].'] LT[-kor]';
},
'sameElse' => 'L',
Expand Down
5 changes: 4 additions & 1 deletion src/Carbon/Lang/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* - Davide Casiraghi (davide-casiraghi)
* - Pete Scopes (pdscopes)
*/

use Carbon\CarbonInterface;

return [
'year' => ':count anno|:count anni',
'a_year' => 'un anno|:count anni',
Expand Down Expand Up @@ -81,7 +84,7 @@
'nextDay' => '[Domani alle] LT',
'nextWeek' => 'dddd [alle] LT',
'lastDay' => '[Ieri alle] LT',
'lastWeek' => function (\Carbon\CarbonInterface $date) {
'lastWeek' => function (CarbonInterface $date) {
switch ($date->dayOfWeek) {
case 0:
return '[la scorsa] dddd [alle] LT';
Expand Down
Loading

0 comments on commit 005646e

Please sign in to comment.