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 #9

Merged
merged 1 commit into from
Oct 2, 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"
Expand Down
23 changes: 11 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@
"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",
"symfony/http-kernel": "^5.4|^6.0",
"symfony/property-access": "^5.4|^6.0",
"symfony/serializer": "^5.4|^6.0",
"webmozart/assert": "^1.3"
"symfony/http-kernel": "^6.0|^7.0",
"symfony/property-access": "^6.0|^7.0",
"symfony/serializer": "^6.0|^7.0",
"webmozart/assert": "^1.11"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
"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",
"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.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.com SpeedyBundle Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
13 changes: 5 additions & 8 deletions src/Client/AuthenticationDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@

class AuthenticationDecorator
{
private ConfigProvider $configuration;

public function __construct(ConfigProvider $configuration)
public function __construct(private ConfigProvider $configuration)
{
$this->configuration = $configuration;
}

public function decorate(Request $request): void
{
$request->setUserName($this->configuration->getUsername());
$request->setPassword($this->configuration->getPassword());
$request->setLanguage($this->configuration->getLanguage());
$request->setClientSystemId($this->configuration->getClientSystemId());
$request->userName = $this->configuration->username;
$request->password = $this->configuration->password;
$request->language = $this->configuration->language;
$request->clientSystemId = $this->configuration->clientSystemId;
}
}
10 changes: 3 additions & 7 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,16 @@ class Client
{
private const CONNECTION_TIMEOUT = 10;
private const TIMEOUT = 30;

private ConfigProvider $configuration;
private ClientInterface $client;

public function __construct(
ConfigProvider $configuration,
?ClientInterface $client = null
private ConfigProvider $configuration,
private ?ClientInterface $client = null,
) {
$this->configuration = $configuration;
$this->client = $client ?? new GuzzleClient(
[
'base_uri' => $configuration->getUrl(),
'timeout' => self::TIMEOUT,
'connect_timeout' => self::CONNECTION_TIMEOUT
'connect_timeout' => self::CONNECTION_TIMEOUT,
]
);
}
Expand Down
13 changes: 3 additions & 10 deletions src/Client/RequestTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,11 @@

class RequestTransformer
{
private Serializer $serializer;
private AuthenticationDecorator $decorator;
private ConfigProvider $configuration;

public function __construct(
Serializer $serializer,
AuthenticationDecorator $decorator,
ConfigProvider $configuration
private Serializer $serializer,
private AuthenticationDecorator $decorator,
private ConfigProvider $configuration,
) {
$this->serializer = $serializer;
$this->decorator = $decorator;
$this->configuration = $configuration;
}

public function transform(Request $request): HttpRequest
Expand Down
11 changes: 4 additions & 7 deletions src/Command/FindOffice.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@

class FindOffice extends AbstractCommand
{
private Client $client;
private RequestTransformer $transformer;

public function __construct(Client $client, RequestTransformer $transformer)
{
$this->client = $client;
$this->transformer = $transformer;
public function __construct(
private Client $client,
private RequestTransformer $transformer,
) {
}

public function findOffice(FindOfficeRequest $request): FindOfficeResponse
Expand Down
11 changes: 4 additions & 7 deletions src/Command/GetAllPostCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@

class GetAllPostCodes extends AbstractCommand
{
private Client $client;
private RequestTransformer $transformer;

public function __construct(Client $client, RequestTransformer $transformer)
{
$this->client = $client;
$this->transformer = $transformer;
public function __construct(
private Client $client,
private RequestTransformer $transformer,
) {
}

public function getAllPostCodes(GetAllPostCodesRequest $request): GetAllPostCodesResponse
Expand Down
11 changes: 4 additions & 7 deletions src/Command/GetAllSites.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@

class GetAllSites extends AbstractCommand
{
private Client $client;
private RequestTransformer $transformer;

public function __construct(Client $client, RequestTransformer $transformer)
{
$this->client = $client;
$this->transformer = $transformer;
public function __construct(
private Client $client,
private RequestTransformer $transformer,
) {
}

public function getAllSites(GetAllSitesRequest $request): GetAllSitesResponse
Expand Down
38 changes: 8 additions & 30 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ class ConfigProvider
private const URL = 'https://api.speedy.bg/';
private const API_VERSION = 'v1';

private string $username;
private string $password;
private string $language;
private ?int $clientSystemId;

public function __construct(string $username, string $password, string $language, ?string $clientSystemId = null)
{
$this->username = $username;
$this->password = $password;
$this->language = $language;
public readonly ?int $clientSystemId;

public function __construct(
public readonly string $username,
public readonly string $password,
public readonly string $language,
?string $clientSystemId = null,
) {
$this->clientSystemId = empty($clientSystemId) || !\is_numeric($clientSystemId) ? null : (int) $clientSystemId;
}

Expand All @@ -31,24 +29,4 @@ public function getApiVersion(): string
{
return self::API_VERSION;
}

public function getUsername(): string
{
return $this->username;
}

public function getPassword(): string
{
return $this->password;
}

public function getLanguage(): string
{
return $this->language;
}

public function getClientSystemId(): ?int
{
return $this->clientSystemId;
}
}
25 changes: 4 additions & 21 deletions src/Enum/CargoType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,9 @@

namespace Answear\SpeedyBundle\Enum;

use MabeEnum\Enum;

class CargoType extends Enum
enum CargoType: string
{
public const PARCEL = 'PARCEL';
public const PALLET = 'PALLET';
public const TYRE = 'TYRE';

public static function parcel(): self
{
return static::get(static::PARCEL);
}

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

public static function tyre(): self
{
return static::get(static::PALLET);
}
case Parcel = 'PARCEL';
case Pallet = 'PALLET';
case Tyre = 'TYRE';
}
18 changes: 3 additions & 15 deletions src/Enum/OfficeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@

namespace Answear\SpeedyBundle\Enum;

use MabeEnum\Enum;

class OfficeType extends Enum
enum OfficeType: string
{
public const OFFICE = 'OFFICE';
public const APT = 'APT';

public static function office(): self
{
return static::get(static::OFFICE);
}

public static function apt(): self
{
return static::get(static::APT);
}
case Office = 'OFFICE';
case Apt = 'APT';
}
17 changes: 6 additions & 11 deletions src/Request/FindOfficeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@ class FindOfficeRequest extends Request
private const ENDPOINT = '/location/office';
private const HTTP_METHOD = 'POST';

private ?int $countryId;
private ?int $siteId;
private ?string $name;
private ?int $limit;

public function __construct(?int $countryId = null, ?int $siteId = null, ?string $name = null, ?int $limit = null)
{
$this->countryId = $countryId;
$this->siteId = $siteId;
$this->name = $name;
$this->limit = $limit;
public function __construct(
private ?int $countryId = null,
private ?int $siteId = null,
private ?string $name = null,
private ?int $limit = null,
) {
}

public function getEndpoint(): string
Expand Down
5 changes: 1 addition & 4 deletions src/Request/GetAllPostCodesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ class GetAllPostCodesRequest extends Request
private const ENDPOINT = '/location/postcode/csv';
private const HTTP_METHOD = 'POST';

private int $countryId;

public function __construct(int $countryId)
public function __construct(public readonly int $countryId)
{
$this->countryId = $countryId;
}

public function getEndpoint(): string
Expand Down
5 changes: 1 addition & 4 deletions src/Request/GetAllSitesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ class GetAllSitesRequest extends Request
private const ENDPOINT = '/location/site/csv';
private const HTTP_METHOD = 'POST';

private ?int $countryId;

public function __construct(?int $countryId = null)
public function __construct(public readonly ?int $countryId = null)
{
$this->countryId = $countryId;
}

public function getEndpoint(): string
Expand Down
Loading
Loading