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

Support symfony 7 #11

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.phpunit.result.cache
composer.lock
.php-cs-fixer.cache
/.phpunit.cache
.idea
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
"type": "symfony-bundle",
"license": "MIT",
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.2",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^6.0|^7.0",
"marc-mabe/php-enum": "^4.3",
"symfony/http-kernel": "^5.4|^6.0",
"webmozart/assert": "^1.3"
"symfony/http-kernel": "^6.4|^7.0",
"webmozart/assert": "^1.11"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpro/grumphp": "^1.5.0",
"phpunit/phpunit": "^9.5",
"friendsofphp/php-cs-fixer": "^3.64",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpro/grumphp": "^2.6",
"phpunit/phpunit": "^10.5",
"roave/security-advisories": "dev-master",
"symfony/phpunit-bridge": "6.1.*"
"symfony/phpunit-bridge": "6.4|^7.0"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 4 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/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"
>
<php>
<ini name="error_reporting" value="-1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>

<testsuites>
<testsuite name="Answear DpdPlPickupServicesBundle Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
53 changes: 8 additions & 45 deletions src/Enum/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,13 @@

namespace Answear\DpdPlPickupServicesBundle\Enum;

use MabeEnum\Enum;

class Day extends Enum
enum Day: string
{
public const MONDAY = '1';
public const TUESDAY = '2';
public const WEDNESDAY = '3';
public const THURSDAY = '4';
public const FRIDAY = '5';
public const SATURDAY = '6';
public const SUNDAY = '7';

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

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

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

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

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

public static function saturday(): self
{
return static::get(static::SATURDAY);
}

public static function sunday(): self
{
return static::get(static::SUNDAY);
}
case Monday = '1';
case Tuesday = '2';
case Wednesday = '3';
case Thursday = '4';
case Friday = '5';
case Saturday = '6';
case Sunday = '7';
}
74 changes: 11 additions & 63 deletions src/Enum/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,16 @@

namespace Answear\DpdPlPickupServicesBundle\Enum;

use MabeEnum\Enum;

class Service extends Enum
enum Service: string
{
public const DELIVERY = '100';
public const COD = '101';
public const SWAP = '300';
public const DROPOFF_ONLINE = '200';
public const DROPOFF_OFFLINE = '201';
public const MONITORED_DOCUMENTS = 'P10';
public const ROD = 'P20';
public const TYRES = 'P30';
public const PALLET = 'P90';
public const DRESSING_ROOM = '10001';

public static function delivery(): self
{
return static::get(static::DELIVERY);
}

public static function cod(): self
{
return static::get(static::COD);
}

public static function swap(): self
{
return static::get(static::SWAP);
}

public static function dropoffOnline(): self
{
return static::get(static::DROPOFF_ONLINE);
}

public static function dropoffOffline(): self
{
return static::get(static::DROPOFF_OFFLINE);
}

public static function monitoredDocuments(): self
{
return static::get(static::MONITORED_DOCUMENTS);
}

public static function rod(): self
{
return static::get(static::ROD);
}

public static function tyres(): self
{
return static::get(static::TYRES);
}

public static function pallet(): self
{
return static::get(static::PALLET);
}

public static function dressingRoom(): self
{
return static::get(static::DRESSING_ROOM);
}
case Delivery = '100';
case COD = '101';
case Swap = '300';
case DropoffOnline = '200';
case DropoffOffline = '201';
case MonitoredDocuments = 'P10';
case Rod = 'P20';
case Tyres = 'P30';
case Pallet = 'P90';
case DressingRoom = '10001';
}
60 changes: 9 additions & 51 deletions src/Enum/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,14 @@

namespace Answear\DpdPlPickupServicesBundle\Enum;

use MabeEnum\Enum;

class Type extends Enum
enum Type: string
{
public const STANDARD = '100';
public const CHAIN = '200';
public const DPD = '300';
public const SWIP_BOX_1 = '400401';
public const SWIP_BOX_2 = '400402';
public const POINT_PACK = '500501';
public const FOREIGN_LOCKER = '400';
public const FOREIGN_EXTERNAL_LOCKER = '501';

public static function standard(): self
{
return self::get(self::STANDARD);
}

public static function chain(): self
{
return self::get(self::CHAIN);
}

public static function dpd(): self
{
return self::get(self::DPD);
}

public static function swipBox1(): self
{
return self::get(self::SWIP_BOX_1);
}

public static function swipBox2(): self
{
return self::get(self::SWIP_BOX_2);
}

public static function pointPack(): self
{
return self::get(self::POINT_PACK);
}

public static function foreignLocker(): self
{
return self::get(self::FOREIGN_LOCKER);
}

public static function foreignExternalLocker(): self
{
return self::get(self::FOREIGN_EXTERNAL_LOCKER);
}
case Standard = '100';
case Chain = '200';
case Dpd = '300';
case SwipBox1 = '400401';
case SwipBox2 = '400402';
case PointPack = '500501';
case ForeignLocker = '400';
case ForeignExternalLocker = '501';
}
10 changes: 1 addition & 9 deletions src/Exception/MalformedResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@

class MalformedResponseException extends \RuntimeException
{
private string $response;

public function __construct(string $response)
public function __construct(public string $response)
{
parent::__construct('Response is not a valid XML');
$this->response = $response;
}

public function getResponse(): string
{
return $this->response;
}
}
28 changes: 6 additions & 22 deletions src/Service/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,13 @@

class ConfigProvider
{
private string $url;
private string $key;
private float $requestTimeout;
public string $url;

public function __construct(string $url, string $key, float $requestTimeout)
{
public function __construct(
string $url,
public string $key,
public float $requestTimeout,
) {
$this->url = rtrim($url, '/') . '/';
$this->key = $key;
$this->requestTimeout = $requestTimeout;
}

public function getUrl(): string
{
return $this->url;
}

public function getKey(): string
{
return $this->key;
}

public function getRequestTimeout(): float
{
return $this->requestTimeout;
}
}
8 changes: 4 additions & 4 deletions src/Service/PUDOFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function fromXmlElement(\SimpleXMLElement $xml): PUDO
$pudo = new PUDO();
$pudo->active = 'true' === (string) $xml['active'];
$pudo->id = (string) $xml->PUDO_ID;
$pudo->type = Type::byValue((string) $xml->PUDO_TYPE);
$pudo->type = Type::from((string) $xml->PUDO_TYPE);
$pudo->language = (string) $xml->LANGUAGE;
$pudo->address = $this->createAddress($xml);
$pudo->coordinates = new Coordinates((float) $xml->LATITUDE, (float) $xml->LONGITUDE);
Expand Down Expand Up @@ -52,8 +52,8 @@ private function createAdditionalInfo(\SimpleXMLElement $xml): AdditionalInfo
$info = new AdditionalInfo();
foreach (explode(';', (string) $xml->SERVICE_PUDO) as $service) {
try {
$info->services[] = Service::byValue($service);
} catch (\InvalidArgumentException $e) {
$info->services[] = Service::from($service);
} catch (\ValueError) {
// NOP, do not fail hard for new services
}
}
Expand All @@ -68,7 +68,7 @@ private function createOpeningTimes(\SimpleXMLElement $xml): WeekStoreHours
$openings = [];
foreach ($xml->OPENING_HOURS_ITEMS->OPENING_HOURS_ITEM as $opening) {
$openings[] = new OpeningTime(
Day::byValue((string) $opening->DAY_ID),
Day::from((string) $opening->DAY_ID),
(string) $opening->START_TM,
(string) $opening->END_TM
);
Expand Down
Loading
Loading