Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: drop support for php < 8.1 #15

Merged
merged 3 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
}
],
"require": {
"php": ">=5.5",
"symfony/yaml": "^3.2 | ^4.0 | ^5.0 | ^6.0"
"php": ">=8.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~8.1.0 || ~8.2.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean ~8.1.0 || ~8.2.0 || ~8.3.0 ?

"symfony/yaml": "^5.4 | ^6.0 | ^7.0",
"ext-simplexml": "*"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion resources/all.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@
array (
'alphabeticCode' => 'SLL',
'currency' => 'Leone',
'minorUnit' => 2,
'minorUnit' => 0,
'numericCode' => 694,
),
'SOS' =>
Expand Down
2 changes: 1 addition & 1 deletion resources/all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ SLE:
SLL:
alphabeticCode: SLL
currency: Leone
minorUnit: 2
minorUnit: 0
numericCode: 694
SOS:
alphabeticCode: SOS
Expand Down
2 changes: 1 addition & 1 deletion resources/current.json

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions resources/current.php
Original file line number Diff line number Diff line change
Expand Up @@ -902,13 +902,6 @@
'minorUnit' => 2,
'numericCode' => 925,
),
'SLL' =>
array (
'alphabeticCode' => 'SLL',
'currency' => 'Leone',
'minorUnit' => 2,
'numericCode' => 694,
),
'SOS' =>
array (
'alphabeticCode' => 'SOS',
Expand Down
5 changes: 0 additions & 5 deletions resources/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,6 @@ SLE:
currency: Leone
minorUnit: 2
numericCode: 925
SLL:
alphabeticCode: SLL
currency: Leone
minorUnit: 2
numericCode: 694
SOS:
alphabeticCode: SOS
currency: 'Somali Shilling'
Expand Down
2 changes: 1 addition & 1 deletion resources/historic.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions resources/historic.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,13 @@
'minorUnit' => 0,
'numericCode' => 703,
),
'SLL' =>
array (
'alphabeticCode' => 'SLL',
'currency' => 'Leone',
'minorUnit' => 0,
'numericCode' => 694,
),
'SRG' =>
array (
'alphabeticCode' => 'SRG',
Expand Down
5 changes: 5 additions & 0 deletions resources/historic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ SKK:
currency: 'Slovak Koruna'
minorUnit: 0
numericCode: 703
SLL:
alphabeticCode: SLL
currency: Leone
minorUnit: 0
numericCode: 694
SRG:
alphabeticCode: SRG
currency: 'Surinam Guilder'
Expand Down
68 changes: 10 additions & 58 deletions src/Country.php
Original file line number Diff line number Diff line change
@@ -1,85 +1,37 @@
<?php
namespace MoneyPHP\IsoCurrencies;

/**
* Class Country
* @package MoneyPHP\IsoCurrencies
*/
final class Country
{
/**
* @var string
*/
private $alphabeticCode;
/**
* @var string
*/
private $currency;
/**
* @var string
*/
private $entity;
/**
* @var int
*/
private $minorUnit;
/**
* @var int
*/
private $numericCode;

/**
* @param string $entity
* @param string $currency
* @param string $alphabeticCode
* @param int $numericCode
* @param int $minorUnit
*/
public function __construct($entity, $currency, $alphabeticCode, $numericCode, $minorUnit)
public function __construct(private readonly string $entity,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line

private readonly string $currency,
private readonly string $alphabeticCode,
private readonly int $numericCode,
private readonly int $minorUnit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line, identation

Copy link
Contributor Author

@Chris53897 Chris53897 Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed identation betwen type and variable name. I am not sure if you that is what you mean.

I am not sure where exact you want me to add the new line

{
$this->alphabeticCode = $alphabeticCode;
$this->currency = $currency;
$this->entity = $entity;
$this->minorUnit = $minorUnit;
$this->numericCode = $numericCode;
}

/**
* @return string
*/
public function getAlphabeticCode()
public function getAlphabeticCode(): string
{
return $this->alphabeticCode;
}

/**
* @return string
*/
public function getCurrency()
public function getCurrency(): string
{
return $this->currency;
}

/**
* @return string
*/
public function getEntity()
public function getEntity(): string
{
return $this->entity;
}

/**
* @return int
*/
public function getMinorUnit()
public function getMinorUnit(): int
{
return $this->minorUnit;
}

/**
* @return int
*/
public function getNumericCode()
public function getNumericCode(): int
{
return $this->numericCode;
}
Expand Down
57 changes: 22 additions & 35 deletions src/Fetcher.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,27 @@
<?php
namespace MoneyPHP\IsoCurrencies;

/**
* Class Fetcher
* @package MoneyPHP\IsoCurrencies
*/
final class Fetcher
{
/**
* @var string
*/
private $currentLocation;

/**
* @var string
*/
private $historicLocation;

/**
* @var null|array|Country[]
*/
private $currentCountries;
private ?array $currentCountries = null;

/**
* @var null|array|Country[]
*/
private $historicCountries;
private ?array $historicCountries = null;

/**
* @param string $currentLocation
* @param string $historicLocation
*/
public function __construct($currentLocation, $historicLocation)
public function __construct(private readonly string $currentLocation,
private readonly string $historicLocation)
{
$this->currentLocation = $currentLocation;
$this->historicLocation = $historicLocation;
}

/**
* @param string $fileName
* @param Serializer $serializer
* @throws \Exception
*/
public function saveCurrentCountriesTo($fileName, Serializer $serializer)
public function saveCurrentCountriesTo(string $fileName, Serializer $serializer): void
{
$this->fetch();

Expand All @@ -52,10 +32,9 @@ public function saveCurrentCountriesTo($fileName, Serializer $serializer)
}

/**
* @param string $fileName
* @param Serializer $serializer
* @throws \Exception
*/
public function saveHistoricCountriesTo($fileName, Serializer $serializer)
public function saveHistoricCountriesTo(string $fileName, Serializer $serializer): void
{
$this->fetch();

Expand All @@ -66,10 +45,9 @@ public function saveHistoricCountriesTo($fileName, Serializer $serializer)
}

/**
* @param string $fileName
* @param Serializer $serializer
* @throws \Exception
*/
public function saveAllCountriesTo($fileName, Serializer $serializer)
public function saveAllCountriesTo(string $fileName, Serializer $serializer): void
{
$this->fetch();

Expand All @@ -79,13 +57,19 @@ public function saveAllCountriesTo($fileName, Serializer $serializer)
);
}

private function fetch()
/**
* @throws \Exception
*/
private function fetch(): void
{
$this->fetchCurrentCountries();
$this->fetchHistoricCountries();
}

private function fetchCurrentCountries()
/**
* @throws \Exception
*/
private function fetchCurrentCountries(): void
{
if ($this->currentCountries === null) {
$this->currentCountries = [];
Expand All @@ -107,7 +91,10 @@ private function fetchCurrentCountries()
}
}

private function fetchHistoricCountries()
/**
* @throws \Exception
*/
private function fetchHistoricCountries(): void
{
if ($this->historicCountries === null) {
$this->historicCountries = [];
Expand Down
3 changes: 1 addition & 2 deletions src/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ interface Serializer
{
/**
* @param Country[] $countries
* @return string
*/
public function serialize(array $countries);
public function serialize(array $countries): string;
}
6 changes: 3 additions & 3 deletions src/Serializer/JsonSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ final class JsonSerializer implements Serializer
{
/**
* @param array|Country[] $countries
* @return string
* @throws \JsonException
*/
public function serialize(array $countries)
public function serialize(array $countries): string
{
$serialized = [];
foreach ($countries as $country) {
Expand All @@ -27,6 +27,6 @@ public function serialize(array $countries)

\ksort($serialized);

return json_encode($serialized);
return json_encode($serialized, JSON_THROW_ON_ERROR);
}
}
3 changes: 1 addition & 2 deletions src/Serializer/PhpExportSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ final class PhpExportSerializer implements Serializer
{
/**
* @param array|Country[] $countries
* @return string
*/
public function serialize(array $countries)
public function serialize(array $countries): string
{
$serialized = [];
foreach ($countries as $country) {
Expand Down
3 changes: 1 addition & 2 deletions src/Serializer/YamlSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ final class YamlSerializer implements Serializer
{
/**
* @param array|Country[] $countries
* @return string
*/
public function serialize(array $countries)
public function serialize(array $countries): string
{
$serialized = [];
foreach ($countries as $country) {
Expand Down