Skip to content

Commit

Permalink
Merge pull request #13 from answear/support-symfony-7
Browse files Browse the repository at this point in the history
Support symfony 7
  • Loading branch information
Wiktor6 authored Sep 30, 2024
2 parents 3d804b9 + 1c5c032 commit e16bf04
Show file tree
Hide file tree
Showing 19 changed files with 165 additions and 265 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
deps:
- "normal"
include:
- deps: "low"
php-version: "7.4"
- "low"

steps:
- name: "Checkout"
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ composer.lock
/.idea
/.env*
/composer.phar
/.phpunit.cache
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'strict_param' => false,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'phpdoc_align' => [],
'phpdoc_align' => ['align' => 'left'],
'phpdoc_summary' => false,
'void_return' => false,
'phpdoc_var_without_name' => false,
Expand Down
27 changes: 13 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
"type": "symfony-bundle",
"license": "MIT",
"require": {
"php": ">=7.4|^8.0",
"php": "^8.2",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.0|^7.0",
"marc-mabe/php-enum": "^3.0|^4.3",
"psr/log": "^1.0",
"symfony/http-kernel": "^5.4|^6.0",
"symfony/property-info": "^5.4|^6.0",
"symfony/serializer": "^5.4|^6.0",
"webmozart/assert": "^1.10"
"psr/log": "^1.1",
"symfony/http-kernel": "^6.0|^7.1",
"symfony/property-info": "^6.0|^7.1",
"symfony/serializer": "^6.0|^7.1",
"webmozart/assert": "^1.11"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
"matthiasnoback/symfony-config-test": "^4.3",
"phpro/grumphp": "^1.5.0",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpunit/phpunit": "^9.5",
"friendsofphp/php-cs-fixer": "^3.64",
"matthiasnoback/symfony-config-test": "^5.2",
"phpro/grumphp": "^2.8",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpunit/phpunit": "^10.5",
"roave/security-advisories": "dev-master",
"symfony/phpunit-bridge": "6.1.*"
"symfony/phpunit-bridge": "6.1.*|^7.1"
},
"autoload": {
"psr-4": {
Expand Down
17 changes: 5 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.4/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="./vendor/autoload.php"
backupGlobals="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
cacheDirectory=".phpunit.cache"
beStrictAboutCoverageMetadata="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<php>
<ini name="error_reporting" value="-1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>

<testsuites>
<testsuite name="Answear.com FoxPost Parcel Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
32 changes: 5 additions & 27 deletions src/Response/Enum/ApmType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,10 @@

namespace Answear\FoxPostParcel\Response\Enum;

use MabeEnum\Enum;

class ApmType extends Enum
enum ApmType: string
{
public const UNKNOWN = 'Unknown';
public const ROLLKON = 'Rollkon';
public const CLEVERON = 'Cleveron';
public const KEBA = 'Keba';

public static function unknown(): self
{
return static::get(self::UNKNOWN);
}

public static function rollkon(): self
{
return static::get(self::ROLLKON);
}

public static function cleveron(): self
{
return static::get(self::CLEVERON);
}

public static function keba(): self
{
return static::get(self::KEBA);
}
case Unknown = 'Unknown';
case Rollkon = 'Rollkon';
case Cleveron = 'Cleveron';
case Keba = 'Keba';
}
53 changes: 8 additions & 45 deletions src/Response/Enum/DayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,13 @@

namespace Answear\FoxPostParcel\Response\Enum;

use MabeEnum\Enum;

class DayType extends Enum
enum DayType: string
{
public const MONDAY = 'hetfo';
public const TUESDAY = 'kedd';
public const WEDNESDAY = 'szerda';
public const THURSDAY = 'csutortok';
public const FRIDAY = 'pentek';
public const SATURDAY = 'szombat';
public const SUNDAY = 'vasarnap';

public static function friday(): self
{
return static::get(static::FRIDAY);
}

public static function thursday(): self
{
return static::get(static::THURSDAY);
}

public static function wednesday(): self
{
return static::get(static::WEDNESDAY);
}

public static function tuesday(): self
{
return static::get(static::TUESDAY);
}

public static function monday(): self
{
return static::get(static::MONDAY);
}

public static function sunday(): self
{
return static::get(static::SUNDAY);
}

public static function saturday(): self
{
return static::get(static::SATURDAY);
}
case Monday = 'hetfo';
case Tuesday = 'kedd';
case Wednesday = 'szerda';
case Thursday = 'csutortok';
case Friday = 'pentek';
case Saturday = 'szombat';
case Sunday = 'vasarnap';
}
12 changes: 5 additions & 7 deletions src/Response/GetParcelShopsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
use Answear\FoxPostParcel\Response\Struct\ParcelShop;
use Answear\FoxPostParcel\Response\Struct\ParcelShopCollection;

class GetParcelShopsResponse
readonly class GetParcelShopsResponse
{
public ParcelShopCollection $parcelShopCollection;

public function __construct(ParcelShopCollection $parcelShopCollection)
{
$this->parcelShopCollection = $parcelShopCollection;
public function __construct(
public ParcelShopCollection $parcelShopCollection,
) {
}

public static function fromArray(array $arrayResponse): self
{
return new self(new ParcelShopCollection(\array_map(fn($pointData) => ParcelShop::fromArray($pointData), $arrayResponse)));
return new self(new ParcelShopCollection(\array_map(static fn($pointData) => ParcelShop::fromArray($pointData), $arrayResponse)));
}

public function getParcelShopCollection(): ParcelShopCollection
Expand Down
31 changes: 16 additions & 15 deletions src/Response/Struct/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

use Webmozart\Assert\Assert;

class Address
readonly class Address
{
public string $zipCode;
public string $city;
public string $street;
public string $fullAddress;
public ?string $addressDescription;
public function __construct(
public string $zipCode,
public string $city,
public string $street,
public string $fullAddress,
public ?string $addressDescription,
) {
}

public static function fromArray(array $parcelShopData): self
{
Expand All @@ -20,14 +23,12 @@ public static function fromArray(array $parcelShopData): self
Assert::stringNotEmpty($parcelShopData['address']);
Assert::string($parcelShopData['findme']);

$address = new self();

$address->zipCode = $parcelShopData['zip'];
$address->city = $parcelShopData['city'];
$address->street = $parcelShopData['street'];
$address->fullAddress = $parcelShopData['address'];
$address->addressDescription = empty($parcelShopData['findme']) ? null : $parcelShopData['findme'];

return $address;
return new self(
$parcelShopData['zip'],
$parcelShopData['city'],
$parcelShopData['street'],
$parcelShopData['address'],
empty($parcelShopData['findme']) ? null : $parcelShopData['findme']
);
}
}
14 changes: 5 additions & 9 deletions src/Response/Struct/Coordinates.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@

use Webmozart\Assert\Assert;

class Coordinates
readonly class Coordinates
{
public float $latitude;
public float $longitude;

public function __construct(float $latitude, float $longitude)
{
public function __construct(
public float $latitude,
public float $longitude,
) {
Assert::range($latitude, -90, 90);
Assert::range($longitude, -180, 180);

$this->latitude = $latitude;
$this->longitude = $longitude;
}
}
57 changes: 28 additions & 29 deletions src/Response/Struct/ParcelShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
use Answear\FoxPostParcel\Response\Enum\ApmType;
use Webmozart\Assert\Assert;

class ParcelShop
readonly class ParcelShop
{
public int $placeId;
public string $operatorId;
public string $name;
public Coordinates $coordinates;
public Address $address;
public bool $isOutdoor;
public ApmType $apmType;
/**
* @var WorkingHours[]
* @param WorkingHours[] $workingHours
*/
public array $workingHours = [];
public function __construct(
public int $placeId,
public string $operatorId,
public string $name,
public Coordinates $coordinates,
public Address $address,
public bool $isOutdoor,
public ApmType $apmType,
public array $workingHours,
) {
}

public static function fromArray(array $parcelShopData): self
{
Expand All @@ -30,33 +33,29 @@ public static function fromArray(array $parcelShopData): self
Assert::string($parcelShopData['apmType']);
Assert::allNotEmpty($parcelShopData['open']);

$parcelShop = new self();
$address = Address::fromArray($parcelShopData);

$parcelShop->address = $address;
$parcelShop->placeId = $parcelShopData['place_id'];
$parcelShop->operatorId = $parcelShopData['operator_id'];
$parcelShop->name = $parcelShopData['name'];
$parcelShop->coordinates = new Coordinates($parcelShopData['geolat'], $parcelShopData['geolng']);
$parcelShop->isOutdoor = $parcelShopData['isOutdoor'];
$parcelShop->apmType = self::getApmType($parcelShopData['apmType']);

$workingHours = [];
foreach ($parcelShopData['open'] as $day => $workingHoursString) {
$workingHours = WorkingHours::fromArray($day, $workingHoursString);
if (null !== $workingHours) {
$parcelShop->workingHours[] = $workingHours;
}
$workingHours[] = WorkingHours::fromArray($day, $workingHoursString);
}

return $parcelShop;
return new self(
$parcelShopData['place_id'],
$parcelShopData['operator_id'],
$parcelShopData['name'],
new Coordinates($parcelShopData['geolat'], $parcelShopData['geolng']),
Address::fromArray($parcelShopData),
$parcelShopData['isOutdoor'],
self::getApmType($parcelShopData['apmType']),
$workingHours
);
}

private static function getApmType(string $apmTypeValue): ApmType
{
try {
return ApmType::byValue($apmTypeValue);
} catch (\InvalidArgumentException $exception) {
return ApmType::unknown();
return ApmType::from($apmTypeValue);
} catch (\ValueError) {
return ApmType::Unknown;
}
}
}
Loading

0 comments on commit e16bf04

Please sign in to comment.