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

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,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
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,20 @@ use Answear\LuigisBoxBundle\Exception\ServiceUnavailableException;
try {
// ... request
} catch (BadRequestException $e){
} catch (BadRequestException $exception){
//bad request
$request = $e->getRequest();
$response = $e->getResponse();
} catch (TooManyItemsException $e){
$request = $exception->request;
$response = $exception->response;
} catch (TooManyItemsException $exception){
//items limit reached
$limit = $e->getLimit();
} catch (MalformedResponseException $e){
$limit = $exception->limit;
} catch (MalformedResponseException $exception){
//bad response
$response = $e->getResponse();
} catch (TooManyRequestsException $e){
$response = $exception->response;
} catch (TooManyRequestsException $exception){
//repeat request after $retryAfter seconds
$retryAfter = $e->getRetryAfterSeconds();
} catch (ServiceUnavailableException $e){
$retryAfter = $exception->retryAfterSeconds;
} catch (ServiceUnavailableException $exception){
//delay request
}
```
Expand Down
29 changes: 14 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,24 @@
"type": "symfony-bundle",
"license": "MIT",
"require": {
"php": ">=7.4|^8.0",
"php": "^8.2",
"ext-json": "*",
"marc-mabe/php-enum": "^3.0|^4.3",
"webmozart/assert": "^1.3",
"symfony/validator": "^5.4|^6.0",
"symfony/http-kernel": "^5.4|^6.0",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"symfony/serializer": "^5.4|^6.0",
"symfony/property-access": "^5.4|^6.0"
"webmozart/assert": "^1.11",
"symfony/validator": "^6.0|^7.0",
"symfony/http-kernel": "^6.0|^7.0",
"guzzlehttp/guzzle": "^6.0|^7.0",
"symfony/serializer": "^6.0|^7.0",
"symfony/property-access": "^6.0|^7.0"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"phpunit/phpunit": "^9.5.23",
"symfony/phpunit-bridge": "6.1.*",
"phpro/grumphp": "1.13.x",
"friendsofphp/php-cs-fixer": "^3.9.5",
"phpstan/phpstan": "^1.10.34",
"phpstan/phpstan-webmozart-assert": "^1.2.4",
"matthiasnoback/symfony-config-test": "^4.3"
"phpunit/phpunit": "^10.5",
"symfony/phpunit-bridge": "^6.1|^7.0",
"phpro/grumphp": "^2.8",
"friendsofphp/php-cs-fixer": "^3.64",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-webmozart-assert": "^1.2",
"matthiasnoback/symfony-config-test": "^5.2"
},
"autoload": {
"psr-4": {
Expand Down
15 changes: 3 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
<?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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use vendor/phpunit/phpunit/phpunit.xsd instead

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"/>
</php>

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

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
98 changes: 11 additions & 87 deletions src/LuigisBoxBundle/DTO/ConfigDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,100 +5,24 @@
namespace Answear\LuigisBoxBundle\DTO;

use Answear\LuigisBoxBundle\DependencyInjection\Configuration;
use Webmozart\Assert\Assert;

class ConfigDTO
readonly class ConfigDTO
{
private const MAX_SEARCH_CACHE_TTL = 300;

/**
* @var string
*/
private $host;

/**
* @var string
*/
private $publicKey;

/**
* @var string
*/
private $privateKey;

/**
* @var float
*/
private $connectionTimeout;

/**
* @var float
*/
private $requestTimeout;

/**
* @var float
*/
private $searchTimeout;

/**
* @var int
*/
private $searchCacheTtl;
public int $searchCacheTtl;

public function __construct(
string $publicKey,
string $privateKey,
string $host = Configuration::HOST,
float $connectionTimeout = Configuration::CONNECTION_TIMEOUT,
float $requestTimeout = Configuration::REQUEST_TIMEOUT,
float $searchTimeout = Configuration::SEARCH_TIMEOUT,
int $searchCacheTtl = Configuration::SEARCH_CACHE_TIMEOUT
public string $publicKey,
public string $privateKey,
public string $host = Configuration::HOST,
public float $connectionTimeout = Configuration::CONNECTION_TIMEOUT,
public float $requestTimeout = Configuration::REQUEST_TIMEOUT,
public float $searchTimeout = Configuration::SEARCH_TIMEOUT,
int $searchCacheTtl = Configuration::SEARCH_CACHE_TIMEOUT,
) {
if ($searchCacheTtl < 0) {
throw new \InvalidArgumentException('searchCacheTtl cannot be negative.');
}

$this->host = $host;
$this->publicKey = $publicKey;
$this->privateKey = $privateKey;
$this->connectionTimeout = $connectionTimeout;
$this->requestTimeout = $requestTimeout;
$this->searchTimeout = $searchTimeout;
Assert::greaterThanEq($searchCacheTtl, 0, 'searchCacheTtl cannot be negative.');
$this->searchCacheTtl = min($searchCacheTtl, self::MAX_SEARCH_CACHE_TTL);
}

public function getHost(): string
{
return $this->host;
}

public function getPublicKey(): string
{
return $this->publicKey;
}

public function getPrivateKey(): string
{
return $this->privateKey;
}

public function getConnectionTimeout(): float
{
return $this->connectionTimeout;
}

public function getRequestTimeout(): float
{
return $this->requestTimeout;
}

public function getSearchTimeout(): float
{
return $this->searchTimeout;
}

public function getSearchCacheTtl(): int
{
return $this->searchCacheTtl;
}
}
16 changes: 3 additions & 13 deletions src/LuigisBoxBundle/Exception/ApiErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,10 @@

class ApiErrorException extends \RuntimeException
{
/**
* @var Request
*/
private $request;

public function __construct(string $message, Request $request)
public function __construct(
string $message,
public readonly Request $request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format

{
parent::__construct($message);

$this->request = $request;
}

public function getRequest(): Request
{
return $this->request;
}
}
29 changes: 4 additions & 25 deletions src/LuigisBoxBundle/Exception/BadRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,10 @@

class BadRequestException extends \RuntimeException
{
/**
* @var ResponseInterface
*/
private $response;

/**
* @var Request
*/
private $request;

public function __construct(ResponseInterface $response, Request $request)
{
public function __construct(
public readonly ResponseInterface $response,
public readonly Request $request,
) {
parent::__construct('Bad request.');

$this->response = $response;
$this->request = $request;
}

public function getResponse(): ResponseInterface
{
return $this->response;
}

public function getRequest(): Request
{
return $this->request;
}
}
29 changes: 5 additions & 24 deletions src/LuigisBoxBundle/Exception/MalformedResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,12 @@

class MalformedResponseException extends \RuntimeException
{
/**
* @var ResponseInterface
*/
private $response;

/**
* @var Request
*/
private $request;

public function __construct(string $message, ResponseInterface $response, Request $request, ?\Throwable $previous = null)
public function __construct(
string $message,
public readonly ResponseInterface $response,
public readonly Request $request,
?\Throwable $previous = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format

{
parent::__construct($message, 0, $previous);

$this->response = $response;
$this->request = $request;
}

public function getResponse(): ResponseInterface
{
return $this->response;
}

public function getRequest(): Request
{
return $this->request;
}
}
Loading
Loading