Skip to content

Commit

Permalink
Change endpoint for parcel points
Browse files Browse the repository at this point in the history
  • Loading branch information
yekovalenkoa committed Sep 4, 2024
1 parent ba016f9 commit fda4b0a
Show file tree
Hide file tree
Showing 33 changed files with 1,877 additions and 2,158 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ jobs:
strategy:
matrix:
php-version:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
deps:
- "normal"
include:
- deps: "low"
php-version: "7.4"
php-version: "8.2"

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
31 changes: 15 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@
"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.3",
"symfony/property-access": "^5.4|^6.0"
"guzzlehttp/guzzle": "^6.0|^7.9.2",
"psr/log": "^1.1.4",
"symfony/http-kernel": "6.4.*",
"symfony/property-access": "6.4.*",
"symfony/property-info": "6.4.*",
"symfony/serializer": "6.4.*",
"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.63.2",
"matthiasnoback/symfony-config-test": "^5.2",
"phpro/grumphp": "^2.7.0",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-webmozart-assert": "^1.2.10",
"phpunit/phpunit": "^10.5.30",
"roave/security-advisories": "dev-master",
"symfony/phpunit-bridge": "6.1.*"
"symfony/phpunit-bridge": "6.4.*"
},
"autoload": {
"psr-4": {
Expand Down
13 changes: 1 addition & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
<?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="vendor/phpunit/phpunit/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"
>
<php>
<ini name="error_reporting" value="-1"/>
Expand All @@ -23,7 +15,4 @@
</testsuite>
</testsuites>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
6 changes: 1 addition & 5 deletions src/Client/RequestTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class RequestTransformer

public function __construct(
Serializer $serializer,
ConfigProvider $configuration
ConfigProvider $configuration,
) {
$this->serializer = $serializer;
$this->configuration = $configuration;
Expand All @@ -27,10 +27,6 @@ public function transform(RequestInterface $request): HttpRequest
{
$uri = $this->configuration->getUrl() . $request->getEndpoint();

if (null !== $request->getUrlQuery()) {
$uri .= '?' . $request->getUrlQuery();
}

return new HttpRequest(
$request->getMethod(),
new Uri($uri),
Expand Down
31 changes: 12 additions & 19 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,31 @@

namespace Answear\GlsBundle;

use Answear\GlsBundle\Enum\CountryCode;
use Answear\GlsBundle\Enum\CountryCodeEnum;

class ConfigProvider
{
private const URL_MAP = [
CountryCode::HUNGARY => 'https://online.gls-hungary.com/',
CountryCode::SLOVAKIA => 'https://online.gls-slovakia.com/',
CountryCode::CZECH => 'https://online.gls-czech.com/',
CountryCode::ROMANIA => 'https://online.gls-romania.com/',
CountryCode::SLOVENIA => 'https://online.gls-slovenia.com/',
CountryCode::CROATIA => 'https://online.gls-croatia.com/',
];

private CountryCode $countryCode;
private CountryCodeEnum $countryCode;

public function __construct(string $countryCode)
{
$this->countryCode = CountryCode::byValue($countryCode);
$this->countryCode = CountryCodeEnum::from($countryCode);
}

public function getCountryCode(): CountryCode
public function getCountryCode(): CountryCodeEnum
{
return $this->countryCode;
}

public function getUrl(): string
{
$url = self::URL_MAP[$this->getCountryCode()->getValue()] ?? null;
if (null === $url) {
throw new \InvalidArgumentException('No url for provided country code.');
}

return $url;
return match ($this->getCountryCode()) {
CountryCodeEnum::Romania,
CountryCodeEnum::Hungary => 'https://map.gls-hungary.com/',
CountryCodeEnum::Slovakia => 'https://map.gls-slovakia.com/',
CountryCodeEnum::Czech => 'https://map.gls-czech.com/',
CountryCodeEnum::Slovenia => 'https://map.gls-slovenia.com/',
CountryCodeEnum::Croatia => 'https://map.gls-croatia.com/',
};
}
}
15 changes: 13 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Answear\GlsBundle\DependencyInjection;

use Answear\GlsBundle\Enum\CountryCode;
use Answear\GlsBundle\Enum\CountryCodeEnum;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand All @@ -17,12 +17,23 @@ public function getConfigTreeBuilder(): TreeBuilder
$treeBuilder->getRootNode()
->children()
->enumNode('countryCode')
->values(CountryCode::getValues())
->values($this->getCountryCodes())
->isRequired()
->end()
->scalarNode('logger')->defaultValue(null)->end()
->end();

return $treeBuilder;
}

/**
* @return string[]
*/
private function getCountryCodes(): array
{
return array_map(
static fn(CountryCodeEnum $countryCode) => $countryCode->value,
CountryCodeEnum::cases(),
);
}
}
47 changes: 0 additions & 47 deletions src/Enum/CountryCode.php

This file was deleted.

15 changes: 15 additions & 0 deletions src/Enum/CountryCodeEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Answear\GlsBundle\Enum;

enum CountryCodeEnum: string
{
case Hungary = 'HU';
case Slovakia = 'SK';
case Czech = 'CZ';
case Romania = 'RO';
case Slovenia = 'SI';
case Croatia = 'HR';
}
56 changes: 0 additions & 56 deletions src/Enum/DayType.php

This file was deleted.

30 changes: 30 additions & 0 deletions src/Enum/DayTypeEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Answear\GlsBundle\Enum;

enum DayTypeEnum: string
{
case Monday = 'monday';
case Tuesday = 'tuesday';
case Wednesday = 'wednesday';
case Thursday = 'thursday';
case Friday = 'friday';
case Saturday = 'saturday';
case Sunday = 'sunday';

public static function getDayByNumber(int $dayNumber): self
{
return match ($dayNumber) {
1 => self::Monday,
2 => self::Tuesday,
3 => self::Wednesday,
4 => self::Thursday,
5 => self::Friday,
6 => self::Saturday,
7 => self::Sunday,
default => throw new \InvalidArgumentException("Invalid day number: $dayNumber"),
};
}
}
25 changes: 25 additions & 0 deletions src/Enum/FeatureEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Answear\GlsBundle\Enum;

enum FeatureEnum: string implements \JsonSerializable
{
case AcceptsCash = 'acceptsCash';
case AcceptsCard = 'acceptsCard';
case Pickup = 'pickup';
case Delivery = 'delivery';

public static function isAcceptsCard(string $value): bool
{
return $value === self::AcceptsCard->value;
}

public function jsonSerialize(): array
{
return [
'value' => $this->value,
];
}
}
Loading

0 comments on commit fda4b0a

Please sign in to comment.