Skip to content

Commit

Permalink
Promote some properties to the constructor.
Browse files Browse the repository at this point in the history
Signed-off-by: Sacha Telgenhof <me@sachatelgenhof.com>
  • Loading branch information
stelgenhof committed Dec 5, 2023
1 parent 151a477 commit 3499515
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 29 deletions.
6 changes: 1 addition & 5 deletions src/Yasumi/Filters/BetweenFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class BetweenFilter extends AbstractFilter
/** end date of the time frame to check against */
private string $endDate;

/** indicates whether the start and end dates should be included in the comparison */
private bool $equal;

/**
* Construct the Between FilterIterator Object.
*
Expand All @@ -51,10 +48,9 @@ public function __construct(
\Iterator $iterator,
\DateTimeInterface $startDate,
\DateTimeInterface $endDate,
bool $equal = true
private bool $equal = true
) {
parent::__construct($iterator);
$this->equal = $equal;
$this->startDate = $startDate->format(self::DATE_FORMAT);
$this->endDate = $endDate->format(self::DATE_FORMAT);
}
Expand Down
16 changes: 3 additions & 13 deletions src/Yasumi/Holiday.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ class Holiday extends \DateTime implements \JsonSerializable
*/
public string $shortName;

/**
* @var array<string, string> list of translations of this holiday
*/
public array $translations;

/** identifies the type of holiday */
protected string $type;

/** locale (i.e. language) in which the holiday information needs to be displayed in. (Default 'en_US') */
protected string $displayLocale;

Expand All @@ -87,7 +79,7 @@ class Holiday extends \DateTime implements \JsonSerializable
* (DateTimeInterface) has the correct timezone set. Otherwise, the default system timezone is used.
*
* @param string $key Holiday key
* @param array<string, string> $names An array containing the name/description of this holiday in various
* @param array<string, string> $translations An array containing the name/description of this holiday in various
* languages. Overrides global translations
* @param \DateTimeInterface $date A DateTimeInterface instance representing the date of the holiday
* @param string $displayLocale Locale (i.e. language) in which the holiday information needs to be
Expand All @@ -102,10 +94,10 @@ class Holiday extends \DateTime implements \JsonSerializable
*/
public function __construct(
string $key,
array $names,
public array $translations,
\DateTimeInterface $date,
string $displayLocale = self::DEFAULT_LOCALE,
string $type = self::TYPE_OFFICIAL
protected string $type = self::TYPE_OFFICIAL
) {
// Validate if key is not empty
if ('' === $key) {
Expand All @@ -124,9 +116,7 @@ public function __construct(

// Set additional attributes
$this->shortName = $key;
$this->translations = $names;
$this->displayLocale = $displayLocale;
$this->type = $type;

// Construct instance
parent::__construct($date->format('Y-m-d'), $date->getTimezone());
Expand Down
6 changes: 1 addition & 5 deletions src/Yasumi/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ abstract class AbstractProvider implements \Countable, ProviderInterface, \Itera
*/
private array $holidays = [];

/** global translations */
private ?TranslationsInterface $globalTranslations;

/**
* Creates a new holiday provider (i.e. country/state).
*
Expand All @@ -97,13 +94,12 @@ abstract class AbstractProvider implements \Countable, ProviderInterface, \Itera
public function __construct(
int $year,
?string $locale = null,
?TranslationsInterface $globalTranslations = null
private ?TranslationsInterface $globalTranslations = null
) {
$this->clearHolidays();

$this->year = $year ?: (int) date('Y');
$this->locale = $locale ?? 'en_US';
$this->globalTranslations = $globalTranslations;

$this->initialize();
}
Expand Down
7 changes: 1 addition & 6 deletions src/Yasumi/Translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,12 @@ class Translations implements TranslationsInterface
*/
public array $translations = [];

/**
* @var array<string> list of all defined locales
*/
private array $availableLocales;

/**
* Constructor.
*
* @param array<string> $availableLocales list of all defined locales
*/
public function __construct(array $availableLocales)
public function __construct(private array $availableLocales)
{
$this->availableLocales = $availableLocales;
}
Expand Down

0 comments on commit 3499515

Please sign in to comment.