Skip to content

Commit

Permalink
Merge pull request #18 from answear/support-symfony-7
Browse files Browse the repository at this point in the history
Support symfony 7
  • Loading branch information
Wiktor6 authored Oct 2, 2024
2 parents 5dd10b9 + 7ff467b commit f842b2b
Show file tree
Hide file tree
Showing 28 changed files with 179 additions and 313 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
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.4",
"symfony/property-access": "5.4 - 6.4",
"symfony/property-info": "5.4 - 6.4",
"symfony/serializer": "5.4 - 6.4",
"webmozart/assert": "^1.3"
"guzzlehttp/guzzle": "^6.0|^7.0",
"psr/log": "^1.1",
"symfony/http-kernel": "^6.4|^7.0",
"symfony/property-access": "^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.4",
"matthiasnoback/symfony-config-test": "^4.2",
"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.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 OverseasBundle Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
12 changes: 3 additions & 9 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ class Client
private const CONNECTION_TIMEOUT = 10;
private const TIMEOUT = 30;

private ClientInterface $client;
private RequestTransformer $transformer;
private OverseasLogger $overseasLogger;

public function __construct(
RequestTransformer $transformer,
OverseasLogger $overseasLogger,
?ClientInterface $client = null
private RequestTransformer $transformer,
private OverseasLogger $overseasLogger,
private ?ClientInterface $client = null,
) {
$this->transformer = $transformer;
$this->overseasLogger = $overseasLogger;
$this->client = $client ?? new \GuzzleHttp\Client(['timeout' => self::TIMEOUT, 'connect_timeout' => self::CONNECTION_TIMEOUT]);
}

Expand Down
11 changes: 3 additions & 8 deletions src/Client/RequestTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,16 @@

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

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

public function transform(RequestInterface $request): HttpRequest
{
$uri = $this->configuration->getUrl() . $request->getEndpoint()
. '?apiKey=' . $this->configuration->getApiKey();
. '?apiKey=' . $this->configuration->apiKey;

if (null !== $request->getUrlQuery()) {
$uri .= '&' . $request->getUrlQuery();
Expand Down
17 changes: 6 additions & 11 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,21 @@ class ConfigProvider
private const TEST_URL = 'https://apitest.overseas.hr/';

private EnvironmentEnum $environment;
private string $apiKey;

public function __construct(string $environment, string $apiKey)
{
$this->environment = EnvironmentEnum::get($environment);
$this->apiKey = $apiKey;
public function __construct(
string $environment,
public string $apiKey,
) {
$this->environment = EnvironmentEnum::from($environment);
}

public function getUrl(): string
{
return EnvironmentEnum::prod()->is($this->environment) ? self::URL : self::TEST_URL;
return EnvironmentEnum::Prod === $this->environment ? self::URL : self::TEST_URL;
}

public function getEnvironment(): EnvironmentEnum
{
return $this->environment;
}

public function getApiKey(): string
{
return $this->apiKey;
}
}
83 changes: 24 additions & 59 deletions src/Enum/DayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,30 @@

namespace Answear\OverseasBundle\Enum;

use MabeEnum\Enum;
use MabeEnum\EnumSerializableTrait;

class DayType extends Enum implements \Serializable
enum DayType: int
{
use EnumSerializableTrait;

public const WORKING_DAY = 1;
public const MONDAY = 7;
public const TUESDAY = 8;
public const WEDNESDAY = 9;
public const THURSDAY = 10;
public const FRIDAY = 11;
public const SATURDAY = 2;
public const SATURDAY_2 = 12;
public const SUNDAY = 3;

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

public static function workingDay(): self
{
return static::get(static::WORKING_DAY);
}

public static function saturday2(): self
{
return static::get(static::SATURDAY_2);
case WorkingDay = 1;
case Monday = 7;
case Tuesday = 8;
case Wednesday = 9;
case Thursday = 10;
case Friday = 11;
case Saturday = 2;
case Saturday2 = 12;
case Sunday = 3;

public function getOrdinal(): int
{
return match ($this) {
self::WorkingDay => 1,
self::Monday => 2,
self::Tuesday => 3,
self::Wednesday => 4,
self::Thursday => 5,
self::Friday => 6,
self::Saturday => 7,
self::Saturday2 => 8,
self::Sunday => 9,
};
}
}
26 changes: 11 additions & 15 deletions src/Enum/EnvironmentEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@

namespace Answear\OverseasBundle\Enum;

use MabeEnum\Enum;
use MabeEnum\EnumSerializableTrait;

class EnvironmentEnum extends Enum implements \Serializable
enum EnvironmentEnum: string
{
use EnumSerializableTrait;

public const PROD = 'prod';
public const TEST = 'test';

public static function prod(): self
{
return static::get(static::PROD);
}
case Prod = 'prod';
case Test = 'test';

public static function test(): self
/**
* @return string[]
*/
public static function getValues(): array
{
return static::get(static::TEST);
return [
self::Prod->value,
self::Test->value,
];
}
}
28 changes: 4 additions & 24 deletions src/Enum/StatusResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,9 @@

namespace Answear\OverseasBundle\Enum;

use MabeEnum\Enum;
use MabeEnum\EnumSerializableTrait;

class StatusResult extends Enum implements \Serializable
enum StatusResult: int
{
use EnumSerializableTrait;

public const OK = 0;
public const ERROR = 1;
public const VALIDATION_FAILED = 2;

public static function validationFailed(): self
{
return static::get(static::VALIDATION_FAILED);
}

public static function error(): self
{
return static::get(static::ERROR);
}

public static function ok(): self
{
return static::get(static::OK);
}
case Ok = 0;
case Error = 1;
case ValidationFailed = 2;
}
18 changes: 6 additions & 12 deletions src/Exception/BadRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@

class BadRequestException extends \RuntimeException
{
private ResponseInterface $response;

public function __construct(ResponseInterface $response, ?\Throwable $previous = null)
{
public function __construct(
public readonly ResponseInterface $response,
?\Throwable $previous = null,
) {
$message = 'Error occurs.';
if ($response->getStatus()->is(StatusResult::validationFailed())) {
if (StatusResult::ValidationFailed === $response->getStatus()) {
$message = 'Validation failed.';
}
parent::__construct($message, 0, $previous);

$this->response = $response;
}

public function getResponse(): ResponseInterface
{
return $this->response;
parent::__construct($message, 0, $previous);
}
}
Loading

0 comments on commit f842b2b

Please sign in to comment.