Skip to content

Commit

Permalink
Update to symfony 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiktor6 committed Sep 30, 2024
1 parent 7c08d6f commit 448f2ab
Show file tree
Hide file tree
Showing 25 changed files with 142 additions and 451 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 @@ -5,3 +5,4 @@
composer.lock
/.idea
/.env*
/.phpunit.cache
20 changes: 9 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@
"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|^6.4",
"symfony/property-info": "^5.4|^6.0|^6.4",
"symfony/serializer": "^5.4|^6.0|^6.4",
"webmozart/assert": "^1.10"
"psr/log": "^1.1",
"symfony/http-kernel": "^6.4|^7.0",
"symfony/property-info": "^6.4|^7.0",
"symfony/serializer": "^6.4|^7.0",
"webmozart/assert": "^1.11"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.58",
"matthiasnoback/symfony-config-test": "^4.3",
"friendsofphp/php-cs-fixer": "^3.64",
"phpro/grumphp": "^1.5.0|^2.5",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^10.5",
"roave/security-advisories": "dev-master",
"symfony/phpunit-bridge": "6.4.*"
"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/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"
>
<php>
<ini name="error_reporting" value="-1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
</php>

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

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
34 changes: 8 additions & 26 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,24 @@

use Answear\AcsBundle\Request\BaseInputParameters;

class ConfigProvider
readonly class ConfigProvider
{
private const API_URL = 'https://webservices.acscourier.net/ACSRestServices/api/ACSAutoRest';

private string $apiKey;
private string $companyId;
private string $companyPassword;
private string $userId;
private string $userPassword;
private string $language;

public function __construct(
string $apiKey,
string $companyId,
string $companyPassword,
string $userId,
string $userPassword,
string $language
private string $apiKey,
private string $companyId,
private string $companyPassword,
private string $userId,
private string $userPassword,
private string $language,
) {
$this->apiKey = $apiKey;
$this->companyId = $companyId;
$this->companyPassword = $companyPassword;
$this->userId = $userId;
$this->userPassword = $userPassword;
$this->language = $language;
}

public function getRequestHeaders(): array
{
return [
'AcsApiKey' => $this->getApiKey(),
'AcsApiKey' => $this->apiKey,
'Content-Type' => 'application/json',
];
}
Expand All @@ -50,9 +37,4 @@ public function getUrl(): string
{
return self::API_URL;
}

private function getApiKey(): string
{
return $this->apiKey;
}
}
18 changes: 3 additions & 15 deletions src/Enum/CountryIdEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@

namespace Answear\AcsBundle\Enum;

use MabeEnum\Enum;

class CountryIdEnum extends Enum
enum CountryIdEnum: string
{
public const GREECE = 'GR';
public const CYPRUS = 'CY';

public static function greece(): self
{
return static::get(static::GREECE);
}

public static function cyprus(): self
{
return static::get(static::CYPRUS);
}
case Greece = 'GR';
case Cyprus = 'CY';
}
20 changes: 7 additions & 13 deletions src/Request/BaseInputParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,13 @@

class BaseInputParameters
{
protected string $companyId;
protected string $companyPassword;
protected string $userId;
protected string $userPassword;
protected string $language;

public function __construct(string $companyId, string $companyPassword, string $userId, string $userPassword, string $language)
{
$this->companyId = $companyId;
$this->companyPassword = $companyPassword;
$this->userId = $userId;
$this->userPassword = $userPassword;
$this->language = $language;
public function __construct(
protected string $companyId,
protected string $companyPassword,
protected string $userId,
protected string $userPassword,
protected string $language,
) {
}

public function toArray(): array
Expand Down
27 changes: 13 additions & 14 deletions src/Request/StationsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,29 @@ class StationsRequest implements Request
{
private const ALIAS = 'ACS_Stations';

private BaseInputParameters $baseInputParameters;
private CountryIdEnum $countryId;
private ?int $kind;

public function __construct(BaseInputParameters $baseInputParameters, CountryIdEnum $countryId, ?int $kind = null)
{
$this->baseInputParameters = $baseInputParameters;
$this->countryId = $countryId;
$this->kind = $kind;
public function __construct(
private readonly BaseInputParameters $baseInputParameters,
private readonly CountryIdEnum $countryId,
private readonly ?int $kind = null,
) {
}

public function toJson(): string
{
$parameters = [
'ACS_SHOP_COUNTRY_ID' => $this->countryId->getValue(),
'ACS_SHOP_COUNTRY_ID' => $this->countryId->value,
];

if (null !== $this->kind) {
$parameters['ACS_SHOP_KIND'] = $this->kind;
}

return json_encode([
'ACSAlias' => self::ALIAS,
'ACSInputParameters' => array_merge($parameters, $this->baseInputParameters->toArray()),
], JSON_THROW_ON_ERROR);
return json_encode(
[
'ACSAlias' => self::ALIAS,
'ACSInputParameters' => array_merge($parameters, $this->baseInputParameters->toArray()),
],
JSON_THROW_ON_ERROR
);
}
}
57 changes: 7 additions & 50 deletions src/Response/DTO/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,16 @@

use Webmozart\Assert\Assert;

class Address
readonly class Address
{
private string $street;
private string $zipCode;
private string $city;
private string $phones;
private string $email;
private string $fax;

public function __construct(
string $street,
string $zipCode,
string $city,
string $phones,
string $email,
string $fax
public string $street,
public string $zipCode,
public string $city,
public string $phones,
public string $email,
public string $fax,
) {
$this->street = $street;
$this->zipCode = $zipCode;
$this->city = $city;
$this->phones = $phones;
$this->email = $email;
$this->fax = $fax;
}

public static function fromArray(array $parcelShopArray): self
Expand All @@ -49,34 +36,4 @@ public static function fromArray(array $parcelShopArray): self
$parcelShopArray['ACS_SHOP_FAX']
);
}

public function getZipCode(): string
{
return $this->zipCode;
}

public function getCity(): string
{
return $this->city;
}

public function getStreet(): string
{
return $this->street;
}

public function getFax(): ?string
{
return $this->fax;
}

public function getPhones(): ?string
{
return $this->phones;
}

public function getEmail(): ?string
{
return $this->email;
}
}
12 changes: 4 additions & 8 deletions src/Response/DTO/Coordinates.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@

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;
}

public static function fromArray(array $parcelShopArray): self
Expand Down
Loading

0 comments on commit 448f2ab

Please sign in to comment.