diff --git a/README.md b/README.md index 11263a4..5f6f2c2 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ $evidenceData['nazev'] = 'První kontaktní adresa' $evidenceItemId = $client->save($evidenceData, null, $dryRun, $uriParameters); ``` Pokud vše proběhne v pořádku, vratí se třída `\EcomailFlexibee\Http\Response\Response:class` s daty ze systému Flexibee. Nastane-li chyba, vyhodí se výjimka -`EcomailFlexibeeRequestError::class`. Pro editaci záznamu stačí vyplnit druhý parametr `$id`. +`EcomailFlexibeeRequestFail::class`. Pro editaci záznamu stačí vyplnit druhý parametr `$id`. ## Vrácení záznamu dle parametrů Nalezení záznamu dle id s vyhozením výjimky, pokud záznam neexistuje diff --git a/ruleset.xml b/ruleset.xml index 22aed67..d622c40 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,12 +1,15 @@ - + - + + + /resources + @@ -20,7 +23,11 @@ - + + + + + @@ -110,6 +117,7 @@ + @@ -126,8 +134,6 @@ - - @@ -139,28 +145,35 @@ - + + + - + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/src/Client.php b/src/Client.php index 0e1e01c..939af77 100644 --- a/src/Client.php +++ b/src/Client.php @@ -11,15 +11,20 @@ use EcomailFlexibee\Http\ResponseHydrator; use EcomailFlexibee\Http\UrlBuilder; use EcomailFlexibee\Result\EvidenceResult; +use function array_filter; +use function array_merge; +use function count; +use function mb_strtolower; +use function sprintf; class Client { - protected \EcomailFlexibee\Http\UrlBuilder $queryBuilder; - protected \EcomailFlexibee\Http\HttpClient $httpClient; - protected \EcomailFlexibee\Config $config; + protected UrlBuilder $queryBuilder; + protected HttpClient $httpClient; + protected Config $config; - private \EcomailFlexibee\Http\ResponseHydrator $responseHydrator; + private ResponseHydrator $responseHydrator; public function __construct( string $url, @@ -112,7 +117,10 @@ public function getCompanies(): Response */ public function getCompany(): array { - $result = \array_filter($this->getCompanies()->getData()['companies'], fn (array $data): bool => \mb_strtolower($data['dbNazev']) === \mb_strtolower($this->config->getCompany())); + $result = array_filter( + $this->getCompanies()->getData()['companies'], + fn (array $data): bool => mb_strtolower($data['dbNazev']) === mb_strtolower($this->config->getCompany()), + ); if (isset($result['company'])) { return $result['company']; @@ -164,7 +172,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), + $this->queryBuilder->createUri(sprintf('code:%s', $id), $uriParameters), Method::get(Method::DELETE), [], [], @@ -175,12 +183,12 @@ public function deleteByCode(string $id, bool $dryRun = false): void /** * @param array $uriParameters - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ public function findById(int $id, array $uriParameters = []): EvidenceResult { @@ -193,14 +201,14 @@ public function findById(int $id, array $uriParameters = []): EvidenceResult /** * @param array $uriParameters - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidRequestParameter * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNoEvidenceResult * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ public function getByCode(string $code, array $uriParameters = []): EvidenceResult { @@ -219,13 +227,13 @@ public function getByCode(string $code, array $uriParameters = []): EvidenceResu /** * @param array $uriParameters - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNoEvidenceResult * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ public function getById(int $id, array $uriParameters = []): EvidenceResult { @@ -244,13 +252,13 @@ public function getById(int $id, array $uriParameters = []): EvidenceResult /** * @param array $uriParameters - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidRequestParameter * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ public function findByCode(string $code, array $uriParameters = []): EvidenceResult { @@ -264,12 +272,12 @@ public function findByCode(string $code, array $uriParameters = []): EvidenceRes /** * @param array $evidenceData * @param array $uriParameters - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeSaveFailed */ public function save(array $evidenceData, ?int $id, bool $dryRun = false, array $uriParameters = []): FlexibeeResponse @@ -281,14 +289,19 @@ public function save(array $evidenceData, ?int $id, bool $dryRun = false, array $postData = []; $postData[$this->config->getEvidence()] = $evidenceData; $uriParameters = $dryRun - ? \array_merge($uriParameters, ['dry-run' => 'true']) + ? array_merge($uriParameters, ['dry-run' => 'true']) : $uriParameters; /** @var \EcomailFlexibee\Result\EvidenceResult $response */ $response = $this->callRequest(Method::get(Method::PUT), null, $uriParameters, $postData, [])[0]; $data = $response->getData(); - if (isset($data['created']) && (int) $data['created'] === 0 && isset($data['updated']) && (int) $data['updated'] === 0) { - $errorMessage = \sprintf('(%d) %s', $data['status_code'], $data['message']); + if ( + isset($data['created']) + && (int) $data['created'] === 0 + && isset($data['updated']) + && (int) $data['updated'] === 0 + ) { + $errorMessage = sprintf('(%d) %s', $data['status_code'], $data['message']); throw new EcomailFlexibeeSaveFailed($errorMessage); } @@ -302,7 +315,7 @@ public function save(array $evidenceData, ?int $id, bool $dryRun = false, array null, true, null, - \count($data), + count($data), null, $response->getData(), [], @@ -327,7 +340,7 @@ public function addUserRelation(int $objectAId, int $objectBId, float $price, in 'cena' => $price, 'popis' => $description, 'evidenceType' => $this->config->getEvidence(), - 'object' => \sprintf('code:%s', $objectBData['kod']), + 'object' => sprintf('code:%s', $objectBData['kod']), ], ], ]; @@ -337,12 +350,12 @@ public function addUserRelation(int $objectAId, int $objectBId, float $price, in /** * @return array - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ public function allInEvidence(): array { @@ -374,12 +387,12 @@ public function countInEvidence(): int /** * @return array<\EcomailFlexibee\Result\EvidenceResult> - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ public function chunkInEvidence(int $start, int $limit): array { @@ -398,12 +411,12 @@ public function chunkInEvidence(int $start, int $limit): array /** * @param array $uriParameters * @return array<\EcomailFlexibee\Result\EvidenceResult> - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ public function searchInEvidence(string $query, array $uriParameters): array { @@ -425,12 +438,12 @@ public function searchInEvidence(string $query, array $uriParameters): array * @param array $postFields * @param array $headers * @return array<\EcomailFlexibee\Result\EvidenceResult> - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ public function callRequest(Method $httpMethod, $queryFilterOrId, array $uriParameters, array $postFields, array $headers): array { @@ -448,12 +461,12 @@ public function callRequest(Method $httpMethod, $queryFilterOrId, array $uriPara /** * @param array $uriParameters - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ public function getPdfById(int $id, array $uriParameters): Response { diff --git a/src/Enum/SearchQueryOperator.php b/src/Enum/SearchQueryOperator.php index 52d12ce..a802945 100644 --- a/src/Enum/SearchQueryOperator.php +++ b/src/Enum/SearchQueryOperator.php @@ -3,6 +3,14 @@ namespace EcomailFlexibee\Enum; use Consistence\Enum\Enum; +use function array_keys; +use function array_values; +use function implode; +use function preg_match_all; +use function preg_replace; +use function preg_split; +use function str_replace; +use function urldecode; class SearchQueryOperator extends Enum { @@ -23,24 +31,24 @@ class SearchQueryOperator extends Enum public static function convertOperatorsInQuery(string $query): string { - $query = \urldecode($query); + $query = urldecode($query); /** @var array $queryExploded */ - $queryExploded = \preg_split('/\s+/', $query); + $queryExploded = preg_split('/\s+/', $query); foreach($queryExploded as &$part) { $toReplace = []; - \preg_match_all('/[^\'](?=(?:[^\']*\'[^"]*\'[^\']*|[^\'])*$)/', $part, $matches); + preg_match_all('/[^\'](?=(?:[^\']*\'[^"]*\'[^\']*|[^\'])*$)/', $part, $matches); if (isset($matches[0])) { - $text = \implode('', $matches[0]); - $toReplace[$text] = \str_replace(\array_keys(self::$operators), \array_values(self::$operators), $text); + $text = implode('', $matches[0]); + $toReplace[$text] = str_replace(array_keys(self::$operators), array_values(self::$operators), $text); } - $part = \str_replace(\array_keys($toReplace), \array_values($toReplace), $part); + $part = str_replace(array_keys($toReplace), array_values($toReplace), $part); } /** @var string $result */ - $result = \preg_replace('/\s+/', ' ', \implode(' ',$queryExploded)); + $result = preg_replace('/\s+/', ' ', implode(' ',$queryExploded)); return $result; } diff --git a/src/Exception/EcomailFlexibeeConnectionError.php b/src/Exception/EcomailFlexibeeConnectionFail.php similarity index 60% rename from src/Exception/EcomailFlexibeeConnectionError.php rename to src/Exception/EcomailFlexibeeConnectionFail.php index 711342a..2cc8cc0 100644 --- a/src/Exception/EcomailFlexibeeConnectionError.php +++ b/src/Exception/EcomailFlexibeeConnectionFail.php @@ -4,7 +4,7 @@ use Exception; -final class EcomailFlexibeeConnectionError extends Exception +final class EcomailFlexibeeConnectionFail extends Exception { } diff --git a/src/Exception/EcomailFlexibeeInvalidRequestParameter.php b/src/Exception/EcomailFlexibeeInvalidRequestParameter.php index 71669e8..b347dd6 100644 --- a/src/Exception/EcomailFlexibeeInvalidRequestParameter.php +++ b/src/Exception/EcomailFlexibeeInvalidRequestParameter.php @@ -5,13 +5,15 @@ use Exception; use Rakit\Validation\Validation; use Throwable; +use function implode; +use const PHP_EOL; final class EcomailFlexibeeInvalidRequestParameter extends Exception { public function __construct(Validation $validation, ?Throwable $previous = null) { - parent::__construct(\implode(\PHP_EOL,$validation->errors()->all()), 0, $previous); + parent::__construct(implode(PHP_EOL,$validation->errors()->all()), 0, $previous); } } diff --git a/src/Exception/EcomailFlexibeeRequestError.php b/src/Exception/EcomailFlexibeeRequestFail.php similarity index 61% rename from src/Exception/EcomailFlexibeeRequestError.php rename to src/Exception/EcomailFlexibeeRequestFail.php index f7a3321..2516bd6 100644 --- a/src/Exception/EcomailFlexibeeRequestError.php +++ b/src/Exception/EcomailFlexibeeRequestFail.php @@ -4,7 +4,7 @@ use Exception; -final class EcomailFlexibeeRequestError extends Exception +final class EcomailFlexibeeRequestFail extends Exception { } diff --git a/src/Http/HttpClient.php b/src/Http/HttpClient.php index 7c132e5..393688d 100644 --- a/src/Http/HttpClient.php +++ b/src/Http/HttpClient.php @@ -3,14 +3,30 @@ namespace EcomailFlexibee\Http; use EcomailFlexibee\Config; +use EcomailFlexibee\Http\Response\FlexibeeResponse; use League\Flysystem\Adapter\Local; use League\Flysystem\Filesystem; +use function basename; +use function curl_errno; +use function curl_error; +use function curl_exec; +use function curl_getinfo; +use function date; +use function dirname; +use function is_string; +use function mb_strlen; +use function microtime; +use function number_format; +use function sprintf; +use function trim; +use const CURLINFO_HTTP_CODE; +use const FILE_APPEND; final class HttpClient { - private \EcomailFlexibee\Http\UrlNormalizer $urlNormalizer; - private \EcomailFlexibee\Http\HttpCurlBuilder $httpCurlBuilder; + private UrlNormalizer $urlNormalizer; + private HttpCurlBuilder $httpCurlBuilder; public function __construct() { $this->urlNormalizer = new UrlNormalizer(); @@ -21,12 +37,12 @@ public function __construct() { * @param array $postFields * @param array $queryParameters * @param array $headers - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ public function request( string $url, @@ -35,7 +51,7 @@ public function request( array $queryParameters, array $headers, Config $config - ): \EcomailFlexibee\Http\Response\FlexibeeResponse + ): FlexibeeResponse { $ch = $this->httpCurlBuilder->build( @@ -47,34 +63,34 @@ public function request( $config, ); - $startTime = \microtime(true); - $output = \curl_exec($ch); - $responseTime = \microtime(true) - $startTime; - $output = \is_string($output) ? $output : null; - $errorMessage = \mb_strlen(\trim(\curl_error($ch))) === 0 + $startTime = microtime(true); + $output = curl_exec($ch); + $responseTime = microtime(true) - $startTime; + $output = is_string($output) ? $output : null; + $errorMessage = mb_strlen(trim(curl_error($ch))) === 0 ? null - : \curl_error($ch); - $statusCode = \curl_getinfo($ch, \CURLINFO_HTTP_CODE); + : curl_error($ch); + $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($config->getLogFilePath() !== null) { - $rootDir = \dirname($config->getLogFilePath()); - $fileSystem = new Filesystem(new Local($rootDir, \FILE_APPEND)); - $logContent = \sprintf( + $rootDir = dirname($config->getLogFilePath()); + $fileSystem = new Filesystem(new Local($rootDir, FILE_APPEND)); + $logContent = sprintf( '%s METHOD: %s URL:%s TIME:%s STATUS:%s', - \date('Y-m-d H:i:s'), + date('Y-m-d H:i:s'), $httpMethod->getValue(), $url, - \number_format($responseTime, 2), + number_format($responseTime, 2), $statusCode, ); if ($errorMessage !== null) { - $logContent = \sprintf('%s ERROR:%s', $logContent, $errorMessage); + $logContent = sprintf('%s ERROR:%s', $logContent, $errorMessage); } $logContent .= "\n"; $fileSystem->put( - \basename($config->getLogFilePath()), + basename($config->getLogFilePath()), $logContent, ); } @@ -84,7 +100,7 @@ public function request( $httpMethod, $output, $statusCode, - \curl_errno($ch), + curl_errno($ch), $errorMessage, ); } diff --git a/src/Http/HttpCurlBuilder.php b/src/Http/HttpCurlBuilder.php index 367774a..e649280 100644 --- a/src/Http/HttpCurlBuilder.php +++ b/src/Http/HttpCurlBuilder.php @@ -3,6 +3,23 @@ namespace EcomailFlexibee\Http; use EcomailFlexibee\Config; +use function count; +use function curl_init; +use function curl_setopt; +use function http_build_query; +use function json_encode; +use function sprintf; +use const CURLOPT_CUSTOMREQUEST; +use const CURLOPT_FOLLOWLOCATION; +use const CURLOPT_HTTPAUTH; +use const CURLOPT_HTTPHEADER; +use const CURLOPT_POSTFIELDS; +use const CURLOPT_RETURNTRANSFER; +use const CURLOPT_SSL_VERIFYHOST; +use const CURLOPT_SSL_VERIFYPEER; +use const CURLOPT_URL; +use const CURLOPT_USERAGENT; +use const CURLOPT_USERPWD; final class HttpCurlBuilder { @@ -16,37 +33,37 @@ final class HttpCurlBuilder public function build(string $url, Method $httpMethod, array $postFields, array $queryParameters, array $headers, Config $config) { /** @var resource $ch */ - $ch = \curl_init(); - \curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, TRUE); - \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, TRUE); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); if ($config->getAuthSessionId() !== null) { - \curl_setopt($ch, \CURLOPT_HTTPAUTH, FALSE); - $headers[] = \sprintf('X-authSessionId: %s', $config->getAuthSessionId()); + curl_setopt($ch, CURLOPT_HTTPAUTH, FALSE); + $headers[] = sprintf('X-authSessionId: %s', $config->getAuthSessionId()); } else { - \curl_setopt($ch, \CURLOPT_HTTPAUTH, TRUE); - \curl_setopt($ch, \CURLOPT_USERPWD, \sprintf('%s:%s', $config->getUser(), $config->getPassword())); + curl_setopt($ch, CURLOPT_HTTPAUTH, TRUE); + curl_setopt($ch, CURLOPT_USERPWD, sprintf('%s:%s', $config->getUser(), $config->getPassword())); } - \curl_setopt($ch, \CURLOPT_URL, $url); - \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, $httpMethod->getValue()); - \curl_setopt($ch, \CURLOPT_USERAGENT, 'Ecomail.cz Flexibee client (https://github.com/Ecomailcz/flexibee-client)'); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod->getValue()); + 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); - \curl_setopt($ch, \CURLOPT_SSL_VERIFYHOST, $verifySSLCertificate); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSLCertificate); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verifySSLCertificate); - if (\count($postFields) > 0) { - \curl_setopt($ch, \CURLOPT_POSTFIELDS, \json_encode([ + if (count($postFields) > 0) { + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ 'winstrom' => $postFields, ])); } - if (\count($queryParameters) > 0) { - \curl_setopt($ch, \CURLOPT_POSTFIELDS, \http_build_query($queryParameters)); + if (count($queryParameters) > 0) { + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($queryParameters)); } - if (\count($headers) !== 0) { - \curl_setopt($ch, \CURLOPT_HTTPHEADER, $headers); + if (count($headers) !== 0) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } return $ch; diff --git a/src/Http/ResponseFactory.php b/src/Http/ResponseFactory.php index 927a6f1..e6d11d2 100644 --- a/src/Http/ResponseFactory.php +++ b/src/Http/ResponseFactory.php @@ -2,15 +2,22 @@ namespace EcomailFlexibee\Http; -use EcomailFlexibee\Exception\EcomailFlexibeeConnectionError; +use EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail; use EcomailFlexibee\Exception\EcomailFlexibeeForbidden; use EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization; use EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed; use EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest; -use EcomailFlexibee\Exception\EcomailFlexibeeRequestError; +use EcomailFlexibee\Exception\EcomailFlexibeeRequestFail; use EcomailFlexibee\Http\Response\FlexibeeBackupResponse; use EcomailFlexibee\Http\Response\FlexibeePdfResponse; use EcomailFlexibee\Http\Response\FlexibeeResponse; +use function implode; +use function in_array; +use function json_decode; +use function mb_stripos; +use function mb_strpos; +use function sprintf; +use const CURLE_OK; final class ResponseFactory { @@ -25,25 +32,25 @@ public static function createFromOutput( ): FlexibeeResponse { if ($responseContent === null) { - throw new EcomailFlexibeeRequestError(); + throw new EcomailFlexibeeRequestFail(); } - if ($errorNumber !== \CURLE_OK && $errorMessage !== null) { - throw new EcomailFlexibeeConnectionError(\sprintf('cURL error (%s): %s', $errorNumber, $errorMessage)); + if ($errorNumber !== CURLE_OK && $errorMessage !== null) { + throw new EcomailFlexibeeConnectionFail(sprintf('cURL error (%s): %s', $errorNumber, $errorMessage)); } // PDF content - if (\mb_strpos($url, '.pdf') !== false) { + if (mb_strpos($url, '.pdf') !== false) { return new FlexibeePdfResponse($responseContent); } // Backup content - if ($httpMethod->equalsValue(Method::GET) && \mb_stripos($url, '/backup') !== false) { + if ($httpMethod->equalsValue(Method::GET) && mb_stripos($url, '/backup') !== false) { return new FlexibeeBackupResponse($responseContent); } /** @var array|null $data */ - $data = \json_decode($responseContent, true); + $data = json_decode($responseContent, true); $data ??= []; $data = $data['winstrom'] ?? $data; $results = $data['results'] ?? $data; @@ -84,7 +91,7 @@ public static function createFromOutput( if (isset($data['success'])) { $success = (isset($data['success']) && ($data['success'] === 'true' || $data['success'] === true)); unset($data['success']); - } elseif(\in_array($statusCode, [200, 201], true)) { + } elseif(in_array($statusCode, [200, 201], true)) { $success = true; } @@ -93,18 +100,22 @@ public static function createFromOutput( } if ($statusCode === 403) { - throw new EcomailFlexibeeForbidden('Uživatel na tuto operaci nemá oprávnění. Tato chyba se zobrazí i v případě, že danou operaci neumožňuje licence.'); + throw new EcomailFlexibeeForbidden( + 'Uživatel na tuto operaci nemá oprávnění. Tato chyba se zobrazí i v případě, že danou operaci neumožňuje licence.', + ); } if ($statusCode === 406) { - throw new EcomailFlexibeeNotAcceptableRequest('Cílový formát není nad konkrétním zdrojem podporovaný (např. export adresáře jako ISDOC).'); + throw new EcomailFlexibeeNotAcceptableRequest( + 'Cílový formát není nad konkrétním zdrojem podporovaný (např. export adresáře jako ISDOC).', + ); } if ($statusCode === 405) { throw new EcomailFlexibeeMethodNotAllowed(); } - if (\in_array($statusCode, [500, 400], true)) { + if (in_array($statusCode, [500, 400], true)) { foreach ($results as $resultData) { if (!isset($resultData['errors'])) { continue; @@ -113,7 +124,7 @@ public static function createFromOutput( self::throwErrorMessage($resultData['errors'], $statusCode); } - throw new EcomailFlexibeeRequestError($message); + throw new EcomailFlexibeeRequestFail($message); } return new FlexibeeResponse( @@ -130,7 +141,7 @@ public static function createFromOutput( /** * @param array $errors - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ private static function throwErrorMessage(array $errors, int $statusCode): void { @@ -138,22 +149,22 @@ private static function throwErrorMessage(array $errors, int $statusCode): void $messageLines = []; if (isset($error['code'])) { - $messageLines[] = \sprintf('code: %s',$error['code']); + $messageLines[] = sprintf('code: %s',$error['code']); } if (isset($error['for'])) { - $messageLines[] = \sprintf('for attribute: %s', $error['for']); + $messageLines[] = sprintf('for attribute: %s', $error['for']); } if (isset($error['path'])) { - $messageLines[] = \sprintf('path: %s',$error['path']); + $messageLines[] = sprintf('path: %s',$error['path']); } if (isset($error['message'])) { - $messageLines[] = \sprintf('message: %s', $error['message']); + $messageLines[] = sprintf('message: %s', $error['message']); } - throw new EcomailFlexibeeRequestError(\implode("\n", $messageLines), $statusCode); + throw new EcomailFlexibeeRequestFail(implode("\n", $messageLines), $statusCode); } } diff --git a/src/Http/ResponseHydrator.php b/src/Http/ResponseHydrator.php index c3611c9..f808d57 100644 --- a/src/Http/ResponseHydrator.php +++ b/src/Http/ResponseHydrator.php @@ -5,14 +5,16 @@ use Consistence\ObjectPrototype; use EcomailFlexibee\Config; use EcomailFlexibee\Exception\EcomailFlexibeeNoEvidenceResult; -use EcomailFlexibee\Exception\EcomailFlexibeeRequestError; +use EcomailFlexibee\Exception\EcomailFlexibeeRequestFail; use EcomailFlexibee\Http\Response\Response; use EcomailFlexibee\Result\EvidenceResult; +use function array_map; +use function count; class ResponseHydrator extends ObjectPrototype { - private \EcomailFlexibee\Config $config; + private Config $config; public function __construct(Config $config) { @@ -21,18 +23,18 @@ public function __construct(Config $config) /** * @return array<\EcomailFlexibee\Result\EvidenceResult> - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail */ public function convertResponseToEvidenceResults(Response $response): array { $data = $response->getData(); if (isset($data['success']) && $data['success'] === 'false') { - throw new EcomailFlexibeeRequestError($data['message']); + throw new EcomailFlexibeeRequestFail($data['message']); } if (!isset($data[$this->config->getEvidence()])) { - if (\count($data) === 0) { + if (count($data) === 0) { $data = $response->getStatistics(); $data['status_code'] = $response->getStatusCode(); $data['message'] = $response->getMessage(); @@ -43,7 +45,7 @@ public function convertResponseToEvidenceResults(Response $response): array return [new EvidenceResult($data)]; } - return \array_map(static fn (array $data) => new EvidenceResult($data), $data[$this->config->getEvidence()]); + return array_map(static fn (array $data) => new EvidenceResult($data), $data[$this->config->getEvidence()]); } public function convertResponseToEvidenceResult(Response $response, bool $throwException): EvidenceResult @@ -55,7 +57,7 @@ public function convertResponseToEvidenceResult(Response $response, bool $throwE throw new EcomailFlexibeeNoEvidenceResult(); } - return \count($data) !== 0 ? new EvidenceResult($data) : new EvidenceResult([]); + return count($data) !== 0 ? new EvidenceResult($data) : new EvidenceResult([]); } return new EvidenceResult($data[$this->config->getEvidence()]); diff --git a/src/Http/UrlBuilder.php b/src/Http/UrlBuilder.php index d30d24f..55635e7 100644 --- a/src/Http/UrlBuilder.php +++ b/src/Http/UrlBuilder.php @@ -9,6 +9,9 @@ use Purl\Path; use Purl\Query; use Purl\Url; +use function array_merge; +use function http_build_query; +use function sprintf; class UrlBuilder extends Url { @@ -17,7 +20,7 @@ class UrlBuilder extends Url private string $evidence; - private \EcomailFlexibee\Validator\ParameterValidator $validator; + private ParameterValidator $validator; public function __construct(Config $config, ?ParserInterface $parser = null) { @@ -59,21 +62,21 @@ public function createPdfUrl(int $id, array $uriParameters): string public function createBackupUrl(): string { - $this->setPath(new Path(\sprintf('/c/%s/backup', $this->company))); + $this->setPath(new Path(sprintf('/c/%s/backup', $this->company))); return $this->getUrl(); } public function createCompanyUrl(): string { - $this->setPath(new Path(\sprintf('/c/%s.json', $this->company))); + $this->setPath(new Path(sprintf('/c/%s.json', $this->company))); return $this->getUrl(); } public function createRestoreUrl(string $companyName): string { - $this->setPath(new Path(\sprintf('/c/%s/restore?name=%s', $this->company, $companyName))); + $this->setPath(new Path(sprintf('/c/%s/restore?name=%s', $this->company, $companyName))); return $this->getUrl(); } @@ -83,7 +86,7 @@ public function createRestoreUrl(string $companyName): string */ public function createChangesUrl(array $uriParameters = []): string { - $this->setPath(new Path(\sprintf('/c/%s/changes.json', $this->company))); + $this->setPath(new Path(sprintf('/c/%s/changes.json', $this->company))); $this->createQueryParams($uriParameters); return $this->getUrl(); @@ -91,7 +94,7 @@ public function createChangesUrl(array $uriParameters = []): string public function createChangesStatusUrl(): string { - $this->setPath(new Path(\sprintf('/c/%s/changes/status.json', $this->company))); + $this->setPath(new Path(sprintf('/c/%s/changes/status.json', $this->company))); return $this->getUrl(); } @@ -125,7 +128,7 @@ public function createFilterQuery(string $filterQuery, array $uriParameters): st public function createUriByCodeOnly(string $code, array $uriParameters): string { $this->validator->validateFlexibeeRequestCodeParameter($code); - $this->setPath($this->buildPathWithIdOrFilter(\sprintf('(kod eq \'%s\')', $code))); + $this->setPath($this->buildPathWithIdOrFilter(sprintf('(kod eq \'%s\')', $code))); $this->createQueryParams($uriParameters); return $this->getUrl(); @@ -162,12 +165,12 @@ public function createUri($filterQueryOrId, array $uriParams): string */ private function buildPathWithIdOrFilter($filterQueryOrId, string $format = 'json'): Path { - return new Path(\sprintf('c/%s/%s/%s.%s', $this->company, $this->evidence, $filterQueryOrId, $format)); + return new Path(sprintf('c/%s/%s/%s.%s', $this->company, $this->evidence, $filterQueryOrId, $format)); } private function buildPathForOnlyEvidence(): Path { - return new Path(\sprintf('c/%s/%s.json', $this->company, $this->evidence)); + return new Path(sprintf('c/%s/%s.json', $this->company, $this->evidence)); } /** @@ -175,8 +178,8 @@ private function buildPathForOnlyEvidence(): Path */ private function createQueryParams(array $parameters): void { - $parameters = \array_merge(['limit' => '0'], $parameters); - $this->setQuery(new Query(\http_build_query($parameters))); + $parameters = array_merge(['limit' => '0'], $parameters); + $this->setQuery(new Query(http_build_query($parameters))); } } diff --git a/src/Http/UrlNormalizer.php b/src/Http/UrlNormalizer.php index 6d2a4bf..27354ce 100644 --- a/src/Http/UrlNormalizer.php +++ b/src/Http/UrlNormalizer.php @@ -2,12 +2,14 @@ namespace EcomailFlexibee\Http; +use function urldecode; + final class UrlNormalizer { public function normalize(string $url): string { - return \urldecode($url); + return urldecode($url); } } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 4c4b6ab..ece9df6 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -5,25 +5,40 @@ use EcomailFlexibee\Client; use EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization; use EcomailFlexibee\Exception\EcomailFlexibeeNoEvidenceResult; -use EcomailFlexibee\Exception\EcomailFlexibeeRequestError; +use EcomailFlexibee\Exception\EcomailFlexibeeRequestFail; use EcomailFlexibee\Http\Method; use EcomailFlexibee\Result\EvidenceResult; use Faker\Factory; +use Faker\Generator; use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; +use function count; +use function file_exists; +use function file_get_contents; +use function mb_substr; +use function uniqid; +use function unlink; final class ClientTest extends TestCase { - private \EcomailFlexibee\Client $client; - private \Faker\Generator $faker; + private Client $client; + private Generator $faker; public function setUp(): void { parent::setUp(); $this->faker = Factory::create(); - $this->client = new Client(Config::HOST, Config::COMPANY, Config::USERNAME, Config::PASSWORD, Config::EVIDENCE, false, null); + $this->client = new Client( + Config::HOST, + Config::COMPANY, + Config::USERNAME, + Config::PASSWORD, + Config::EVIDENCE, + false, + null, + ); } public function testGetCompanies(): void @@ -31,7 +46,7 @@ public function testGetCompanies(): void /** @var array $companies */ $companies = $this->client->getCompanies()->getData(); Assert::assertArrayHasKey('companies', $companies); - Assert::assertTrue(\count($companies) > 0); + Assert::assertTrue(count($companies) > 0); } public function testGetCompany(): void @@ -60,7 +75,15 @@ public function testGetAuthTokenAndMakeSuccessCallWithSessionAuthId(): void Assert::assertArrayHasKey('refreshToken', $authToken); Assert::assertArrayHasKey('authSessionId', $authToken); Assert::assertArrayHasKey('csrfToken', $authToken); - $client = new Client(Config::HOST, Config::COMPANY, 'xxx', 'xxx', Config::EVIDENCE, false, $authToken['authSessionId']); + $client = new Client( + Config::HOST, + Config::COMPANY, + 'xxx', + 'xxx', + Config::EVIDENCE, + false, + $authToken['authSessionId'], + ); Assert::assertNotEmpty($client->allInEvidence()); } @@ -104,7 +127,7 @@ public function testCRUDForCustomIds(): void Assert::assertCount(1, $evidenceItem->getData()); Assert::assertEquals($id, (int) $evidenceItem->getData()[0]['id']); $evidenceItemFull = $this->client->getByCode($code, ['detail' => 'full']); - Assert::assertNotEquals(\count($evidenceItem->getData()[0]), \count($evidenceItemFull->getData()[0])); + Assert::assertNotEquals(count($evidenceItem->getData()[0]), count($evidenceItemFull->getData()[0])); $this->client->deleteByCode($code); Assert::assertCount(0, $this->client->findByCode($code)->getData()); } @@ -129,13 +152,13 @@ public function testEvidenceGetOnlyCustomFields(): void * @dataProvider getEvidences * @param array $evidenceData * @param array $expectedDataAfterUpdate - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeConnectionFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeForbidden * @throws \EcomailFlexibee\Exception\EcomailFlexibeeInvalidAuthorization * @throws \EcomailFlexibee\Exception\EcomailFlexibeeMethodNotAllowed * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNoEvidenceResult * @throws \EcomailFlexibee\Exception\EcomailFlexibeeNotAcceptableRequest - * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestError + * @throws \EcomailFlexibee\Exception\EcomailFlexibeeRequestFail * @throws \EcomailFlexibee\Exception\EcomailFlexibeeSaveFailed */ public function testCRUDOperations(string $evidence, array $evidenceData, array $expectedDataAfterUpdate): void @@ -150,12 +173,14 @@ public function testCRUDOperations(string $evidence, array $evidenceData, array } Assert::assertNotEmpty($client->getPdfById($addressBookId, [])); - Assert::assertNotEmpty($client->getPdfById($addressBookId, ['report-name' => 'FAKTURA-BLUE-FAV', 'report-lang' => 'en'])); + Assert::assertNotEmpty( + $client->getPdfById($addressBookId, ['report-name' => 'FAKTURA-BLUE-FAV', 'report-lang' => 'en']), + ); $client->deleteById($addressBookId); Assert::assertCount(0, $client->findById($addressBookId)->getData()); $this->expectException(EcomailFlexibeeNoEvidenceResult::class); $client->getById($addressBookId); - $this->expectException(EcomailFlexibeeRequestError::class); + $this->expectException(EcomailFlexibeeRequestFail::class); $evidenceData = []; $this->client->save($evidenceData, null); } @@ -166,7 +191,7 @@ public function testCRUDOperations(string $evidence, array $evidenceData, array public function getEvidences(): array { $faker = Factory::create(); - $code = \mb_substr($faker->uuid, 0, 20); + $code = mb_substr($faker->uuid, 0, 20); $name = $faker->userName; return [ @@ -198,7 +223,7 @@ public function getEvidences(): array public function testAllAndChunkInEvidence(): void { $result = $this->client->allInEvidence(); - Assert::assertTrue(\count($result) > 0); + Assert::assertTrue(count($result) > 0); $firstResult = $this->client->chunkInEvidence(0, 1); Assert::assertCount(1, $firstResult); @@ -210,23 +235,39 @@ public function testAllAndChunkInEvidence(): void public function testSearchInEvidence(): void { - $client = new Client(Config::HOST, Config::COMPANY, Config::USERNAME, Config::PASSWORD, 'faktura-vydana', false, null); + $client = new Client( + Config::HOST, + Config::COMPANY, + Config::USERNAME, + Config::PASSWORD, + 'faktura-vydana', + false, + null, + ); $result = $client->searchInEvidence('(kod neq \'JAN\')', []); - Assert::assertTrue(\count($result) > 0); - $this->expectException(EcomailFlexibeeRequestError::class); + Assert::assertTrue(count($result) > 0); + $this->expectException(EcomailFlexibeeRequestFail::class); $client->searchInEvidence('kod neq \'JAN\'', []); } public function testSearchInEvidenceWithInvalidUrl(): void { - $client = new Client(Config::HOST, Config::COMPANY, Config::USERNAME, Config::PASSWORD, 'faktura-vydana', false, null); - $this->expectException(EcomailFlexibeeRequestError::class); + $client = new Client( + Config::HOST, + Config::COMPANY, + Config::USERNAME, + Config::PASSWORD, + 'faktura-vydana', + false, + null, + ); + $this->expectException(EcomailFlexibeeRequestFail::class); $client->searchInEvidence(' bla.json', []); } public function testDryRunRequest(): void { - $response = $this->client->save(['kod' => \uniqid(), 'nazev' => 'SDSDXXXXX'], null, true); + $response = $this->client->save(['kod' => uniqid(), 'nazev' => 'SDSDXXXXX'], null, true); $firstItem = $response->getData()[0]; Assert::assertArrayHasKey('content', $firstItem); Assert::assertArrayHasKey(Config::EVIDENCE, $firstItem['content']); @@ -262,20 +303,20 @@ public function testRunBackendProcesses(): void public function testUnknownCompany(): void { $client = new Client(Config::HOST, 'xxx', Config::USERNAME, Config::PASSWORD, 'faktura-vydana', false); - $this->expectException(EcomailFlexibeeRequestError::class); + $this->expectException(EcomailFlexibeeRequestFail::class); $client->save([], null); } public function testCreateSameEvidenceRecord(): void { - $code = \uniqid(); + $code = uniqid(); $data = [ 'nazev' => $code, 'kod' => $code, ]; $this->client->save($data, null); - $this->expectException(EcomailFlexibeeRequestError::class); + $this->expectException(EcomailFlexibeeRequestFail::class); $this->expectExceptionCode(400); $this->client->save($data, null); } @@ -290,7 +331,7 @@ public function testGetPropertiesForEvidence(): void public function testLogRequest(): void { $logPath = 'logs/log.txt'; - @\unlink($logPath); + @unlink($logPath); $client = new Client( Config::HOST, Config::COMPANY, @@ -303,8 +344,8 @@ public function testLogRequest(): void ); $client->allInEvidence(); - Assert::assertTrue(\file_exists($logPath)); - Assert::assertNotEmpty(\file_get_contents($logPath)); + Assert::assertTrue(file_exists($logPath)); + Assert::assertNotEmpty(file_get_contents($logPath)); } private function checkResponseStructure(EvidenceResult $result): void diff --git a/tests/Http/QueryBuilderTest.php b/tests/Http/QueryBuilderTest.php index cabd61e..cd5821a 100644 --- a/tests/Http/QueryBuilderTest.php +++ b/tests/Http/QueryBuilderTest.php @@ -1,6 +1,6 @@ urlBuilder->createUriByCodeOnly('CODE:TEST', [])); - Assert::assertEquals('https://demo.flexibee.eu/c/demo/adresar/(kod%20eq%20\'CODE:TEST\').json?limit=0&test=1', $this->urlBuilder->createUriByCodeOnly('CODE:TEST', ['test' => true])); + Assert::assertEquals( + 'https://demo.flexibee.eu/c/demo/adresar/(kod%20eq%20\'CODE:TEST\').json?limit=0', + $this->urlBuilder->createUriByCodeOnly('CODE:TEST', []), + ); + Assert::assertEquals( + 'https://demo.flexibee.eu/c/demo/adresar/(kod%20eq%20\'CODE:TEST\').json?limit=0&test=1', + $this->urlBuilder->createUriByCodeOnly('CODE:TEST', ['test' => true]), + ); } public function testCreateUriByEvidenceOnly(): void { - Assert::assertEquals('https://demo.flexibee.eu/c/demo/adresar.json?limit=0', $this->urlBuilder->createUriByEvidenceOnly([])); + Assert::assertEquals( + 'https://demo.flexibee.eu/c/demo/adresar.json?limit=0', + $this->urlBuilder->createUriByEvidenceOnly([]), + ); } public function testCreateUriByCustomId(): void { - Assert::assertEquals('https://demo.flexibee.eu/c/demo/adresar/code:TEST.json?limit=0', $this->urlBuilder->createFilterQuery('code:TEST', [])); + Assert::assertEquals( + 'https://demo.flexibee.eu/c/demo/adresar/code:TEST.json?limit=0', + $this->urlBuilder->createFilterQuery('code:TEST', []), + ); } public function testCreateUriPdf(): void { - Assert::assertEquals('https://demo.flexibee.eu/c/demo/adresar/11.pdf?limit=0', $this->urlBuilder->createPdfUrl(11, [])); + Assert::assertEquals( + 'https://demo.flexibee.eu/c/demo/adresar/11.pdf?limit=0', + $this->urlBuilder->createPdfUrl(11, []), + ); $queryParams = []; $queryParams['report-name'] = 'test'; $queryParams['report-lang'] = 'en'; - Assert::assertEquals('https://demo.flexibee.eu/c/demo/adresar/11.pdf?limit=0&report-name=test&report-lang=en', $this->urlBuilder->createPdfUrl(11, $queryParams)); + Assert::assertEquals( + 'https://demo.flexibee.eu/c/demo/adresar/11.pdf?limit=0&report-name=test&report-lang=en', + $this->urlBuilder->createPdfUrl(11, $queryParams), + ); } public function testCreateUriByEvidenceForSearchQuery(): void { - Assert::assertEquals('https://demo.flexibee.eu/c/demo/adresar/1.json?limit=10000', $this->urlBuilder->createFilterQuery('1', ['limit' => 10000])); - Assert::assertEquals('https://demo.flexibee.eu/c/demo/adresar/1.json?limit=10000&start=0', $this->urlBuilder->createFilterQuery('1', ['limit' => 10000, 'start' => 0])); + Assert::assertEquals( + 'https://demo.flexibee.eu/c/demo/adresar/1.json?limit=10000', + $this->urlBuilder->createFilterQuery('1', ['limit' => 10000]), + ); + Assert::assertEquals( + 'https://demo.flexibee.eu/c/demo/adresar/1.json?limit=10000&start=0', + $this->urlBuilder->createFilterQuery('1', ['limit' => 10000, 'start' => 0]), + ); } public function testCreateUriByEvidenceForSearchQueryWithouLimitParameter(): void { - Assert::assertEquals('https://demo.flexibee.eu/c/demo/adresar/1.json?limit=0', $this->urlBuilder->createFilterQuery('1', [])); + Assert::assertEquals( + 'https://demo.flexibee.eu/c/demo/adresar/1.json?limit=0', + $this->urlBuilder->createFilterQuery('1', []), + ); } } diff --git a/tests/Validator/ParameterValidatorTest.php b/tests/Validator/ParameterValidatorTest.php index 504eedd..00e7fc8 100644 --- a/tests/Validator/ParameterValidatorTest.php +++ b/tests/Validator/ParameterValidatorTest.php @@ -9,7 +9,7 @@ final class ParameterValidatorTest extends TestCase { - private \EcomailFlexibee\Validator\ParameterValidator $validator; + private ParameterValidator $validator; public function setUp(): void {