Skip to content

Commit

Permalink
Support symfony 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiktor6 committed Oct 1, 2024
1 parent 38fda42 commit 4ac81d1
Show file tree
Hide file tree
Showing 33 changed files with 188 additions and 423 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +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"
uses: "actions/checkout@v2"
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 @@ -20,7 +20,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
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
"type": "symfony-bundle",
"license": "MIT",
"require": {
"php": ">=7.4|^8.0",
"php": "^8.2",
"ext-json": "*",
"webmozart/assert": "^1.3",
"webmozart/assert": "^1.11",
"guzzlehttp/guzzle": "^6.0|^7.0",
"symfony/http-kernel": "^5.4|^6.0"
"symfony/http-kernel": "^6.0|^7.0"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"phpunit/phpunit": "^9.5",
"symfony/phpunit-bridge": "6.1.*",
"phpro/grumphp": "^1.5.0",
"friendsofphp/php-cs-fixer": "^3.4",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-webmozart-assert": "^1.0"
"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"
},
"autoload": {
"psr-4": {
Expand Down
17 changes: 4 additions & 13 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"
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"/>
<ini name="error_reporting" value="1"/>
</php>

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

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</phpunit>
19 changes: 5 additions & 14 deletions src/Exception/MalformedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,11 @@

class MalformedResponse extends \RuntimeException
{
/**
* @var mixed
*/
private $response;

public function __construct($message, $response, ?\Throwable $previous = null)
{
public function __construct(
$message,
public readonly mixed $response,
?\Throwable $previous = null,
) {
parent::__construct($message, 0, $previous);

$this->response = $response;
}

public function getResponse()
{
return $this->response;
}
}
10 changes: 4 additions & 6 deletions src/Request/DetectAndFeaturesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@

namespace Answear\WideEyesBundle\Request;

class DetectAndFeaturesRequest implements Request
readonly class DetectAndFeaturesRequest implements Request
{
private string $image;

public function __construct(string $image)
public function __construct(private string $image)
{
$this->image = $image;
}

public function toJson(): string
{
return json_encode(
[
'image' => $this->image,
]
],
JSON_THROW_ON_ERROR
);
}
}
16 changes: 7 additions & 9 deletions src/Request/GetSimilarRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

namespace Answear\WideEyesBundle\Request;

class GetSimilarRequest implements Request
readonly class GetSimilarRequest implements Request
{
private string $uid;
private string $country;

public function __construct(string $uid, string $country)
{
$this->uid = $uid;
$this->country = $country;
public function __construct(
private string $uid,
private string $country,
) {
}

public function toJson(): string
Expand All @@ -21,7 +18,8 @@ public function toJson(): string
[
'uid' => $this->uid,
'country' => $this->country,
]
],
JSON_THROW_ON_ERROR
);
}
}
25 changes: 10 additions & 15 deletions src/Request/SearchByFeatureRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@

namespace Answear\WideEyesBundle\Request;

class SearchByFeatureRequest implements Request
readonly class SearchByFeatureRequest implements Request
{
private string $featureId;
private string $label;
private ?string $gender;
private ?string $filters;
private ?int $maxNumResults;

public function __construct(string $featureId, string $label, ?string $gender = null, ?string $filters = null, ?int $maxNumResults = null)
{
$this->featureId = $featureId;
$this->label = $label;
$this->gender = $gender;
$this->filters = $filters;
$this->maxNumResults = $maxNumResults;
public function __construct(
private string $featureId,
private string $label,
private ?string $gender = null,
private ?string $filters = null,
private ?int $maxNumResults = null,
) {
}

public function toJson(): string
Expand All @@ -32,7 +26,8 @@ public function toJson(): string
'filters' => $this->filters,
'maxNumResults' => $this->maxNumResults,
]
)
),
JSON_THROW_ON_ERROR
);
}
}
18 changes: 5 additions & 13 deletions src/Response/DetectAndFeaturesResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
use Answear\WideEyesBundle\ValueObject\Detection;
use Webmozart\Assert\Assert;

class DetectAndFeaturesResponse
readonly class DetectAndFeaturesResponse
{
/**
* @var Detection[]
* @param Detection[] $detections
*/
private array $detections;

private function __construct(array $detections)
private function __construct(public array $detections)
{
Assert::allIsInstanceOf($detections, Detection::class);
$this->detections = $detections;
}

public static function fromArray(array $response): DetectAndFeaturesResponse
Expand All @@ -34,13 +31,8 @@ static function ($item) {
$response['detections'],
)
);
} catch (\Throwable $e) {
throw new MalformedResponse($e->getMessage(), $response, $e);
} catch (\Throwable $throwable) {
throw new MalformedResponse($throwable->getMessage(), $response, $throwable);
}
}

public function getDetections(): array
{
return $this->detections;
}
}
17 changes: 6 additions & 11 deletions src/Response/GetSimilarResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Answear\WideEyesBundle\Exception\MalformedResponse;
use Webmozart\Assert\Assert;

class GetSimilarResponse
readonly class GetSimilarResponse
{
private array $uids;

private function __construct(array $uids)
/**
* @param string[] $uids
*/
private function __construct(public array $uids)
{
Assert::allString($uids);
$this->uids = $uids;
}

public static function fromArray(array $response, string $originalUid): GetSimilarResponse
Expand All @@ -33,17 +33,12 @@ static function ($item) {
array_values(
array_filter(
$responseUids,
static fn ($item) => $item !== $originalUid,
static fn($item) => $item !== $originalUid,
)
)
);
} catch (\Throwable $e) {
throw new MalformedResponse($e->getMessage(), $response, $e);
}
}

public function getUids(): array
{
return $this->uids;
}
}
15 changes: 5 additions & 10 deletions src/Response/SearchByFeatureResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Answear\WideEyesBundle\Exception\MalformedResponse;
use Webmozart\Assert\Assert;

class SearchByFeatureResponse
readonly class SearchByFeatureResponse
{
private array $uids;

private function __construct(array $uids)
/**
* @param string[] $uids
*/
private function __construct(public array $uids)
{
Assert::allString($uids);
$this->uids = $uids;
}

public static function fromArray(array $response): SearchByFeatureResponse
Expand All @@ -39,9 +39,4 @@ static function ($item) {
throw new MalformedResponse($e->getMessage(), $response, $e);
}
}

public function getUids(): array
{
return $this->uids;
}
}
17 changes: 7 additions & 10 deletions src/Service/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@

abstract class AbstractClient
{
protected ConfigProvider $configProvider;
protected ClientInterface $guzzle;

public function __construct(ConfigProvider $configProvider, ClientInterface $client)
{
$this->configProvider = $configProvider;
$this->guzzle = $client;
public function __construct(
protected ConfigProvider $configProvider,
protected ClientInterface $client,
) {
}

protected function request(string $endpoint, Request $request): array
{
try {
$response = $this->guzzle->request(
$response = $this->client->request(
'POST',
$endpoint,
[
Expand All @@ -51,7 +48,7 @@ protected function manyRequests(string $endpoint, array $requests): array
$promises = [];

foreach ($requests as $key => $request) {
$promises[$key] = $this->guzzle->requestAsync(
$promises[$key] = $this->client->requestAsync(
'POST',
$endpoint,
[
Expand All @@ -61,7 +58,7 @@ protected function manyRequests(string $endpoint, array $requests): array
);
}

$promisesResults = Promise\settle($promises)->wait();
$promisesResults = Promise\Utils::settle($promises)->wait();

$processedResults = [];
foreach ($promisesResults as $key => $result) {
Expand Down
Loading

0 comments on commit 4ac81d1

Please sign in to comment.