From f5d39c56e6209cb745188dc2bda0d4b40a4357a1 Mon Sep 17 00:00:00 2001 From: Tlapi Date: Thu, 29 Aug 2024 15:07:48 +0200 Subject: [PATCH] switch to php enums --- composer.json | 2 +- src/Client.php | 36 ++++++++++++++++++------------------ src/Http/HttpCurlBuilder.php | 2 +- src/Http/ResponseFactory.php | 2 +- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index b14e272..19b1354 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "MIT" ], "require": { - "php": "^8.1", + "php": "^8.2", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", diff --git a/src/Client.php b/src/Client.php index 9744b81..62a9ea3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -40,7 +40,7 @@ public function isAllowedChangesApi(): bool { return $this->httpClient->request( $this->queryBuilder->createChangesStatusUrl(), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -52,7 +52,7 @@ public function getChangesApiForEvidence(string $evidenceName): Response { return $this->httpClient->request( $this->queryBuilder->createChangesUrl(['evidence' => $evidenceName]), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -64,7 +64,7 @@ public function getPropertiesForEvidence(): Response { return $this->httpClient->request( $this->queryBuilder->createUri('properties', []), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -76,7 +76,7 @@ public function getAllApiChanges(?string $fromVersion): Response { return $this->httpClient->request( $this->queryBuilder->createChangesUrl(['start' => $fromVersion]), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -88,7 +88,7 @@ public function getCompanies(): Response { return $this->httpClient->request( $this->queryBuilder->createCompanyUrl(), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -125,7 +125,7 @@ public function getAuthAndRefreshToken(): Response { return $this->httpClient->request( $this->queryBuilder->createAuthTokenUrl(), - Method::get(Method::POST), + Method::POST, [], [ 'username' => $this->config->getUser(), @@ -144,7 +144,7 @@ public function deleteById(int $id, bool $dryRun = false): Response return $this->httpClient->request( $this->queryBuilder->createUri($id, $uriParameters), - Method::get(Method::DELETE), + Method::DELETE, [], [], [], @@ -157,7 +157,7 @@ public function deleteByCode(string $id, bool $dryRun = false): void $uriParameters = $dryRun ? ['dry-run' => 'true'] : []; $this->httpClient->request( $this->queryBuilder->createUri(sprintf('code:%s', $id), $uriParameters), - Method::get(Method::DELETE), + Method::DELETE, [], [], [], @@ -199,7 +199,7 @@ public function getByCode(string $code, array $uriParameters = []): EvidenceResu return $this->responseHydrator->convertResponseToEvidenceResult( $this->httpClient->request( $this->queryBuilder->createUriByCodeOnly($code, $uriParameters), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -224,7 +224,7 @@ public function getById(int $id, array $uriParameters = []): EvidenceResult return $this->responseHydrator->convertResponseToEvidenceResult( $this->httpClient->request( $this->queryBuilder->createUri($id, $uriParameters), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -276,7 +276,7 @@ public function save(array $evidenceData, ?int $id, bool $dryRun = false, array ? array_merge($uriParameters, ['dry-run' => 'true']) : $uriParameters; /** @var \EcomailFlexibee\Result\EvidenceResult $response */ - $response = $this->callRequest(Method::get(Method::PUT), null, $uriParameters, $postData, [])[0]; + $response = $this->callRequest(Method::PUT, null, $uriParameters, $postData, [])[0]; $data = $response->getData(); if ( @@ -345,7 +345,7 @@ public function allInEvidence(): array { $response = $this->httpClient->request( $this->queryBuilder->createUriByEvidenceOnly(['limit' => 0]), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -359,7 +359,7 @@ public function countInEvidence(): int { $response = $this->httpClient->request( $this->queryBuilder->createUriByEvidenceOnly(['add-row-count' => 'true']), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -382,7 +382,7 @@ public function chunkInEvidence(int $start, int $limit): array { $response = $this->httpClient->request( $this->queryBuilder->createUriByEvidenceOnly(['limit' => $limit, 'start' => $start]), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -406,7 +406,7 @@ public function searchInEvidence(string $query, array $uriParameters): array { $response = $this->httpClient->request( $this->queryBuilder->createFilterQuery($query, $uriParameters), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -431,7 +431,7 @@ public function searchInEvidencePaginated(string $query, array $uriParameters): $uriParameters = array_merge($uriParameters, ['add-row-count' => 'true']); $response = $this->httpClient->request( $this->queryBuilder->createFilterQuery($query, $uriParameters), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -480,7 +480,7 @@ public function getPdfById(int $id, array $uriParameters): Response { return $this->httpClient->request( $this->queryBuilder->createPdfUrl($id, $uriParameters), - Method::get(Method::GET), + Method::GET, [], [], [], @@ -494,7 +494,7 @@ public function findLastInEvidence(bool $fullDetail): Response $this->queryBuilder->createUriByEvidenceOnly( ['order' => 'id', 'limit' => 1, 'detail' => $fullDetail ? 'full' : 'summary'], ), - Method::get(Method::GET), + Method::GET, [], [], [], diff --git a/src/Http/HttpCurlBuilder.php b/src/Http/HttpCurlBuilder.php index c232014..5b33178 100644 --- a/src/Http/HttpCurlBuilder.php +++ b/src/Http/HttpCurlBuilder.php @@ -47,7 +47,7 @@ public function build(string $url, Method $httpMethod, array $postFields, array } curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod->getValue()); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod->value); curl_setopt($ch, CURLOPT_USERAGENT, 'Ecomail.cz Flexibee client (https://github.com/Ecomailcz/flexibee-client)'); $verifySSLCertificate = $config->verifySSLCertificate() && $config->getAuthSessionId() === null; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSLCertificate); diff --git a/src/Http/ResponseFactory.php b/src/Http/ResponseFactory.php index 6840cc7..61b4e8f 100644 --- a/src/Http/ResponseFactory.php +++ b/src/Http/ResponseFactory.php @@ -40,7 +40,7 @@ public static function createFromOutput(string $url, Method $httpMethod, ?string } // Backup content - if ($httpMethod->equalsValue(Method::GET) && mb_stripos($url, '/backup') !== false) { + if ($httpMethod === Method::GET && mb_stripos($url, '/backup') !== false) { return new FlexibeeBackupResponse($responseContent); }