diff --git a/.php_cs.php b/.php_cs.php deleted file mode 100644 index 00769e5a..00000000 --- a/.php_cs.php +++ /dev/null @@ -1,13 +0,0 @@ -setRules(array( - '@PSR2' => true, - 'linebreak_after_opening_tag' => true, - 'ordered_imports' => true, - )) - ->setFinder( - PhpCsFixer\Finder::create() - ->name('*.php') - ->in(__DIR__ . '/src') - ); diff --git a/Dockerfile b/Dockerfile index 32bbb2ff..390f52f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,19 +25,21 @@ RUN apt-get update && \ /usr/share/lintian/* /usr/share/locale/* /usr/share/man/* # Install PHP with some extensions -RUN apt-get update && \ +RUN wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg && \ + sh -c 'echo "deb https://packages.sury.org/php/ bullseye main" > /etc/apt/sources.list.d/php.list' && \ + apt-get update && \ apt-get --no-install-recommends --no-install-suggests --yes --quiet install \ - php7.4-cli \ - php7.4-apcu \ - php7.4-mbstring \ - php7.4-curl \ - php7.4-gd \ - php7.4-imagick \ - php7.4-intl \ - php7.4-bcmath \ - php7.4-xdebug \ - php7.4-xml \ - php7.4-zip && \ + php8.0-cli \ + php8.0-apcu \ + php8.0-mbstring \ + php8.0-curl \ + php8.0-gd \ + php8.0-imagick \ + php8.0-intl \ + php8.0-bcmath \ + php8.0-xdebug \ + php8.0-xml \ + php8.0-zip && \ apt-get clean && apt-get --yes --quiet autoremove --purge && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ /usr/share/doc/* /usr/share/groff/* /usr/share/info/* /usr/share/linda/* \ diff --git a/Makefile b/Makefile index 821e5690..8bc9d960 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,11 @@ DOCKER_RUN = DOCKER_BUILDKIT=1 docker-compose run php_client help: @grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-25s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/' +.PHONY: build-image +build-image: ## Build docker image + DOCKER_BUILDKIT=1 docker-compose build + +.PHONY: .PHONY: dependencies dependencies: ## Install composer dependencies cp docker-compose.yml.dist docker-compose.yml @@ -32,8 +37,12 @@ cs: ## Run code style check @echo "------------------" @echo "- PHP code style -" @echo "------------------" - $(DOCKER_RUN) bin/php-cs-fixer fix --diff --dry-run --config=.php_cs.php -vvv + $(DOCKER_RUN) bin/ecs .PHONY: fix-cs fix-cs: ## Fix PHP code style - $(DOCKER_RUN) bin/php-cs-fixer fix --config=.php_cs.php + $(DOCKER_RUN) bin/ecs --fix + +.PHONY: rector +rector: ## Run rector + $(DOCKER_RUN) bin/rector diff --git a/composer.json b/composer.json index fb870e9a..166c2d30 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } }, "require": { - "php": ">=7.4", + "php": ">=8.0", "psr/http-message": "^1.0", "psr/http-client": "^1.0", "psr/http-factory": "^1.0", @@ -37,12 +37,14 @@ "symfony/yaml": "^4.2", "donatj/mock-webserver": "^2.0", "http-interop/http-factory-guzzle": "^1.0", - "php-http/guzzle6-adapter": "^2.0" + "php-http/guzzle6-adapter": "^2.0", + "rector/rector": "^0.14.6", + "symplify/easy-coding-standard": "^11.1" }, "config": { "bin-dir": "bin", "platform": { - "php": "7.4" + "php": "8.0" } }, "suggest": { diff --git a/composer.lock b/composer.lock index 38198866..b9c2f2b2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b8f1aa13a098971e273ffb1db83eabd1", + "content-hash": "e4a23e97ad1a5ad8af7dcc2efd774ff0", "packages": [ { "name": "guzzlehttp/psr7", @@ -2417,6 +2417,65 @@ }, "time": "2021-12-08T12:19:24+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.8.11", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "46e223dd68a620da18855c23046ddb00940b4014" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/46e223dd68a620da18855c23046ddb00940b4014", + "reference": "46e223dd68a620da18855c23046ddb00940b4014", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/1.8.11" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2022-10-24T15:45:13+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "7.0.15", @@ -2716,16 +2775,16 @@ }, { "name": "phpunit/phpunit", - "version": "8.5.30", + "version": "8.5.31", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "4fd448df9affda65a5faa58f8b93087d415216ce" + "reference": "33c126b09a42de5c99e5e8032b54e8221264a74e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4fd448df9affda65a5faa58f8b93087d415216ce", - "reference": "4fd448df9affda65a5faa58f8b93087d415216ce", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/33c126b09a42de5c99e5e8032b54e8221264a74e", + "reference": "33c126b09a42de5c99e5e8032b54e8221264a74e", "shasum": "" }, "require": { @@ -2793,7 +2852,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.30" + "source": "https://github.com/sebastianbergmann/phpunit/tree/8.5.31" }, "funding": [ { @@ -2809,24 +2868,24 @@ "type": "tidelift" } ], - "time": "2022-09-25T03:43:00+00:00" + "time": "2022-10-28T05:57:37+00:00" }, { "name": "psr/cache", - "version": "1.0.1", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/php-fig/cache.git", - "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", - "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", + "reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=8.0.0" }, "type": "library", "extra": { @@ -2846,7 +2905,7 @@ "authors": [ { "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" + "homepage": "https://www.php-fig.org/" } ], "description": "Common interface for caching libraries", @@ -2856,9 +2915,9 @@ "psr-6" ], "support": { - "source": "https://github.com/php-fig/cache/tree/master" + "source": "https://github.com/php-fig/cache/tree/3.0.0" }, - "time": "2016-08-06T20:24:11+00:00" + "time": "2021-02-03T23:26:27+00:00" }, { "name": "psr/container", @@ -2960,30 +3019,30 @@ }, { "name": "psr/log", - "version": "1.1.4", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + "reference": "ef29f6d262798707a9edd554e2b82517ef3a9376" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "url": "https://api.github.com/repos/php-fig/log/zipball/ef29f6d262798707a9edd554e2b82517ef3a9376", + "reference": "ef29f6d262798707a9edd554e2b82517ef3a9376", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=8.0.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { "psr-4": { - "Psr\\Log\\": "Psr/Log/" + "Psr\\Log\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -3004,9 +3063,67 @@ "psr-3" ], "support": { - "source": "https://github.com/php-fig/log/tree/1.1.4" + "source": "https://github.com/php-fig/log/tree/2.0.0" }, - "time": "2021-05-03T11:20:27+00:00" + "time": "2021-07-14T16:41:46+00:00" + }, + { + "name": "rector/rector", + "version": "0.14.6", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "e61574288661334155de6e5f0f45497285abad5d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/e61574288661334155de6e5f0f45497285abad5d", + "reference": "e61574288661334155de6e5f0f45497285abad5d", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0", + "phpstan/phpstan": "^1.8.7" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-laravel": "*", + "rector/rector-php-parser": "*", + "rector/rector-phpoffice": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "0.14-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/0.14.6" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2022-10-15T22:58:22+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -3739,16 +3856,16 @@ }, { "name": "symfony/console", - "version": "v5.4.12", + "version": "v5.4.15", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "c072aa8f724c3af64e2c7a96b796a4863d24dba1" + "reference": "ea59bb0edfaf9f28d18d8791410ee0355f317669" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/c072aa8f724c3af64e2c7a96b796a4863d24dba1", - "reference": "c072aa8f724c3af64e2c7a96b796a4863d24dba1", + "url": "https://api.github.com/repos/symfony/console/zipball/ea59bb0edfaf9f28d18d8791410ee0355f317669", + "reference": "ea59bb0edfaf9f28d18d8791410ee0355f317669", "shasum": "" }, "require": { @@ -3818,7 +3935,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v5.4.12" + "source": "https://github.com/symfony/console/tree/v5.4.15" }, "funding": [ { @@ -3834,7 +3951,7 @@ "type": "tidelift" } ], - "time": "2022-08-17T13:18:05+00:00" + "time": "2022-10-26T21:41:52+00:00" }, { "name": "symfony/event-dispatcher", @@ -4002,16 +4119,16 @@ }, { "name": "symfony/filesystem", - "version": "v5.4.12", + "version": "v5.4.13", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "2d67c1f9a1937406a9be3171b4b22250c0a11447" + "reference": "ac09569844a9109a5966b9438fc29113ce77cf51" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/2d67c1f9a1937406a9be3171b4b22250c0a11447", - "reference": "2d67c1f9a1937406a9be3171b4b22250c0a11447", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/ac09569844a9109a5966b9438fc29113ce77cf51", + "reference": "ac09569844a9109a5966b9438fc29113ce77cf51", "shasum": "" }, "require": { @@ -4046,7 +4163,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v5.4.12" + "source": "https://github.com/symfony/filesystem/tree/v5.4.13" }, "funding": [ { @@ -4062,7 +4179,7 @@ "type": "tidelift" } ], - "time": "2022-08-02T13:48:16+00:00" + "time": "2022-09-21T19:53:16+00:00" }, { "name": "symfony/finder", @@ -4846,16 +4963,16 @@ }, { "name": "symfony/stopwatch", - "version": "v5.4.5", + "version": "v5.4.13", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "4d04b5c24f3c9a1a168a131f6cbe297155bc0d30" + "reference": "6df7a3effde34d81717bbef4591e5ffe32226d69" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/4d04b5c24f3c9a1a168a131f6cbe297155bc0d30", - "reference": "4d04b5c24f3c9a1a168a131f6cbe297155bc0d30", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/6df7a3effde34d81717bbef4591e5ffe32226d69", + "reference": "6df7a3effde34d81717bbef4591e5ffe32226d69", "shasum": "" }, "require": { @@ -4888,7 +5005,7 @@ "description": "Provides a way to profile code", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/stopwatch/tree/v5.4.5" + "source": "https://github.com/symfony/stopwatch/tree/v5.4.13" }, "funding": [ { @@ -4904,20 +5021,20 @@ "type": "tidelift" } ], - "time": "2022-02-18T16:06:09+00:00" + "time": "2022-09-28T13:19:49+00:00" }, { "name": "symfony/string", - "version": "v5.4.12", + "version": "v5.4.15", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "2fc515e512d721bf31ea76bd02fe23ada4640058" + "reference": "571334ce9f687e3e6af72db4d3b2a9431e4fd9ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/2fc515e512d721bf31ea76bd02fe23ada4640058", - "reference": "2fc515e512d721bf31ea76bd02fe23ada4640058", + "url": "https://api.github.com/repos/symfony/string/zipball/571334ce9f687e3e6af72db4d3b2a9431e4fd9ed", + "reference": "571334ce9f687e3e6af72db4d3b2a9431e4fd9ed", "shasum": "" }, "require": { @@ -4974,7 +5091,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v5.4.12" + "source": "https://github.com/symfony/string/tree/v5.4.15" }, "funding": [ { @@ -4990,7 +5107,7 @@ "type": "tidelift" } ], - "time": "2022-08-12T17:03:11+00:00" + "time": "2022-10-05T15:16:54+00:00" }, { "name": "symfony/yaml", @@ -5063,6 +5180,61 @@ ], "time": "2022-08-02T15:47:23+00:00" }, + { + "name": "symplify/easy-coding-standard", + "version": "11.1.16", + "source": { + "type": "git", + "url": "https://github.com/symplify/easy-coding-standard.git", + "reference": "32ebd57f0f47713540df8ea39134adaa9d912fae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symplify/easy-coding-standard/zipball/32ebd57f0f47713540df8ea39134adaa9d912fae", + "reference": "32ebd57f0f47713540df8ea39134adaa9d912fae", + "shasum": "" + }, + "require": { + "php": ">=7.2" + }, + "conflict": { + "friendsofphp/php-cs-fixer": "<3.0", + "squizlabs/php_codesniffer": "<3.6" + }, + "bin": [ + "bin/ecs" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "10.3-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Prefixed scoped version of ECS package", + "support": { + "source": "https://github.com/symplify/easy-coding-standard/tree/11.1.16" + }, + "funding": [ + { + "url": "https://www.paypal.me/rectorphp", + "type": "custom" + }, + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2022-10-27T10:48:13+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.1", @@ -5178,11 +5350,11 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=7.4" + "php": ">=8.0" }, "platform-dev": [], "platform-overrides": { - "php": "7.4" + "php": "8.0" }, - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.2.0" } diff --git a/ecs.php b/ecs.php new file mode 100644 index 00000000..4b5b94d4 --- /dev/null +++ b/ecs.php @@ -0,0 +1,28 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]); + + $ecsConfig->sets([SetList::PSR_12]); + + $ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, [ + 'syntax' => 'short', + ]); + + $ecsConfig->ruleWithConfiguration(LineLengthFixer::class, [ + LineLengthFixer::LINE_LENGTH => 140, + LineLengthFixer::INLINE_SHORT_LINES => false, + LineLengthFixer::BREAK_LONG_LINES => true, + ]); + + $ecsConfig->rule(StandaloneLinePromotedPropertyFixer::class); +}; diff --git a/rector.php b/rector.php new file mode 100644 index 00000000..7dac39ab --- /dev/null +++ b/rector.php @@ -0,0 +1,28 @@ +paths([ + __DIR__ . '/src', + __DIR__ . '/tests', + __DIR__ . '/spec' + ]); + + $rectorConfig->skip([ + JsonThrowOnErrorRector::class + ]); + + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + + $rectorConfig->sets([ + SetList::CODE_QUALITY, + LevelSetList::UP_TO_PHP_80 + ]); +}; diff --git a/spec/Routing/UriGeneratorSpec.php b/spec/Routing/UriGeneratorSpec.php index b92f589a..ac012430 100644 --- a/spec/Routing/UriGeneratorSpec.php +++ b/spec/Routing/UriGeneratorSpec.php @@ -6,7 +6,7 @@ class UriGeneratorSpec extends ObjectBehavior { - const BASE_URI = 'http://akeneo-pim.local/'; + public const BASE_URI = 'http://akeneo-pim.local/'; function let() { diff --git a/spec/Security/AuthenticationSpec.php b/spec/Security/AuthenticationSpec.php index 9ece8248..830d8b15 100644 --- a/spec/Security/AuthenticationSpec.php +++ b/spec/Security/AuthenticationSpec.php @@ -2,6 +2,7 @@ namespace spec\Akeneo\Pim\ApiClient\Security; +use Akeneo\Pim\ApiClient\Security\Authentication; use PhpSpec\ObjectBehavior; class AuthenticationSpec extends ObjectBehavior @@ -9,7 +10,7 @@ class AuthenticationSpec extends ObjectBehavior function it_is_initializable_from_a_password() { $this->beConstructedThrough('fromPassword', ['client_id', 'secret', 'Julia', 'Julia_pwd']); - $this->shouldHaveType('Akeneo\Pim\ApiClient\Security\Authentication'); + $this->shouldHaveType(Authentication::class); $this->getClientId()->shouldReturn('client_id'); $this->getSecret()->shouldReturn('secret'); @@ -22,7 +23,7 @@ function it_is_initializable_from_a_password() function it_is_initializable_from_a_token() { $this->beConstructedThrough('fromToken', ['client_id', 'secret', 'token', 'refresh_token']); - $this->shouldHaveType('Akeneo\Pim\ApiClient\Security\Authentication'); + $this->shouldHaveType(Authentication::class); $this->getClientId()->shouldReturn('client_id'); $this->getSecret()->shouldReturn('secret'); @@ -35,7 +36,7 @@ function it_is_initializable_from_a_token() function it_is_initializable_from_an_app_token() { $this->beConstructedThrough('fromAppToken', ['a_token']); - $this->shouldHaveType('Akeneo\Pim\ApiClient\Security\Authentication'); + $this->shouldHaveType(Authentication::class); $this->getClientId()->shouldReturn(null); $this->getSecret()->shouldReturn(null); diff --git a/src/AkeneoPimClient.php b/src/AkeneoPimClient.php index c06b0a00..9ee84f13 100644 --- a/src/AkeneoPimClient.php +++ b/src/AkeneoPimClient.php @@ -50,124 +50,46 @@ */ class AkeneoPimClient implements AkeneoPimClientInterface { - protected Authentication $authentication; - protected ProductApiInterface $productApi; - protected CategoryApiInterface $categoryApi; - protected AttributeApiInterface $attributeApi; - protected AttributeOptionApiInterface $attributeOptionApi; - protected AttributeGroupApiInterface $attributeGroupApi; - protected FamilyApiInterface $familyApi; - protected MediaFileApiInterface $productMediaFileApi; - protected LocaleApiInterface $localeApi; - protected ChannelApiInterface $channelApi; - protected CurrencyApiInterface $currencyApi; - protected MeasureFamilyApiInterface $measureFamilyApi; - protected AssociationTypeApiInterface $associationTypeApi; - protected FamilyVariantApiInterface $familyVariantApi; - protected ProductModelApiInterface $productModelApi; - private MeasurementFamilyApiInterface $measurementFamilyApi; - private PublishedProductApiInterface $publishedProductApi; - private ProductModelDraftApiInterface $productModelDraftApi; - private ProductDraftApiInterface $productDraftApi; - private AssetApiInterface $assetApi; - private AssetCategoryApiInterface $assetCategoryApi; - private AssetTagApiInterface $assetTagApi; - private AssetReferenceFileApiInterface $assetReferenceFileApi; - private AssetVariationFileApiInterface $assetVariationFileApi; - private ReferenceEntityRecordApiInterface $referenceEntityRecordApi; - private ReferenceEntityMediaFileApiInterface $referenceEntityMediaFileApi; - private ReferenceEntityAttributeApiInterface $referenceEntityAttributeApi; - private ReferenceEntityAttributeOptionApiInterface $referenceEntityAttributeOptionApi; - private ReferenceEntityApiInterface $referenceEntityApi; - private AssetManagerApiInterface $assetManagerApi; - private AssetFamilyApiInterface $assetFamilyApi; - private AssetAttributeApiInterface $assetAttributeApi; - private AssetAttributeOptionApiInterface $assetAttributeOptionApi; - private AssetMediaFileApiInterface $assetMediaFileApi; - private AppCatalogApiInterface $appCatalogApi; - private AppCatalogProductApiInterface $appCatalogProductApi; - - private ProductUuidApiInterface $productUuidApi; - private ProductDraftUuidApiInterface $productDraftUuidApi; - public function __construct( - Authentication $authentication, - ProductApiInterface $productApi, - CategoryApiInterface $categoryApi, - AttributeApiInterface $attributeApi, - AttributeOptionApiInterface $attributeOptionApi, - AttributeGroupApiInterface $attributeGroupApi, - FamilyApiInterface $familyApi, - MediaFileApiInterface $productMediaFileApi, - LocaleApiInterface $localeApi, - ChannelApiInterface $channelApi, - CurrencyApiInterface $currencyApi, - MeasureFamilyApiInterface $measureFamilyApi, - MeasurementFamilyApiInterface $measurementFamilyApi, - AssociationTypeApiInterface $associationTypeApi, - FamilyVariantApiInterface $familyVariantApi, - ProductModelApiInterface $productModelApi, - ProductModelDraftApiInterface $productModelDraftApi, - PublishedProductApiInterface $publishedProductApi, - ProductDraftApiInterface $productDraftApi, - AssetApiInterface $assetApi, - AssetCategoryApiInterface $assetCategoryApi, - AssetTagApiInterface $assetTagApi, - AssetReferenceFileApiInterface $assetReferenceFileApi, - AssetVariationFileApiInterface $assetVariationFileApi, - ReferenceEntityRecordApiInterface $referenceEntityRecordApi, - ReferenceEntityMediaFileApiInterface $referenceEntityMediaFileApi, - ReferenceEntityAttributeApiInterface $referenceEntityAttributeApi, - ReferenceEntityAttributeOptionApiInterface $referenceEntityAttributeOptionApi, - ReferenceEntityApiInterface $referenceEntityApi, - AssetManagerApiInterface $assetManagerApi, - AssetFamilyApiInterface $assetFamilyApi, - AssetAttributeApiInterface $assetAttributeApi, - AssetAttributeOptionApiInterface $assetAttributeOptionApi, - AssetMediaFileApiInterface $assetMediaFileApi, - ProductUuidApiInterface $productUuidApi, - ProductDraftUuidApiInterface $productDraftUuidApi, - AppCatalogApiInterface $appCatalogApi, - AppCatalogProductApiInterface $appCatalogProductApi + protected Authentication $authentication, + protected ProductApiInterface $productApi, + protected CategoryApiInterface $categoryApi, + protected AttributeApiInterface $attributeApi, + protected AttributeOptionApiInterface $attributeOptionApi, + protected AttributeGroupApiInterface $attributeGroupApi, + protected FamilyApiInterface $familyApi, + protected MediaFileApiInterface $productMediaFileApi, + protected LocaleApiInterface $localeApi, + protected ChannelApiInterface $channelApi, + protected CurrencyApiInterface $currencyApi, + protected MeasureFamilyApiInterface $measureFamilyApi, + private MeasurementFamilyApiInterface $measurementFamilyApi, + protected AssociationTypeApiInterface $associationTypeApi, + protected FamilyVariantApiInterface $familyVariantApi, + protected ProductModelApiInterface $productModelApi, + private ProductModelDraftApiInterface $productModelDraftApi, + private PublishedProductApiInterface $publishedProductApi, + private ProductDraftApiInterface $productDraftApi, + private AssetApiInterface $assetApi, + private AssetCategoryApiInterface $assetCategoryApi, + private AssetTagApiInterface $assetTagApi, + private AssetReferenceFileApiInterface $assetReferenceFileApi, + private AssetVariationFileApiInterface $assetVariationFileApi, + private ReferenceEntityRecordApiInterface $referenceEntityRecordApi, + private ReferenceEntityMediaFileApiInterface $referenceEntityMediaFileApi, + private ReferenceEntityAttributeApiInterface $referenceEntityAttributeApi, + private ReferenceEntityAttributeOptionApiInterface $referenceEntityAttributeOptionApi, + private ReferenceEntityApiInterface $referenceEntityApi, + private AssetManagerApiInterface $assetManagerApi, + private AssetFamilyApiInterface $assetFamilyApi, + private AssetAttributeApiInterface $assetAttributeApi, + private AssetAttributeOptionApiInterface $assetAttributeOptionApi, + private AssetMediaFileApiInterface $assetMediaFileApi, + private ProductUuidApiInterface $productUuidApi, + private ProductDraftUuidApiInterface $productDraftUuidApi, + private AppCatalogApiInterface $appCatalogApi, + private AppCatalogProductApiInterface $appCatalogProductApi ) { - $this->authentication = $authentication; - $this->productApi = $productApi; - $this->categoryApi = $categoryApi; - $this->attributeApi = $attributeApi; - $this->attributeOptionApi = $attributeOptionApi; - $this->attributeGroupApi = $attributeGroupApi; - $this->familyApi = $familyApi; - $this->productMediaFileApi = $productMediaFileApi; - $this->localeApi = $localeApi; - $this->channelApi = $channelApi; - $this->currencyApi = $currencyApi; - $this->measureFamilyApi = $measureFamilyApi; - $this->measurementFamilyApi = $measurementFamilyApi; - $this->associationTypeApi = $associationTypeApi; - $this->familyVariantApi = $familyVariantApi; - $this->productModelApi = $productModelApi; - $this->publishedProductApi = $publishedProductApi; - $this->productDraftApi = $productDraftApi; - $this->productModelDraftApi = $productModelDraftApi; - $this->assetApi = $assetApi; - $this->assetCategoryApi = $assetCategoryApi; - $this->assetTagApi = $assetTagApi; - $this->assetReferenceFileApi = $assetReferenceFileApi; - $this->assetVariationFileApi = $assetVariationFileApi; - $this->referenceEntityRecordApi = $referenceEntityRecordApi; - $this->referenceEntityMediaFileApi = $referenceEntityMediaFileApi; - $this->referenceEntityAttributeApi = $referenceEntityAttributeApi; - $this->referenceEntityAttributeOptionApi = $referenceEntityAttributeOptionApi; - $this->referenceEntityApi = $referenceEntityApi; - $this->assetManagerApi = $assetManagerApi; - $this->assetFamilyApi = $assetFamilyApi; - $this->assetAttributeApi = $assetAttributeApi; - $this->assetAttributeOptionApi = $assetAttributeOptionApi; - $this->assetMediaFileApi = $assetMediaFileApi; - $this->productUuidApi = $productUuidApi; - $this->productDraftUuidApi = $productDraftUuidApi; - $this->appCatalogApi = $appCatalogApi; - $this->appCatalogProductApi = $appCatalogProductApi; } /** diff --git a/src/AkeneoPimClientBuilder.php b/src/AkeneoPimClientBuilder.php index be777a0f..dd3ffa78 100644 --- a/src/AkeneoPimClientBuilder.php +++ b/src/AkeneoPimClientBuilder.php @@ -70,9 +70,6 @@ */ class AkeneoPimClientBuilder { - /** @var string */ - protected $baseUri; - /** @var ClientInterface */ protected $httpClient; @@ -92,9 +89,10 @@ class AkeneoPimClientBuilder /** * @param string $baseUri Base uri to request the API */ - public function __construct(string $baseUri, array $options = []) - { - $this->baseUri = $baseUri; + public function __construct( + protected string $baseUri, + array $options = [] + ) { $this->options = Options::fromArray($options); } @@ -130,10 +128,6 @@ public function setStreamFactory(StreamFactoryInterface $streamFactory): self /** * Allows to define another implementation than LocalFileSystem - * - * @param FileSystemInterface $fileSystem - * - * @return AkeneoPimClientBuilder */ public function setFileSystem(FileSystemInterface $fileSystem): self { @@ -149,11 +143,13 @@ public function setFileSystem(FileSystemInterface $fileSystem): self * @param string $secret Secret associated to the client * @param string $username Username to use for the authentication * @param string $password Password associated to the username - * - * @return AkeneoPimClientInterface */ - public function buildAuthenticatedByPassword(string $clientId, string $secret, string $username, string $password): AkeneoPimClientInterface - { + public function buildAuthenticatedByPassword( + string $clientId, + string $secret, + string $username, + string $password + ): AkeneoPimClientInterface { $authentication = Authentication::fromPassword($clientId, $secret, $username, $password); return $this->buildAuthenticatedClient($authentication); @@ -173,11 +169,13 @@ public function buildAuthenticatedByAppToken(string $token): AkeneoPimClientInte * @param string $secret Secret associated to the client * @param string $token Token to use for the authentication * @param string $refreshToken Token to use to refresh the access token - * - * @return AkeneoPimClientInterface */ - public function buildAuthenticatedByToken(string $clientId, string $secret, string $token, string $refreshToken): AkeneoPimClientInterface - { + public function buildAuthenticatedByToken( + string $clientId, + string $secret, + string $token, + string $refreshToken + ): AkeneoPimClientInterface { $authentication = Authentication::fromToken($clientId, $secret, $token, $refreshToken); return $this->buildAuthenticatedClient($authentication); @@ -205,16 +203,11 @@ public function disableCache(): self return $this; } - /** - * @param Authentication $authentication - * - * @return AkeneoPimClientInterface - */ protected function buildAuthenticatedClient(Authentication $authentication): AkeneoPimClientInterface { [$resourceClient, $pageFactory, $cursorFactory, $fileSystem] = $this->setUp($authentication); - $resourceClientWithCache = !$this->cacheEnabled ? $resourceClient : new CachedResourceClient($resourceClient, new LRUCache()); + $resourceClientWithCache = $this->cacheEnabled ? new CachedResourceClient($resourceClient, new LRUCache()) : $resourceClient; return new AkeneoPimClient( $authentication, @@ -258,11 +251,6 @@ protected function buildAuthenticatedClient(Authentication $authentication): Ake ); } - /** - * @param Authentication $authentication - * - * @return array - */ protected function setUp(Authentication $authentication): array { $uriGenerator = new UriGenerator($this->baseUri); diff --git a/src/AkeneoPimClientInterface.php b/src/AkeneoPimClientInterface.php index 912a51ab..3c3ea2a9 100644 --- a/src/AkeneoPimClientInterface.php +++ b/src/AkeneoPimClientInterface.php @@ -136,9 +136,9 @@ public function getAssetAttributeOptionApi(): AssetAttributeOptionApiInterface; public function getAssetMediaFileApi(): AssetMediaFileApiInterface; - public function getProductUuidApi() : ProductUuidApiInterface; + public function getProductUuidApi(): ProductUuidApiInterface; - public function getProductDraftUuidApi() : ProductDraftUuidApiInterface; + public function getProductDraftUuidApi(): ProductDraftUuidApiInterface; public function getAppCatalogApi(): AppCatalogApiInterface; diff --git a/src/Api/AppCatalog/AppCatalogApi.php b/src/Api/AppCatalog/AppCatalogApi.php index 0f8e7d3d..a2d52cd8 100644 --- a/src/Api/AppCatalog/AppCatalogApi.php +++ b/src/Api/AppCatalog/AppCatalogApi.php @@ -1,4 +1,5 @@ resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } public function listPerPage(int $limit = 100, bool $withCount = false, array $queryParameters = []): PageInterface diff --git a/src/Api/AppCatalog/AppCatalogApiInterface.php b/src/Api/AppCatalog/AppCatalogApiInterface.php index 524e9a3b..63e3896e 100644 --- a/src/Api/AppCatalog/AppCatalogApiInterface.php +++ b/src/Api/AppCatalog/AppCatalogApiInterface.php @@ -1,4 +1,5 @@ resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/AppCatalog/AppCatalogProductApiInterface.php b/src/Api/AppCatalog/AppCatalogProductApiInterface.php index f2975796..d7e9f542 100644 --- a/src/Api/AppCatalog/AppCatalogProductApiInterface.php +++ b/src/Api/AppCatalog/AppCatalogProductApiInterface.php @@ -1,4 +1,5 @@ resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/AssetCategoryApi.php b/src/Api/AssetCategoryApi.php index f673cc88..8f672d7e 100644 --- a/src/Api/AssetCategoryApi.php +++ b/src/Api/AssetCategoryApi.php @@ -22,26 +22,14 @@ */ class AssetCategoryApi implements AssetCategoryApiInterface { - const ASSET_CATEGORIES_URI = '/api/rest/v1/asset-categories'; - const ASSET_CATEGORY_URI = '/api/rest/v1/asset-categories/%s'; - - /** @var ResourceClientInterface */ - private $resourceClient; - - /** @var PageFactoryInterface */ - private $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - private $cursorFactory; + public const ASSET_CATEGORIES_URI = '/api/rest/v1/asset-categories'; + public const ASSET_CATEGORY_URI = '/api/rest/v1/asset-categories/%s'; public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/AssetManager/AssetApi.php b/src/Api/AssetManager/AssetApi.php index 2435e304..f9390958 100644 --- a/src/Api/AssetManager/AssetApi.php +++ b/src/Api/AssetManager/AssetApi.php @@ -11,26 +11,14 @@ class AssetApi implements AssetApiInterface { - const ASSET_URI= 'api/rest/v1/asset-families/%s/assets/%s'; - const ASSETS_URI = 'api/rest/v1/asset-families/%s/assets'; - - /** @var ResourceClientInterface */ - private $resourceClient; - - /** @var PageFactoryInterface */ - private $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - private $cursorFactory; + public const ASSET_URI = 'api/rest/v1/asset-families/%s/assets/%s'; + public const ASSETS_URI = 'api/rest/v1/asset-families/%s/assets'; public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/AssetManager/AssetAttributeApi.php b/src/Api/AssetManager/AssetAttributeApi.php index 38d8d071..d9c8eef1 100644 --- a/src/Api/AssetManager/AssetAttributeApi.php +++ b/src/Api/AssetManager/AssetAttributeApi.php @@ -8,15 +8,12 @@ class AssetAttributeApi implements AssetAttributeApiInterface { - const ASSET_ATTRIBUTE_URI = 'api/rest/v1/asset-families/%s/attributes/%s'; - const ASSET_ATTRIBUTES_URI = 'api/rest/v1/asset-families/%s/attributes'; + public const ASSET_ATTRIBUTE_URI = 'api/rest/v1/asset-families/%s/attributes/%s'; + public const ASSET_ATTRIBUTES_URI = 'api/rest/v1/asset-families/%s/attributes'; - /** @var ResourceClientInterface */ - private $resourceClient; - - public function __construct(ResourceClientInterface $resourceClient) - { - $this->resourceClient = $resourceClient; + public function __construct( + private ResourceClientInterface $resourceClient + ) { } /** diff --git a/src/Api/AssetManager/AssetAttributeOptionApi.php b/src/Api/AssetManager/AssetAttributeOptionApi.php index edd4c063..062669a3 100644 --- a/src/Api/AssetManager/AssetAttributeOptionApi.php +++ b/src/Api/AssetManager/AssetAttributeOptionApi.php @@ -8,15 +8,12 @@ class AssetAttributeOptionApi implements AssetAttributeOptionApiInterface { - const ASSET_ATTRIBUTE_OPTION_URI = 'api/rest/v1/asset-families/%s/attributes/%s/options/%s'; - const ASSET_ATTRIBUTE_OPTIONS_URI = 'api/rest/v1/asset-families/%s/attributes/%s/options'; + public const ASSET_ATTRIBUTE_OPTION_URI = 'api/rest/v1/asset-families/%s/attributes/%s/options/%s'; + public const ASSET_ATTRIBUTE_OPTIONS_URI = 'api/rest/v1/asset-families/%s/attributes/%s/options'; - /** @var ResourceClientInterface */ - private $resourceClient; - - public function __construct(ResourceClientInterface $resourceClient) - { - $this->resourceClient = $resourceClient; + public function __construct( + private ResourceClientInterface $resourceClient + ) { } /** diff --git a/src/Api/AssetManager/AssetFamilyApi.php b/src/Api/AssetManager/AssetFamilyApi.php index bc5bade4..8a1e3c65 100644 --- a/src/Api/AssetManager/AssetFamilyApi.php +++ b/src/Api/AssetManager/AssetFamilyApi.php @@ -11,26 +11,14 @@ class AssetFamilyApi implements AssetFamilyApiInterface { - const ASSET_FAMILY_URI = 'api/rest/v1/asset-families/%s'; - const ASSET_FAMILIES_URI= 'api/rest/v1/asset-families'; - - /** @var ResourceClientInterface */ - private $resourceClient; - - /** @var PageFactoryInterface */ - private $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - private $cursorFactory; + public const ASSET_FAMILY_URI = 'api/rest/v1/asset-families/%s'; + public const ASSET_FAMILIES_URI = 'api/rest/v1/asset-families'; public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/AssetManager/AssetMediaFileApi.php b/src/Api/AssetManager/AssetMediaFileApi.php index 8b63ba0e..55a418b2 100644 --- a/src/Api/AssetManager/AssetMediaFileApi.php +++ b/src/Api/AssetManager/AssetMediaFileApi.php @@ -1,4 +1,5 @@ resourceClient = $resourceClient; - $this->fileSystem = $fileSystem; + public function __construct( + private ResourceClientInterface $resourceClient, + private FileSystemInterface $fileSystem + ) { } /** @@ -57,11 +52,7 @@ public function create($mediaFile): string /** * Extracts the code of a media-file from a creation response. * - * @param ResponseInterface $response - * * @throws RuntimeException if unable to extract the code - * - * @return string */ private function extractCodeFromCreationResponse(ResponseInterface $response): string { diff --git a/src/Api/AssetManager/AssetMediaFileApiInterface.php b/src/Api/AssetManager/AssetMediaFileApiInterface.php index b62b4998..889ec345 100644 --- a/src/Api/AssetManager/AssetMediaFileApiInterface.php +++ b/src/Api/AssetManager/AssetMediaFileApiInterface.php @@ -1,4 +1,5 @@ resourceClient = $resourceClient; - $this->fileSystem = $fileSystem; + public const ASSET_REFERENCE_FILE_URI = '/api/rest/v1/assets/%s/reference-files/%s'; + public const ASSET_REFERENCE_FILE_DOWNLOAD_URI = '/api/rest/v1/assets/%s/reference-files/%s/download'; + public const NOT_LOCALIZABLE_ASSET_LOCALE_CODE = 'no-locale'; + + public function __construct( + private ResourceClientInterface $resourceClient, + private FileSystemInterface $fileSystem + ) { } /** @@ -88,10 +82,6 @@ public function downloadFromNotLocalizableAsset(string $assetCode): ResponseInte /** * @param string|resource $referenceFile - * @param string $assetCode - * @param string $localeCode - * - * @return int */ private function upload($referenceFile, string $assetCode, string $localeCode): int { @@ -104,7 +94,11 @@ private function upload($referenceFile, string $assetCode, string $localeCode): 'contents' => $referenceFile, ]]; - $response = $this->resourceClient->createMultipartResource(static::ASSET_REFERENCE_FILE_URI, [$assetCode, $localeCode], $requestParts); + $response = $this->resourceClient->createMultipartResource( + static::ASSET_REFERENCE_FILE_URI, + [$assetCode, $localeCode], + $requestParts + ); $this->handleUploadErrors($response); return $response->getStatusCode(); diff --git a/src/Api/AssetTagApi.php b/src/Api/AssetTagApi.php index 5e4e3398..5749f3f2 100644 --- a/src/Api/AssetTagApi.php +++ b/src/Api/AssetTagApi.php @@ -20,26 +20,14 @@ */ class AssetTagApi implements AssetTagApiInterface { - const ASSET_TAGS_URI = '/api/rest/v1/asset-tags'; - const ASSET_TAG_URI = '/api/rest/v1/asset-tags/%s'; - - /** @var ResourceClientInterface */ - private $resourceClient; - - /** @var PageFactoryInterface */ - private $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - private $cursorFactory; + public const ASSET_TAGS_URI = '/api/rest/v1/asset-tags'; + public const ASSET_TAG_URI = '/api/rest/v1/asset-tags/%s'; public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/AssetVariationFileApi.php b/src/Api/AssetVariationFileApi.php index 2a3d2684..e8f36335 100644 --- a/src/Api/AssetVariationFileApi.php +++ b/src/Api/AssetVariationFileApi.php @@ -18,20 +18,14 @@ */ class AssetVariationFileApi implements AssetVariationFileApiInterface { - const ASSET_VARIATION_FILE_URI = '/api/rest/v1/assets/%s/variation-files/%s/%s'; - const ASSET_VARIATION_FILE_DOWNLOAD_URI = '/api/rest/v1/assets/%s/variation-files/%s/%s/download'; - const NOT_LOCALIZABLE_ASSET_LOCALE_CODE = 'no-locale'; - - /** @var ResourceClientInterface */ - private $resourceClient; - - /** @var FileSystemInterface */ - private $fileSystem; - - public function __construct(ResourceClientInterface $resourceClient, FileSystemInterface $fileSystem) - { - $this->resourceClient = $resourceClient; - $this->fileSystem = $fileSystem; + public const ASSET_VARIATION_FILE_URI = '/api/rest/v1/assets/%s/variation-files/%s/%s'; + public const ASSET_VARIATION_FILE_DOWNLOAD_URI = '/api/rest/v1/assets/%s/variation-files/%s/%s/download'; + public const NOT_LOCALIZABLE_ASSET_LOCALE_CODE = 'no-locale'; + + public function __construct( + private ResourceClientInterface $resourceClient, + private FileSystemInterface $fileSystem + ) { } /** @@ -95,11 +89,6 @@ private function get(string $assetCode, string $channelCode, string $localeCode) /** * @param string|resource $variationFile - * @param string $assetCode - * @param string $channelCode - * @param string $localeCode - * - * @return int */ private function upload($variationFile, string $assetCode, string $channelCode, string $localeCode): int { diff --git a/src/Api/AssociationTypeApi.php b/src/Api/AssociationTypeApi.php index 75000e40..5447c24f 100644 --- a/src/Api/AssociationTypeApi.php +++ b/src/Api/AssociationTypeApi.php @@ -16,31 +16,14 @@ */ class AssociationTypeApi implements AssociationTypeApiInterface { - const ASSOCIATION_TYPES_URI = 'api/rest/v1/association-types'; - const ASSOCIATION_TYPE_URI = 'api/rest/v1/association-types/%s'; + public const ASSOCIATION_TYPES_URI = 'api/rest/v1/association-types'; + public const ASSOCIATION_TYPE_URI = 'api/rest/v1/association-types/%s'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** * {@inheritdoc} diff --git a/src/Api/AttributeApi.php b/src/Api/AttributeApi.php index 0aa496cb..baab98f8 100644 --- a/src/Api/AttributeApi.php +++ b/src/Api/AttributeApi.php @@ -18,31 +18,14 @@ */ class AttributeApi implements AttributeApiInterface { - const ATTRIBUTES_URI = 'api/rest/v1/attributes'; - const ATTRIBUTE_URI = 'api/rest/v1/attributes/%s'; + public const ATTRIBUTES_URI = 'api/rest/v1/attributes'; + public const ATTRIBUTE_URI = 'api/rest/v1/attributes/%s'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/AttributeGroupApi.php b/src/Api/AttributeGroupApi.php index 2f9f3119..78db2949 100644 --- a/src/Api/AttributeGroupApi.php +++ b/src/Api/AttributeGroupApi.php @@ -18,31 +18,14 @@ */ class AttributeGroupApi implements AttributeGroupApiInterface { - const ATTRIBUTE_GROUP_URI = 'api/rest/v1/attribute-groups/%s'; - const ATTRIBUTE_GROUPS_URI = 'api/rest/v1/attribute-groups'; + public const ATTRIBUTE_GROUP_URI = 'api/rest/v1/attribute-groups/%s'; + public const ATTRIBUTE_GROUPS_URI = 'api/rest/v1/attribute-groups'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/AttributeOptionApi.php b/src/Api/AttributeOptionApi.php index 684f3b0a..fd61a6c1 100644 --- a/src/Api/AttributeOptionApi.php +++ b/src/Api/AttributeOptionApi.php @@ -18,31 +18,14 @@ */ class AttributeOptionApi implements AttributeOptionApiInterface { - const ATTRIBUTE_OPTIONS_URI = 'api/rest/v1/attributes/%s/options'; - const ATTRIBUTE_OPTION_URI = 'api/rest/v1/attributes/%s/options/%s'; + public const ATTRIBUTE_OPTIONS_URI = 'api/rest/v1/attributes/%s/options'; + public const ATTRIBUTE_OPTION_URI = 'api/rest/v1/attributes/%s/options/%s'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/AuthenticationApi.php b/src/Api/AuthenticationApi.php index c8ce743e..b1ecb6bb 100644 --- a/src/Api/AuthenticationApi.php +++ b/src/Api/AuthenticationApi.php @@ -14,22 +14,12 @@ */ class AuthenticationApi implements AuthenticationApiInterface { - const TOKEN_URI = 'api/oauth/v1/token'; + public const TOKEN_URI = 'api/oauth/v1/token'; - /** @var HttpClient */ - protected $httpClient; - - /** @var UriGeneratorInterface */ - protected $uriGenerator; - - /** - * @param HttpClient $httpClient - * @param UriGeneratorInterface $uriGenerator - */ - public function __construct(HttpClient $httpClient, UriGeneratorInterface $uriGenerator) - { - $this->httpClient = $httpClient; - $this->uriGenerator = $uriGenerator; + public function __construct( + protected HttpClient $httpClient, + protected UriGeneratorInterface $uriGenerator + ) { } /** @@ -39,8 +29,8 @@ public function authenticateByPassword($clientId, $secret, $username, $password) { $requestBody = [ 'grant_type' => 'password', - 'username' => $username, - 'password' => $password, + 'username' => $username, + 'password' => $password, ]; return $this->authenticate($clientId, $secret, $requestBody); @@ -52,7 +42,7 @@ public function authenticateByPassword($clientId, $secret, $username, $password) public function authenticateByRefreshToken($clientId, $secret, $refreshToken): array { $requestBody = [ - 'grant_type' => 'refresh_token', + 'grant_type' => 'refresh_token', 'refresh_token' => $refreshToken ]; @@ -71,7 +61,7 @@ public function authenticateByRefreshToken($clientId, $secret, $refreshToken): a protected function authenticate($clientId, $secret, array $requestBody): array { $headers = [ - 'Content-Type' => 'application/json', + 'Content-Type' => 'application/json', 'Authorization' => sprintf('Basic %s', base64_encode($clientId . ':' . $secret)), ]; @@ -79,8 +69,6 @@ protected function authenticate($clientId, $secret, array $requestBody): array $response = $this->httpClient->sendRequest('POST', $uri, $headers, json_encode($requestBody)); - $responseBody = json_decode($response->getBody()->getContents(), true); - - return $responseBody; + return json_decode($response->getBody()->getContents(), true); } } diff --git a/src/Api/CategoryApi.php b/src/Api/CategoryApi.php index 4ef4e04d..95d9d524 100644 --- a/src/Api/CategoryApi.php +++ b/src/Api/CategoryApi.php @@ -18,31 +18,14 @@ */ class CategoryApi implements CategoryApiInterface { - const CATEGORY_URI = 'api/rest/v1/categories/%s'; - const CATEGORIES_URI = 'api/rest/v1/categories'; + public const CATEGORY_URI = 'api/rest/v1/categories/%s'; + public const CATEGORIES_URI = 'api/rest/v1/categories'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/ChannelApi.php b/src/Api/ChannelApi.php index c468bd76..de885da9 100644 --- a/src/Api/ChannelApi.php +++ b/src/Api/ChannelApi.php @@ -18,31 +18,14 @@ */ class ChannelApi implements ChannelApiInterface { - const CHANNELS_URI = 'api/rest/v1/channels'; - const CHANNEL_URI = 'api/rest/v1/channels/%s'; + public const CHANNELS_URI = 'api/rest/v1/channels'; + public const CHANNEL_URI = 'api/rest/v1/channels/%s'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/CurrencyApi.php b/src/Api/CurrencyApi.php index cafc4764..fc6204ce 100644 --- a/src/Api/CurrencyApi.php +++ b/src/Api/CurrencyApi.php @@ -17,31 +17,14 @@ */ class CurrencyApi implements CurrencyApiInterface { - const CURRENCY_URI = 'api/rest/v1/currencies/%s'; - const CURRENCIES_URI = 'api/rest/v1/currencies'; + public const CURRENCY_URI = 'api/rest/v1/currencies/%s'; + public const CURRENCIES_URI = 'api/rest/v1/currencies'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/FamilyApi.php b/src/Api/FamilyApi.php index 9ce667fe..4a82b1a0 100644 --- a/src/Api/FamilyApi.php +++ b/src/Api/FamilyApi.php @@ -18,31 +18,14 @@ */ class FamilyApi implements FamilyApiInterface { - const FAMILIES_URI = 'api/rest/v1/families'; - const FAMILY_URI = 'api/rest/v1/families/%s'; + public const FAMILIES_URI = 'api/rest/v1/families'; + public const FAMILY_URI = 'api/rest/v1/families/%s'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/FamilyVariantApi.php b/src/Api/FamilyVariantApi.php index aa523ed4..14917d23 100644 --- a/src/Api/FamilyVariantApi.php +++ b/src/Api/FamilyVariantApi.php @@ -18,31 +18,14 @@ */ class FamilyVariantApi implements FamilyVariantApiInterface { - const FAMILY_VARIANT_URI = 'api/rest/v1/families/%s/variants/%s'; - const FAMILY_VARIANTS_URI = 'api/rest/v1/families/%s/variants'; + public const FAMILY_VARIANT_URI = 'api/rest/v1/families/%s/variants/%s'; + public const FAMILY_VARIANTS_URI = 'api/rest/v1/families/%s/variants'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/LocaleApi.php b/src/Api/LocaleApi.php index 1eac43fa..7ef6f91c 100644 --- a/src/Api/LocaleApi.php +++ b/src/Api/LocaleApi.php @@ -17,31 +17,14 @@ */ class LocaleApi implements LocaleApiInterface { - const LOCALES_URI = 'api/rest/v1/locales'; - const LOCALE_URI = 'api/rest/v1/locales/%s'; + public const LOCALES_URI = 'api/rest/v1/locales'; + public const LOCALE_URI = 'api/rest/v1/locales/%s'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/MeasureFamilyApi.php b/src/Api/MeasureFamilyApi.php index ce5f92c7..c7106239 100644 --- a/src/Api/MeasureFamilyApi.php +++ b/src/Api/MeasureFamilyApi.php @@ -17,31 +17,14 @@ */ class MeasureFamilyApi implements MeasureFamilyApiInterface { - const MEASURE_FAMILY_URI = 'api/rest/v1/measure-families/%s'; - const MEASURE_FAMILIES_URI = 'api/rest/v1/measure-families'; + public const MEASURE_FAMILY_URI = 'api/rest/v1/measure-families/%s'; + public const MEASURE_FAMILIES_URI = 'api/rest/v1/measure-families'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/MeasurementFamilyApi.php b/src/Api/MeasurementFamilyApi.php index 487d20b5..487fd3b3 100644 --- a/src/Api/MeasurementFamilyApi.php +++ b/src/Api/MeasurementFamilyApi.php @@ -13,17 +13,11 @@ */ class MeasurementFamilyApi implements MeasurementFamilyApiInterface { - const MEASUREMENT_FAMILIES_URI = 'api/rest/v1/measurement-families'; + public const MEASUREMENT_FAMILIES_URI = 'api/rest/v1/measurement-families'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** - * @param ResourceClientInterface $resourceClient - */ - public function __construct(ResourceClientInterface $resourceClient) - { - $this->resourceClient = $resourceClient; + public function __construct( + protected ResourceClientInterface $resourceClient + ) { } /** diff --git a/src/Api/Operation/UpsertableResourceListInterface.php b/src/Api/Operation/UpsertableResourceListInterface.php index 89f1323f..0f19fae4 100644 --- a/src/Api/Operation/UpsertableResourceListInterface.php +++ b/src/Api/Operation/UpsertableResourceListInterface.php @@ -23,5 +23,5 @@ interface UpsertableResourceListInterface * * @return \Traversable returns an iterable object, each entry corresponding to the response of the upserted resource */ - public function upsertList($resources): \Traversable; + public function upsertList(array|StreamInterface $resources): \Traversable; } diff --git a/src/Api/ProductApi.php b/src/Api/ProductApi.php index b8d6f4f1..7ea53680 100644 --- a/src/Api/ProductApi.php +++ b/src/Api/ProductApi.php @@ -18,31 +18,14 @@ */ class ProductApi implements ProductApiInterface { - const PRODUCTS_URI = 'api/rest/v1/products'; - const PRODUCT_URI = 'api/rest/v1/products/%s'; + public const PRODUCTS_URI = 'api/rest/v1/products'; + public const PRODUCT_URI = 'api/rest/v1/products/%s'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/ProductDraftApi.php b/src/Api/ProductDraftApi.php index 7ef80932..9656c524 100644 --- a/src/Api/ProductDraftApi.php +++ b/src/Api/ProductDraftApi.php @@ -17,26 +17,14 @@ */ class ProductDraftApi implements ProductDraftApiInterface { - const PRODUCT_DRAFT_URI = '/api/rest/v1/products/%s/draft'; - const PRODUCT_PROPOSAL_URI = '/api/rest/v1/products/%s/proposal'; - - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; + public const PRODUCT_DRAFT_URI = '/api/rest/v1/products/%s/draft'; + public const PRODUCT_PROPOSAL_URI = '/api/rest/v1/products/%s/proposal'; public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/ProductDraftUuidApi.php b/src/Api/ProductDraftUuidApi.php index 75c1c9d8..03b59eb1 100644 --- a/src/Api/ProductDraftUuidApi.php +++ b/src/Api/ProductDraftUuidApi.php @@ -17,18 +17,11 @@ class ProductDraftUuidApi implements ProductDraftUuidApiInterface public const PRODUCT_DRAFT_UUID_URI = '/api/rest/v1/products-uuid/%s/draft'; public const PRODUCT_PROPOSAL_UUID_URI = '/api/rest/v1/products-uuid/%s/proposal'; - protected ResourceClientInterface $resourceClient; - protected PageFactoryInterface $pageFactory; - protected ResourceCursorFactoryInterface $cursorFactory; - public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/ProductMediaFileApi.php b/src/Api/ProductMediaFileApi.php index daa8a882..06cf1fa1 100644 --- a/src/Api/ProductMediaFileApi.php +++ b/src/Api/ProductMediaFileApi.php @@ -20,39 +20,17 @@ */ class ProductMediaFileApi implements MediaFileApiInterface { - const MEDIA_FILES_URI = 'api/rest/v1/media-files'; - const MEDIA_FILE_URI = 'api/rest/v1/media-files/%s'; - const MEDIA_FILE_DOWNLOAD_URI = 'api/rest/v1/media-files/%s/download'; - const MEDIA_FILE_URI_CODE_REGEX = '~/api/rest/v1/media\-files/(?P.*)$~'; + public const MEDIA_FILES_URI = 'api/rest/v1/media-files'; + public const MEDIA_FILE_URI = 'api/rest/v1/media-files/%s'; + public const MEDIA_FILE_DOWNLOAD_URI = 'api/rest/v1/media-files/%s/download'; + public const MEDIA_FILE_URI_CODE_REGEX = '~/api/rest/v1/media\-files/(?P.*)$~'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** @var FileSystemInterface */ - private $fileSystem; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - * @param FileSystemInterface $fileSystem - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory, - FileSystemInterface $fileSystem + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory, + private FileSystemInterface $fileSystem ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; - $this->fileSystem = $fileSystem; } /** @@ -121,8 +99,6 @@ public function download(string $code): ResponseInterface /** * Extracts the code of a media-file from a creation response. * - * @param ResponseInterface $response - * * @throws RuntimeException if unable to extract the code * * @return mixed diff --git a/src/Api/ProductModelApi.php b/src/Api/ProductModelApi.php index 2b9c80d4..6c3e19ec 100644 --- a/src/Api/ProductModelApi.php +++ b/src/Api/ProductModelApi.php @@ -18,31 +18,14 @@ */ class ProductModelApi implements ProductModelApiInterface { - const PRODUCT_MODEL_URI = 'api/rest/v1/product-models/%s'; - const PRODUCT_MODELS_URI = 'api/rest/v1/product-models'; + public const PRODUCT_MODEL_URI = 'api/rest/v1/product-models/%s'; + public const PRODUCT_MODELS_URI = 'api/rest/v1/product-models'; - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; - - /** - * @param ResourceClientInterface $resourceClient - * @param PageFactoryInterface $pageFactory - * @param ResourceCursorFactoryInterface $cursorFactory - */ public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/ProductModelDraftApi.php b/src/Api/ProductModelDraftApi.php index a789074c..9f997f29 100644 --- a/src/Api/ProductModelDraftApi.php +++ b/src/Api/ProductModelDraftApi.php @@ -17,26 +17,14 @@ */ class ProductModelDraftApi implements ProductModelDraftApiInterface { - const PRODUCT_MODEL_DRAFT_URI = '/api/rest/v1/product-models/%s/draft'; - const PRODUCT_MODEL_PROPOSAL_URI = '/api/rest/v1/product-models/%s/proposal'; - - /** @var ResourceClientInterface */ - protected $resourceClient; - - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - protected $cursorFactory; + public const PRODUCT_MODEL_DRAFT_URI = '/api/rest/v1/product-models/%s/draft'; + public const PRODUCT_MODEL_PROPOSAL_URI = '/api/rest/v1/product-models/%s/proposal'; public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + protected ResourceClientInterface $resourceClient, + protected PageFactoryInterface $pageFactory, + protected ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/ProductUuidApi.php b/src/Api/ProductUuidApi.php index e542e2aa..5a316cfe 100644 --- a/src/Api/ProductUuidApi.php +++ b/src/Api/ProductUuidApi.php @@ -1,4 +1,5 @@ resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } public function listPerPage(int $limit = 100, bool $withCount = false, array $queryParameters = []): PageInterface { diff --git a/src/Api/ProductUuidApiInterface.php b/src/Api/ProductUuidApiInterface.php index 26df21c1..858e2dbf 100644 --- a/src/Api/ProductUuidApiInterface.php +++ b/src/Api/ProductUuidApiInterface.php @@ -1,4 +1,5 @@ resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/ReferenceEntityApi.php b/src/Api/ReferenceEntityApi.php index 0351ba39..11a440ed 100644 --- a/src/Api/ReferenceEntityApi.php +++ b/src/Api/ReferenceEntityApi.php @@ -16,26 +16,14 @@ */ class ReferenceEntityApi implements ReferenceEntityApiInterface { - const REFERENCE_ENTITY_URI = 'api/rest/v1/reference-entities/%s'; - const REFERENCE_ENTITIES_URI= 'api/rest/v1/reference-entities'; - - /** @var ResourceClientInterface */ - private $resourceClient; - - /** @var PageFactoryInterface */ - private $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - private $cursorFactory; + public const REFERENCE_ENTITY_URI = 'api/rest/v1/reference-entities/%s'; + public const REFERENCE_ENTITIES_URI = 'api/rest/v1/reference-entities'; public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Api/ReferenceEntityAttributeApi.php b/src/Api/ReferenceEntityAttributeApi.php index bc96dfa1..b5e0819b 100644 --- a/src/Api/ReferenceEntityAttributeApi.php +++ b/src/Api/ReferenceEntityAttributeApi.php @@ -13,15 +13,12 @@ */ class ReferenceEntityAttributeApi implements ReferenceEntityAttributeApiInterface { - const REFERENCE_ENTITY_ATTRIBUTE_URI = 'api/rest/v1/reference-entities/%s/attributes/%s'; - const REFERENCE_ENTITY_ATTRIBUTES_URI = 'api/rest/v1/reference-entities/%s/attributes'; + public const REFERENCE_ENTITY_ATTRIBUTE_URI = 'api/rest/v1/reference-entities/%s/attributes/%s'; + public const REFERENCE_ENTITY_ATTRIBUTES_URI = 'api/rest/v1/reference-entities/%s/attributes'; - /** @var ResourceClientInterface */ - private $resourceClient; - - public function __construct(ResourceClientInterface $resourceClient) - { - $this->resourceClient = $resourceClient; + public function __construct( + private ResourceClientInterface $resourceClient + ) { } /** diff --git a/src/Api/ReferenceEntityAttributeOptionApi.php b/src/Api/ReferenceEntityAttributeOptionApi.php index 915fcf81..29729d13 100644 --- a/src/Api/ReferenceEntityAttributeOptionApi.php +++ b/src/Api/ReferenceEntityAttributeOptionApi.php @@ -13,15 +13,12 @@ */ class ReferenceEntityAttributeOptionApi implements ReferenceEntityAttributeOptionApiInterface { - const REFERENCE_ENTITY_ATTRIBUTE_OPTION_URI = 'api/rest/v1/reference-entities/%s/attributes/%s/options/%s'; - const REFERENCE_ENTITY_ATTRIBUTE_OPTIONS_URI = 'api/rest/v1/reference-entities/%s/attributes/%s/options'; + public const REFERENCE_ENTITY_ATTRIBUTE_OPTION_URI = 'api/rest/v1/reference-entities/%s/attributes/%s/options/%s'; + public const REFERENCE_ENTITY_ATTRIBUTE_OPTIONS_URI = 'api/rest/v1/reference-entities/%s/attributes/%s/options'; - /** @var ResourceClientInterface */ - private $resourceClient; - - public function __construct(ResourceClientInterface $resourceClient) - { - $this->resourceClient = $resourceClient; + public function __construct( + private ResourceClientInterface $resourceClient + ) { } /** diff --git a/src/Api/ReferenceEntityMediaFileApi.php b/src/Api/ReferenceEntityMediaFileApi.php index 2c99a2da..30fa52e5 100644 --- a/src/Api/ReferenceEntityMediaFileApi.php +++ b/src/Api/ReferenceEntityMediaFileApi.php @@ -16,19 +16,13 @@ */ class ReferenceEntityMediaFileApi implements ReferenceEntityMediaFileApiInterface { - const MEDIA_FILE_DOWNLOAD_URI = 'api/rest/v1/reference-entities-media-files/%s'; - const MEDIA_FILE_CREATE_URI = 'api/rest/v1/reference-entities-media-files'; + public const MEDIA_FILE_DOWNLOAD_URI = 'api/rest/v1/reference-entities-media-files/%s'; + public const MEDIA_FILE_CREATE_URI = 'api/rest/v1/reference-entities-media-files'; - /** @var ResourceClientInterface */ - private $resourceClient; - - /** @var FileSystemInterface */ - private $fileSystem; - - public function __construct(ResourceClientInterface $resourceClient, FileSystemInterface $fileSystem) - { - $this->resourceClient = $resourceClient; - $this->fileSystem = $fileSystem; + public function __construct( + private ResourceClientInterface $resourceClient, + private FileSystemInterface $fileSystem + ) { } /** @@ -63,11 +57,7 @@ public function create($mediaFile): string /** * Extracts the code of a media-file from a creation response. * - * @param ResponseInterface $response - * * @throws RuntimeException if unable to extract the code - * - * @return string */ private function extractCodeFromCreationResponse(ResponseInterface $response): string { diff --git a/src/Api/ReferenceEntityRecordApi.php b/src/Api/ReferenceEntityRecordApi.php index dce21e24..95712961 100644 --- a/src/Api/ReferenceEntityRecordApi.php +++ b/src/Api/ReferenceEntityRecordApi.php @@ -16,26 +16,14 @@ */ class ReferenceEntityRecordApi implements ReferenceEntityRecordApiInterface { - const REFERENCE_ENTITY_RECORD_URI = 'api/rest/v1/reference-entities/%s/records/%s'; - const REFERENCE_ENTITY_RECORDS_URI = 'api/rest/v1/reference-entities/%s/records'; - - /** @var ResourceClientInterface */ - private $resourceClient; - - /** @var PageFactoryInterface */ - private $pageFactory; - - /** @var ResourceCursorFactoryInterface */ - private $cursorFactory; + public const REFERENCE_ENTITY_RECORD_URI = 'api/rest/v1/reference-entities/%s/records/%s'; + public const REFERENCE_ENTITY_RECORDS_URI = 'api/rest/v1/reference-entities/%s/records'; public function __construct( - ResourceClientInterface $resourceClient, - PageFactoryInterface $pageFactory, - ResourceCursorFactoryInterface $cursorFactory + private ResourceClientInterface $resourceClient, + private PageFactoryInterface $pageFactory, + private ResourceCursorFactoryInterface $cursorFactory ) { - $this->resourceClient = $resourceClient; - $this->pageFactory = $pageFactory; - $this->cursorFactory = $cursorFactory; } /** diff --git a/src/Cache/CacheInterface.php b/src/Cache/CacheInterface.php index 3754bc34..767a202c 100644 --- a/src/Cache/CacheInterface.php +++ b/src/Cache/CacheInterface.php @@ -16,8 +16,6 @@ public function get(string $key): ?array; /** * @param string $key Key of the cached resource * @param mixed $value The cached resource - * - * @return void */ - public function set(string $key, $value): void; + public function set(string $key, mixed $value): void; } diff --git a/src/Cache/LRUCache.php b/src/Cache/LRUCache.php index ba7f50df..9a4f6b91 100644 --- a/src/Cache/LRUCache.php +++ b/src/Cache/LRUCache.php @@ -6,15 +6,14 @@ class LRUCache implements CacheInterface { - private int $maxItems; private array $items = []; /** * @param int $maxItems Maximum number of allowed cache items. */ - public function __construct(int $maxItems = 100) - { - $this->maxItems = $maxItems; + public function __construct( + private int $maxItems = 100 + ) { } /** @@ -46,10 +45,8 @@ public function set(string $key, $value): void if ($diff <= 0) { return; } - - reset($this->items); for ($i = 0; $i < $diff; $i++) { - unset($this->items[key($this->items)]); + unset($this->items[array_key_first($this->items)]); next($this->items); } } diff --git a/src/Client/AuthenticatedHttpClient.php b/src/Client/AuthenticatedHttpClient.php index 58b6c381..1232e648 100644 --- a/src/Client/AuthenticatedHttpClient.php +++ b/src/Client/AuthenticatedHttpClient.php @@ -22,23 +22,11 @@ */ class AuthenticatedHttpClient implements HttpClientInterface { - /** @var HttpClient */ - protected $basicHttpClient; - - /** @var AuthenticationApiInterface */ - protected $authenticationApi; - - /** @var Authentication */ - protected $authentication; - public function __construct( - HttpClient $basicHttpClient, - AuthenticationApiInterface $authenticationApi, - Authentication $authentication + protected HttpClient $basicHttpClient, + protected AuthenticationApiInterface $authenticationApi, + protected Authentication $authentication ) { - $this->basicHttpClient = $basicHttpClient; - $this->authenticationApi = $authenticationApi; - $this->authentication = $authentication; } /** @@ -60,7 +48,7 @@ public function sendRequest(string $httpMethod, $uri, array $headers = [], $body } try { - $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); + $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); $response = $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); } catch (UnauthorizedHttpException $e) { $tokens = $this->renewTokens($e); @@ -69,8 +57,8 @@ public function sendRequest(string $httpMethod, $uri, array $headers = [], $body ->setAccessToken($tokens['access_token']) ->setRefreshToken($tokens['refresh_token']); - $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); - $response = $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); + $headers['Authorization'] = sprintf('Bearer %s', $this->authentication->getAccessToken()); + $response = $this->basicHttpClient->sendRequest($httpMethod, $uri, $headers, $body); } return $response; @@ -84,7 +72,7 @@ private function renewTokens(UnauthorizedHttpException $unauthorizedHttpExceptio $this->authentication->getSecret(), $this->authentication->getRefreshToken() ); - } catch (UnprocessableEntityHttpException $e) { + } catch (UnprocessableEntityHttpException) { throw $unauthorizedHttpException; } } diff --git a/src/Client/CachedResourceClient.php b/src/Client/CachedResourceClient.php index 684a639c..906adab9 100644 --- a/src/Client/CachedResourceClient.php +++ b/src/Client/CachedResourceClient.php @@ -13,15 +13,10 @@ */ class CachedResourceClient implements ResourceClientInterface { - private ResourceClientInterface $resourceClient; - private CacheInterface $cache; - public function __construct( - ResourceClientInterface $resourceClient, - CacheInterface $cache + private ResourceClientInterface $resourceClient, + private CacheInterface $cache ) { - $this->resourceClient = $resourceClient; - $this->cache = $cache; } /** @@ -29,7 +24,7 @@ public function __construct( */ public function getResource(string $uri, array $uriParameters = [], array $queryParameters = []): array { - $cacheKey = md5($uri.implode('', $uriParameters)); + $cacheKey = md5($uri . implode('', $uriParameters)); if ($cachedItem = $this->cache->get($cacheKey)) { return $cachedItem; @@ -44,8 +39,13 @@ public function getResource(string $uri, array $uriParameters = [], array $query /** * {@inheritdoc} */ - public function getResources(string $uri, array $uriParameters = [], ?int $limit = 100, ?bool $withCount = false, array $queryParameters = []): array - { + public function getResources( + string $uri, + array $uriParameters = [], + ?int $limit = 100, + ?bool $withCount = false, + array $queryParameters = [] + ): array { return $this->resourceClient->getResources($uri, $uriParameters, $limit, $withCount, $queryParameters); } diff --git a/src/Client/HttpClient.php b/src/Client/HttpClient.php index 0f6a6175..58e86f69 100644 --- a/src/Client/HttpClient.php +++ b/src/Client/HttpClient.php @@ -17,36 +17,27 @@ */ class HttpClient implements HttpClientInterface { - const HTTP_OK = 200; - const HTTP_CREATED = 201; - const HTTP_NO_CONTENT = 204; - const HTTP_BAD_REQUEST = 400; - const HTTP_UNAUTHORIZED = 401; - const HTTP_FORBIDDEN = 403; - const HTTP_NOT_FOUND = 404; - const HTTP_METHOD_NOT_ALLOWED = 405; - const HTTP_NOT_ACCEPTABLE = 406; - const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; - const HTTP_UNPROCESSABLE_ENTITY = 422; - const HTTP_TOO_MANY_REQUESTS = 429; - - protected ClientInterface $httpClient; - protected RequestFactoryInterface $requestFactory; + public const HTTP_OK = 200; + public const HTTP_CREATED = 201; + public const HTTP_NO_CONTENT = 204; + public const HTTP_BAD_REQUEST = 400; + public const HTTP_UNAUTHORIZED = 401; + public const HTTP_FORBIDDEN = 403; + public const HTTP_NOT_FOUND = 404; + public const HTTP_METHOD_NOT_ALLOWED = 405; + public const HTTP_NOT_ACCEPTABLE = 406; + public const HTTP_UNSUPPORTED_MEDIA_TYPE = 415; + public const HTTP_UNPROCESSABLE_ENTITY = 422; + public const HTTP_TOO_MANY_REQUESTS = 429; protected HttpExceptionHandler $httpExceptionHandler; - private StreamFactoryInterface $streamFactory; - private Options $options; public function __construct( - ClientInterface $httpClient, - RequestFactoryInterface $requestFactory, - StreamFactoryInterface $streamFactory, - Options $options + protected ClientInterface $httpClient, + protected RequestFactoryInterface $requestFactory, + private StreamFactoryInterface $streamFactory, + private Options $options ) { - $this->httpClient = $httpClient; - $this->requestFactory = $requestFactory; - $this->streamFactory = $streamFactory; $this->httpExceptionHandler = new HttpExceptionHandler(); - $this->options = $options; } /** @@ -74,8 +65,7 @@ public function sendRequest(string $httpMethod, $uri, array $headers = [], $body } $response = $this->httpClient->sendRequest($request); - $response = $this->httpExceptionHandler->transformResponseToException($request, $response); - return $response; + return $this->httpExceptionHandler->transformResponseToException($request, $response); } } diff --git a/src/Client/HttpExceptionHandler.php b/src/Client/HttpExceptionHandler.php index 85af429c..ff6a0602 100644 --- a/src/Client/HttpExceptionHandler.php +++ b/src/Client/HttpExceptionHandler.php @@ -94,10 +94,6 @@ public function transformResponseToException( /** * Returns the response message, or the reason phrase if there is none. - * - * @param ResponseInterface $response - * - * @return string */ protected function getResponseMessage(ResponseInterface $response): string { diff --git a/src/Client/Options.php b/src/Client/Options.php index 2ad7c006..ff53ca9f 100644 --- a/src/Client/Options.php +++ b/src/Client/Options.php @@ -8,11 +8,9 @@ class Options { - private array $options; - - private function __construct(array $options) - { - $this->options = $options; + private function __construct( + private array $options + ) { } public static function fromArray(array $options): self diff --git a/src/Client/ResourceClient.php b/src/Client/ResourceClient.php index 5aef3ffe..7d56f530 100644 --- a/src/Client/ResourceClient.php +++ b/src/Client/ResourceClient.php @@ -21,21 +21,12 @@ */ class ResourceClient implements ResourceClientInterface { - protected HttpClientInterface $httpClient; - protected UriGeneratorInterface $uriGenerator; - protected MultipartStreamBuilderFactory $multipartStreamBuilderFactory; - protected UpsertResourceListResponseFactory $upsertListResponseFactory; - public function __construct( - HttpClientInterface $httpClient, - UriGeneratorInterface $uriGenerator, - MultipartStreamBuilderFactory $multipartStreamBuilderFactory, - UpsertResourceListResponseFactory $upsertListResponseFactory + protected HttpClientInterface $httpClient, + protected UriGeneratorInterface $uriGenerator, + protected MultipartStreamBuilderFactory $multipartStreamBuilderFactory, + protected UpsertResourceListResponseFactory $upsertListResponseFactory ) { - $this->httpClient = $httpClient; - $this->uriGenerator = $uriGenerator; - $this->multipartStreamBuilderFactory = $multipartStreamBuilderFactory; - $this->upsertListResponseFactory = $upsertListResponseFactory; } /** diff --git a/src/Client/ResourceClientInterface.php b/src/Client/ResourceClientInterface.php index 04f94066..4cdd408e 100644 --- a/src/Client/ResourceClientInterface.php +++ b/src/Client/ResourceClientInterface.php @@ -48,7 +48,13 @@ public function getResource(string $uri, array $uriParameters = [], array $query * * @return array */ - public function getResources(string $uri, array $uriParameters = [], ?int $limit = 100, ?bool $withCount = false, array $queryParameters = []): array; + public function getResources( + string $uri, + array $uriParameters = [], + ?int $limit = 100, + ?bool $withCount = false, + array $queryParameters = [] + ): array; /** * Creates a resource. @@ -128,7 +134,7 @@ public function upsertAndReturnResource(string $uri, array $uriParameters = [], * * @return \Traversable returns an iterable object, each entry corresponding to the response of the upserted resource */ - public function upsertStreamResourceList(string $uri, array $uriParameters = [], $resources = []) : \Traversable; + public function upsertStreamResourceList(string $uri, array $uriParameters = [], $resources = []): \Traversable; /** * Updates or creates several resources using a single JSON string for the request and the response. diff --git a/src/Exception/HttpException.php b/src/Exception/HttpException.php index b36fb225..9e2ce382 100644 --- a/src/Exception/HttpException.php +++ b/src/Exception/HttpException.php @@ -14,19 +14,18 @@ */ class HttpException extends RuntimeException { - /** @var RequestInterface */ - protected $request; - /** @var ResponseInterface */ protected $response; - public function __construct(string $message, RequestInterface $request, ResponseInterface $response, ?\Exception $previous = null) - { + public function __construct( + string $message, + protected RequestInterface $request, + ResponseInterface $response, + ?\Exception $previous = null + ) { $message .= ' ' . $this->getAdditionalInformationMessage(); parent::__construct($message, $response->getStatusCode(), $previous); - - $this->request = $request; $this->response = $response; } diff --git a/src/Exception/UploadAssetReferenceFileErrorException.php b/src/Exception/UploadAssetReferenceFileErrorException.php index 15147241..83062abd 100644 --- a/src/Exception/UploadAssetReferenceFileErrorException.php +++ b/src/Exception/UploadAssetReferenceFileErrorException.php @@ -14,18 +14,14 @@ */ class UploadAssetReferenceFileErrorException extends RuntimeException { - /** @var array */ - private $errors; - /** * @param string $message - * @param array $errors */ - public function __construct($message, array $errors) - { + public function __construct( + $message, + private array $errors + ) { parent::__construct($message); - - $this->errors = $errors; } public function getErrors(): array diff --git a/src/MultipartStream/MultipartStreamBuilder.php b/src/MultipartStream/MultipartStreamBuilder.php index c8ede8fe..7ebca464 100644 --- a/src/MultipartStream/MultipartStreamBuilder.php +++ b/src/MultipartStream/MultipartStreamBuilder.php @@ -14,24 +14,20 @@ */ class MultipartStreamBuilder { - /** @var StreamFactoryInterface */ - private $streamFactory; - /** @var MimetypeHelper */ private $mimetypeHelper; - /** @var string */ - private $boundary; + private ?string $boundary = null; /** * @var array Element where each Element is an array with keys ['contents', 'headers', 'filename'] */ - private $data = []; + private array $data = []; - public function __construct(StreamFactoryInterface $streamFactory) - { - $this->streamFactory = $streamFactory; + public function __construct( + private StreamFactoryInterface $streamFactory + ) { } /** @@ -68,7 +64,7 @@ public function addResource(string $name, $resource, array $options = []) if (empty($options['filename'])) { $options['filename'] = null; $uri = $stream->getMetadata('uri'); - if (substr($uri, 0, 6) !== 'php://') { + if (!str_starts_with($uri, 'php://')) { $options['filename'] = $uri; } } @@ -89,8 +85,8 @@ public function build() $streams = ''; foreach ($this->data as $data) { // Add start and headers - $streams .= "--{$this->getBoundary()}\r\n". - $this->getHeaders($data['headers'])."\r\n"; + $streams .= "--{$this->getBoundary()}\r\n" . + $this->getHeaders($data['headers']) . "\r\n"; // Convert the stream to string /* @var $contentStream StreamInterface */ @@ -131,25 +127,21 @@ private function prepareHeaders($name, StreamInterface $stream, $filename, array } // Set a default content-length header if one was not provided - if (!$this->hasHeader($headers, 'content-length')) { - if ($length = $stream->getSize()) { - $headers['Content-Length'] = (string) $length; - } + if (!$this->hasHeader($headers, 'content-length') && ($length = $stream->getSize())) { + $headers['Content-Length'] = (string) $length; } // Set a default Content-Type if one was not provided - if (!$this->hasHeader($headers, 'content-type') && $hasFilename) { - if ($type = $this->getMimetypeHelper()->getMimetypeFromFilename($filename)) { - $headers['Content-Type'] = $type; - } + if (!$this->hasHeader($headers, 'content-type') && $hasFilename && ($type = $this->getMimetypeHelper()->getMimetypeFromFilename( + $filename + ))) { + $headers['Content-Type'] = $type; } } /** * Get the headers formatted for the HTTP message. * - * @param array $headers - * * @return string */ private function getHeaders(array $headers) @@ -165,9 +157,7 @@ private function getHeaders(array $headers) /** * Check if header exist. * - * @param array $headers * @param string $key case insensitive - * * @return bool */ private function hasHeader(array $headers, $key) @@ -223,8 +213,6 @@ private function getMimetypeHelper() /** * If you have custom file extension you may overwrite the default MimetypeHelper with your own. * - * @param MimetypeHelper $mimetypeHelper - * * @return MultipartStreamBuilder */ public function setMimetypeHelper(MimetypeHelper $mimetypeHelper) @@ -270,7 +258,7 @@ private function basename($path) $path = rtrim($path, $separators); // Returns the trailing part of the $path starting after one of the directory separators. - $filename = preg_match('@[^'.preg_quote($separators, '@').']+$@', $path, $matches) ? $matches[0] : ''; + $filename = preg_match('@[^' . preg_quote($separators, '@') . ']+$@', $path, $matches) ? $matches[0] : ''; return $filename; } diff --git a/src/Pagination/Page.php b/src/Pagination/Page.php index a4a8cb28..15e616e0 100644 --- a/src/Pagination/Page.php +++ b/src/Pagination/Page.php @@ -13,43 +13,15 @@ */ class Page implements PageInterface { - /** @var PageFactoryInterface */ - protected $pageFactory; - - /** @var HttpClientInterface */ - protected $httpClient; - - /** @var string */ - protected $firstLink; - - /** @var string */ - protected $previousLink; - - /** @var string */ - protected $nextLink; - - /** @var integer */ - protected $count; - - /** @var array */ - protected $items; - public function __construct( - PageFactoryInterface $pageFactory, - HttpClientInterface $httpClient, - string $firstLink, - ?string$previousLink, - ?string $nextLink, - ?int $count, - array $items + protected PageFactoryInterface $pageFactory, + protected HttpClientInterface $httpClient, + protected string $firstLink, + protected ?string$previousLink, + protected ?string $nextLink, + protected ?int $count, + protected array $items ) { - $this->pageFactory = $pageFactory; - $this->httpClient = $httpClient; - $this->firstLink = $firstLink; - $this->previousLink = $previousLink; - $this->nextLink = $nextLink; - $this->count = $count; - $this->items = $items; } /** diff --git a/src/Pagination/PageFactory.php b/src/Pagination/PageFactory.php index 5ba2e826..0ebb2ce9 100644 --- a/src/Pagination/PageFactory.php +++ b/src/Pagination/PageFactory.php @@ -13,12 +13,9 @@ */ class PageFactory implements PageFactoryInterface { - /** @var HttpClientInterface */ - protected $httpClient; - - public function __construct(HttpClientInterface $httpClient) - { - $this->httpClient = $httpClient; + public function __construct( + protected HttpClientInterface $httpClient + ) { } /** diff --git a/src/Pagination/PaginationParameter.php b/src/Pagination/PaginationParameter.php index 5c4d8b6b..07e6da3b 100644 --- a/src/Pagination/PaginationParameter.php +++ b/src/Pagination/PaginationParameter.php @@ -11,7 +11,7 @@ */ final class PaginationParameter { - const SEARCH = 'search'; - const LIMIT = 'limit'; - const WITH_COUNT = 'with_count'; + public const SEARCH = 'search'; + public const LIMIT = 'limit'; + public const WITH_COUNT = 'with_count'; } diff --git a/src/Pagination/ResourceCursor.php b/src/Pagination/ResourceCursor.php index 15131e5b..470ee924 100644 --- a/src/Pagination/ResourceCursor.php +++ b/src/Pagination/ResourceCursor.php @@ -12,17 +12,14 @@ class ResourceCursor implements ResourceCursorInterface { protected PageInterface $currentPage; - protected PageInterface $firstPage; - /** @var null|int */ - protected $pageSize; protected int $currentIndex = 0; protected int $totalIndex = 0; - public function __construct(?int $pageSize, PageInterface $firstPage) - { - $this->firstPage = $firstPage; + public function __construct( + protected ?int $pageSize, + protected PageInterface $firstPage + ) { $this->currentPage = $firstPage; - $this->pageSize = $pageSize; } /** diff --git a/src/Routing/UriGenerator.php b/src/Routing/UriGenerator.php index 9876dab2..783cb3f4 100644 --- a/src/Routing/UriGenerator.php +++ b/src/Routing/UriGenerator.php @@ -49,8 +49,6 @@ public function generate($path, array $uriParameters = [], array $queryParameter /** * Transforms boolean query parameters as string 'true' or 'false' instead of 0 or 1. * - * @param array $queryParameters - * * @return array */ protected function booleanQueryParametersAsString(array $queryParameters) diff --git a/src/Search/Operator.php b/src/Search/Operator.php index 959ecc30..a3338295 100644 --- a/src/Search/Operator.php +++ b/src/Search/Operator.php @@ -11,33 +11,33 @@ */ final class Operator { - const EQUAL = '='; - const NOT_EQUAL = '!='; - const GREATER_THAN = '>'; - const GREATER_THAN_OR_EQUAL = '>='; - const LOWER_THAN = '<'; - const LOWER_THAN_OR_EQUAL = '<='; - const IN = 'IN'; - const NOT_IN = 'NOT IN'; - const IN_OR_UNCLASSIFIED = 'IN OR UNCLASSIFIED'; - const IN_CHILDREN = 'IN CHILDREN'; - const NOT_IN_CHILDREN = 'NOT IN CHILDREN'; - const UNCLASSIFIED = 'UNCLASSIFIED'; - const GREATER_THAN_ON_ALL_LOCALES = 'GREATER THAN ON ALL LOCALES'; - const GREATER_OR_EQUALS_THAN_ON_ALL_LOCALES = 'GREATER OR EQUALS THAN ON ALL LOCALES'; - const LOWER_THAN_ON_ALL_LOCALES = 'LOWER THAN ON ALL LOCALES'; - const LOWER_OR_EQUALS_THAN_ON_ALL_LOCALES = 'LOWER OR EQUALS THAN ON ALL LOCALES'; - const IS_EMPTY = 'EMPTY'; - const NOT_EMPTY = 'NOT EMPTY'; - const BETWEEN = 'BETWEEN'; - const NOT_BETWEEN = 'NOT BETWEEN'; - const SINCE_LAST_N_DAYS = 'SINCE LAST N DAYS'; - const STARTS_WITH = 'STARTS WITH'; - const ENDS_WITH = 'ENDS WITH'; - const CONTAINS = 'CONTAINS'; - const DOES_NOT_CONTAIN = 'DOES NOT CONTAIN'; - const AT_LEAST_COMPLETE = 'AT LEAST COMPLETE'; - const AT_LEAST_INCOMPLETE = 'AT LEAST INCOMPLETE'; - const ALL_COMPLETE = 'ALL COMPLETE'; - const ALL_INCOMPLETE = 'ALL INCOMPLETE'; + public const EQUAL = '='; + public const NOT_EQUAL = '!='; + public const GREATER_THAN = '>'; + public const GREATER_THAN_OR_EQUAL = '>='; + public const LOWER_THAN = '<'; + public const LOWER_THAN_OR_EQUAL = '<='; + public const IN = 'IN'; + public const NOT_IN = 'NOT IN'; + public const IN_OR_UNCLASSIFIED = 'IN OR UNCLASSIFIED'; + public const IN_CHILDREN = 'IN CHILDREN'; + public const NOT_IN_CHILDREN = 'NOT IN CHILDREN'; + public const UNCLASSIFIED = 'UNCLASSIFIED'; + public const GREATER_THAN_ON_ALL_LOCALES = 'GREATER THAN ON ALL LOCALES'; + public const GREATER_OR_EQUALS_THAN_ON_ALL_LOCALES = 'GREATER OR EQUALS THAN ON ALL LOCALES'; + public const LOWER_THAN_ON_ALL_LOCALES = 'LOWER THAN ON ALL LOCALES'; + public const LOWER_OR_EQUALS_THAN_ON_ALL_LOCALES = 'LOWER OR EQUALS THAN ON ALL LOCALES'; + public const IS_EMPTY = 'EMPTY'; + public const NOT_EMPTY = 'NOT EMPTY'; + public const BETWEEN = 'BETWEEN'; + public const NOT_BETWEEN = 'NOT BETWEEN'; + public const SINCE_LAST_N_DAYS = 'SINCE LAST N DAYS'; + public const STARTS_WITH = 'STARTS WITH'; + public const ENDS_WITH = 'ENDS WITH'; + public const CONTAINS = 'CONTAINS'; + public const DOES_NOT_CONTAIN = 'DOES NOT CONTAIN'; + public const AT_LEAST_COMPLETE = 'AT LEAST COMPLETE'; + public const AT_LEAST_INCOMPLETE = 'AT LEAST INCOMPLETE'; + public const ALL_COMPLETE = 'ALL COMPLETE'; + public const ALL_INCOMPLETE = 'ALL INCOMPLETE'; } diff --git a/src/Search/SearchBuilder.php b/src/Search/SearchBuilder.php index 22e411fc..c48ba97a 100644 --- a/src/Search/SearchBuilder.php +++ b/src/Search/SearchBuilder.php @@ -24,12 +24,10 @@ class SearchBuilder * @param string $operator operator of the filter. * @param mixed|null $value value of the filter. Should not be defined for certain specifics operators. * @param array $options optionals parameters to apply to the filter (as scope or locale). - * - * @return SearchBuilder */ public function addFilter(string $property, string $operator, $value = null, array $options = []): self { - $filter = ['operator'=> $operator]; + $filter = ['operator' => $operator]; if (null !== $value) { $filter['value'] = $value; diff --git a/src/Stream/LineStreamReader.php b/src/Stream/LineStreamReader.php index 4da3a989..d934235d 100644 --- a/src/Stream/LineStreamReader.php +++ b/src/Stream/LineStreamReader.php @@ -16,8 +16,6 @@ class LineStreamReader /** * Gets the next line of a stream. * - * @param StreamInterface $stream - * * @return string|null returns the line, or null if the stream is not readable or at the end */ public function getNextLine(StreamInterface $stream): ?string @@ -26,7 +24,7 @@ public function getNextLine(StreamInterface $stream): ?string return null; } - $line = ''; + $line = ''; $isEol = false; while (!$stream->eof() && !$isEol) { $character = $stream->read(1); diff --git a/src/Stream/MultipartStreamBuilderFactory.php b/src/Stream/MultipartStreamBuilderFactory.php index c709a608..5ef68ca6 100644 --- a/src/Stream/MultipartStreamBuilderFactory.php +++ b/src/Stream/MultipartStreamBuilderFactory.php @@ -14,12 +14,9 @@ */ class MultipartStreamBuilderFactory { - /** @var StreamFactoryInterface */ - protected $streamFactory; - - public function __construct(StreamFactoryInterface $streamFactory) - { - $this->streamFactory = $streamFactory; + public function __construct( + protected StreamFactoryInterface $streamFactory + ) { } public function create(): MultipartStreamBuilder diff --git a/src/Stream/UpsertResourceListResponse.php b/src/Stream/UpsertResourceListResponse.php index a50df2e9..cfba42c7 100644 --- a/src/Stream/UpsertResourceListResponse.php +++ b/src/Stream/UpsertResourceListResponse.php @@ -18,22 +18,16 @@ */ class UpsertResourceListResponse implements \Iterator { - /** @var StreamInterface */ - protected $bodyStream; - - /** @var LineStreamReader */ - protected $streamReader; - /** @var int */ protected $lineNumber = 1; /** @var string */ protected $line; - public function __construct(StreamInterface $bodyStream, LineStreamReader $streamReader) - { - $this->bodyStream = $bodyStream; - $this->streamReader = $streamReader; + public function __construct( + protected StreamInterface $bodyStream, + protected LineStreamReader $streamReader + ) { } /** diff --git a/src/Stream/UpsertResourceListResponseFactory.php b/src/Stream/UpsertResourceListResponseFactory.php index f2e82592..61777220 100644 --- a/src/Stream/UpsertResourceListResponseFactory.php +++ b/src/Stream/UpsertResourceListResponseFactory.php @@ -13,7 +13,7 @@ */ class UpsertResourceListResponseFactory { - public function create(StreamInterface $bodyStream): UpsertResourceListResponse + public function create(StreamInterface $bodyStream): UpsertResourceListResponse { return new UpsertResourceListResponse($bodyStream, new LineStreamReader()); } diff --git a/tests/Api/ApiTestCase.php b/tests/Api/ApiTestCase.php index 9ae97631..61867e02 100644 --- a/tests/Api/ApiTestCase.php +++ b/tests/Api/ApiTestCase.php @@ -28,7 +28,7 @@ protected function setUp(): void $this->server->start(); $this->server->setResponseOfPath( - '/'. AuthenticationApi::TOKEN_URI, + '/' . AuthenticationApi::TOKEN_URI, new ResponseStack( new Response($this->getAuthenticatedJson()) ) diff --git a/tests/Api/AppCatalog/CreateAppCatalogIntegration.php b/tests/Api/AppCatalog/CreateAppCatalogIntegration.php index d4d55b33..6a84e9cd 100644 --- a/tests/Api/AppCatalog/CreateAppCatalogIntegration.php +++ b/tests/Api/AppCatalog/CreateAppCatalogIntegration.php @@ -1,4 +1,5 @@ server->setResponseOfPath( - '/'.AppCatalogApi::APP_CATALOGS_URI, + '/' . AppCatalogApi::APP_CATALOGS_URI, new ResponseStack( new Response($expectedJson, [], HttpClient::HTTP_CREATED) ) diff --git a/tests/Api/AppCatalog/DeleteAppCatalogIntegration.php b/tests/Api/AppCatalog/DeleteAppCatalogIntegration.php index 75c4f214..72f7fd48 100644 --- a/tests/Api/AppCatalog/DeleteAppCatalogIntegration.php +++ b/tests/Api/AppCatalog/DeleteAppCatalogIntegration.php @@ -1,4 +1,5 @@ server->setResponseOfPath( - '/'.sprintf(AppCatalogApi::APP_CATALOG_URI, $catalogId), + '/' . sprintf(AppCatalogApi::APP_CATALOG_URI, $catalogId), new ResponseStack( new Response('', [], HttpClient::HTTP_NO_CONTENT) ) diff --git a/tests/Api/AppCatalog/GetAppCatalogIntegration.php b/tests/Api/AppCatalog/GetAppCatalogIntegration.php index 0cd474d2..9e4921c6 100644 --- a/tests/Api/AppCatalog/GetAppCatalogIntegration.php +++ b/tests/Api/AppCatalog/GetAppCatalogIntegration.php @@ -1,4 +1,5 @@ server->setResponseOfPath( - '/'.sprintf(AppCatalogApi::APP_CATALOG_URI, $catalogId), + '/' . sprintf(AppCatalogApi::APP_CATALOG_URI, $catalogId), new ResponseStack( new Response($this->getACatalog(), [], HttpClient::HTTP_OK) ) diff --git a/tests/Api/AppCatalog/ListAppCatalogIntegration.php b/tests/Api/AppCatalog/ListAppCatalogIntegration.php index 9b05858d..03eec19c 100644 --- a/tests/Api/AppCatalog/ListAppCatalogIntegration.php +++ b/tests/Api/AppCatalog/ListAppCatalogIntegration.php @@ -1,4 +1,5 @@ server->setResponseOfPath( - '/'.sprintf(AppCatalogApi::APP_CATALOG_URI, $catalogId), + '/' . sprintf(AppCatalogApi::APP_CATALOG_URI, $catalogId), new ResponseStack( new Response($expectedJson, [], HttpClient::HTTP_OK) ) diff --git a/tests/Api/AppCatalogProduct/ListAppCatalogProductIntegration.php b/tests/Api/AppCatalogProduct/ListAppCatalogProductIntegration.php index 6891c0e5..51f7199e 100644 --- a/tests/Api/AppCatalogProduct/ListAppCatalogProductIntegration.php +++ b/tests/Api/AppCatalogProduct/ListAppCatalogProductIntegration.php @@ -1,4 +1,5 @@ server->setResponseOfPath( - '/'. sprintf(AssetApi::ASSET_URI, 'packshot', 'battleship'), + '/' . sprintf(AssetApi::ASSET_URI, 'packshot', 'battleship'), new ResponseStack( new Response($this->getAsset(), [], 200) ) @@ -32,7 +32,7 @@ public function test_get_asset() public function test_get_unknown_asset() { $this->server->setResponseOfPath( - '/'. sprintf(AssetApi::ASSET_URI, 'packshot', 'peace-sheep'), + '/' . sprintf(AssetApi::ASSET_URI, 'packshot', 'peace-sheep'), new ResponseStack( new Response('{"code": 404, "message":"Asset \"peace-sheep\" does not exist."}', [], 404) ) diff --git a/tests/Api/Asset/ListAllAssetsIntegration.php b/tests/Api/Asset/ListAllAssetsIntegration.php index e8a085eb..8ac16101 100644 --- a/tests/Api/Asset/ListAllAssetsIntegration.php +++ b/tests/Api/Asset/ListAllAssetsIntegration.php @@ -15,7 +15,7 @@ class ListAllAssetsIntegration extends ApiTestCase public function test_list_per_page() { $this->server->setResponseOfPath( - '/'. sprintf(AssetApi::ASSETS_URI, 'packshot'), + '/' . sprintf(AssetApi::ASSETS_URI, 'packshot'), new ResponseStack( new Response($this->getFirstPage(), [], 200), new Response($this->getSecondPage(), [], 200) diff --git a/tests/Api/Asset/UpsertAssetIntegration.php b/tests/Api/Asset/UpsertAssetIntegration.php index a2ddc3b8..d39a80fa 100644 --- a/tests/Api/Asset/UpsertAssetIntegration.php +++ b/tests/Api/Asset/UpsertAssetIntegration.php @@ -16,7 +16,7 @@ class UpsertAssetIntegration extends ApiTestCase public function test_upsert_asset() { $this->server->setResponseOfPath( - '/'. sprintf(AssetApi::ASSET_URI, 'packshot', 'sku_54628_telescope'), + '/' . sprintf(AssetApi::ASSET_URI, 'packshot', 'sku_54628_telescope'), new ResponseStack( new Response('', [], 204) ) diff --git a/tests/Api/Asset/UpsertListAssetIntegration.php b/tests/Api/Asset/UpsertListAssetIntegration.php index fb3d0734..9ff1737a 100644 --- a/tests/Api/Asset/UpsertListAssetIntegration.php +++ b/tests/Api/Asset/UpsertListAssetIntegration.php @@ -29,7 +29,7 @@ public function test_upsert_a_list_of_assets() JSON; $this->server->setResponseOfPath( - '/'. sprintf(AssetApi::ASSETS_URI, 'packshot'), + '/' . sprintf(AssetApi::ASSETS_URI, 'packshot'), new ResponseStack( new Response($responseBody, [], 200) ) diff --git a/tests/Api/AssetAttribute/GetAssetFamilyAttributeIntegration.php b/tests/Api/AssetAttribute/GetAssetFamilyAttributeIntegration.php index d3146902..4fe45ca3 100644 --- a/tests/Api/AssetAttribute/GetAssetFamilyAttributeIntegration.php +++ b/tests/Api/AssetAttribute/GetAssetFamilyAttributeIntegration.php @@ -5,6 +5,7 @@ namespace Akeneo\Pim\ApiClient\tests\Api\AssetAttribute; use Akeneo\Pim\ApiClient\Api\AssetManager\AssetAttributeApi; +use Akeneo\Pim\ApiClient\Exception\NotFoundHttpException; use Akeneo\Pim\ApiClient\tests\Api\ApiTestCase; use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; @@ -16,7 +17,7 @@ class GetAssetFamilyAttributeIntegration extends ApiTestCase public function test_get_asset_family_attribute() { $this->server->setResponseOfPath( - '/'. sprintf(AssetAttributeApi::ASSET_ATTRIBUTE_URI, 'packshot', 'media_preview'), + '/' . sprintf(AssetAttributeApi::ASSET_ATTRIBUTE_URI, 'packshot', 'media_preview'), new ResponseStack( new Response($this->getPackshotPreviewAttribute(), [], 200) ) @@ -29,20 +30,20 @@ public function test_get_asset_family_attribute() Assert::assertEquals($familyAttribute, json_decode($this->getPackshotPreviewAttribute(), true)); } - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - * @expectedExceptionMessage Resource `foo` does not exist. - */ public function test_get_unknown_asset_family_attribute() { $this->server->setResponseOfPath( - '/'. sprintf(AssetAttributeApi::ASSET_ATTRIBUTE_URI, 'packshot', 'foo'), + '/' . sprintf(AssetAttributeApi::ASSET_ATTRIBUTE_URI, 'packshot', 'foo'), new ResponseStack( new Response('{"code": 404, "message":"Resource `foo` does not exist."}', [], 404) ) ); $api = $this->createClientByPassword()->getAssetAttributeApi(); + + $this->expectException(NotFoundHttpException::class); + $this->expectExceptionMessage('Resource `foo` does not exist.'); + $api->get('packshot', 'foo'); } diff --git a/tests/Api/AssetAttribute/UpsertAssetFamilyAttributeIntegration.php b/tests/Api/AssetAttribute/UpsertAssetFamilyAttributeIntegration.php index b8981f7b..b4b05b03 100644 --- a/tests/Api/AssetAttribute/UpsertAssetFamilyAttributeIntegration.php +++ b/tests/Api/AssetAttribute/UpsertAssetFamilyAttributeIntegration.php @@ -16,7 +16,7 @@ class UpsertAssetFamilyAttributeIntegration extends ApiTestCase public function test_upsert_asset_family_attribute() { $this->server->setResponseOfPath( - '/'. sprintf(AssetAttributeApi::ASSET_ATTRIBUTE_URI, 'packshot', 'media_preview'), + '/' . sprintf(AssetAttributeApi::ASSET_ATTRIBUTE_URI, 'packshot', 'media_preview'), new ResponseStack( new Response('', [], 204) ) @@ -39,7 +39,10 @@ public function test_upsert_asset_family_attribute() $api = $this->createClientByPassword()->getAssetAttributeApi(); $response = $api->upsert('packshot', 'media_preview', $assetFamilyAttribute); - Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($assetFamilyAttribute)); + Assert::assertSame( + $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], + json_encode($assetFamilyAttribute) + ); Assert::assertSame(204, $response); } } diff --git a/tests/Api/AssetAttributeOption/GetAssetFamilyAttributeOptionIntegration.php b/tests/Api/AssetAttributeOption/GetAssetFamilyAttributeOptionIntegration.php index eb161d6e..5a70c333 100644 --- a/tests/Api/AssetAttributeOption/GetAssetFamilyAttributeOptionIntegration.php +++ b/tests/Api/AssetAttributeOption/GetAssetFamilyAttributeOptionIntegration.php @@ -5,6 +5,7 @@ namespace Akeneo\Pim\ApiClient\tests\Api\AssetAttributeOption; use Akeneo\Pim\ApiClient\Api\AssetManager\AssetAttributeOptionApi; +use Akeneo\Pim\ApiClient\Exception\NotFoundHttpException; use Akeneo\Pim\ApiClient\tests\Api\ApiTestCase; use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; @@ -16,7 +17,7 @@ class GetAssetFamilyAttributeOptionIntegration extends ApiTestCase public function test_get_asset_family_attribute_option() { $this->server->setResponseOfPath( - '/'. sprintf(AssetAttributeOptionApi::ASSET_ATTRIBUTE_OPTION_URI, 'packshot', 'wearing_model_size', 'small'), + '/' . sprintf(AssetAttributeOptionApi::ASSET_ATTRIBUTE_OPTION_URI, 'packshot', 'wearing_model_size', 'small'), new ResponseStack( new Response($this->getPackshotAttributeOption(), [], 200) ) @@ -29,20 +30,20 @@ public function test_get_asset_family_attribute_option() Assert::assertEquals($familyAttributeOption, json_decode($this->getPackshotAttributeOption(), true)); } - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - * @expectedExceptionMessage Resource `XLS` does not exist. - */ public function test_get_unknown_asset_family_attribute_option() { $this->server->setResponseOfPath( - '/'. sprintf(AssetAttributeOptionApi::ASSET_ATTRIBUTE_OPTION_URI, 'packshot', 'wearing_model_size', 'XLS'), + '/' . sprintf(AssetAttributeOptionApi::ASSET_ATTRIBUTE_OPTION_URI, 'packshot', 'wearing_model_size', 'XLS'), new ResponseStack( new Response('{"code": 404, "message":"Resource `XLS` does not exist."}', [], 404) ) ); $api = $this->createClientByPassword()->getAssetAttributeOptionApi(); + + $this->expectException(NotFoundHttpException::class); + $this->expectExceptionMessage('Resource `XLS` does not exist.'); + $api->get('packshot', 'wearing_model_size', 'XLS'); } diff --git a/tests/Api/AssetAttributeOption/UpsertAssetFamilyAttributeOptionIntegration.php b/tests/Api/AssetAttributeOption/UpsertAssetFamilyAttributeOptionIntegration.php index f65e790e..d6364af5 100644 --- a/tests/Api/AssetAttributeOption/UpsertAssetFamilyAttributeOptionIntegration.php +++ b/tests/Api/AssetAttributeOption/UpsertAssetFamilyAttributeOptionIntegration.php @@ -16,7 +16,7 @@ class UpsertAssetFamilyAttributeOptionIntegration extends ApiTestCase public function test_upsert_asset_family_attribute_option() { $this->server->setResponseOfPath( - '/'. sprintf( + '/' . sprintf( AssetAttributeOptionApi::ASSET_ATTRIBUTE_OPTION_URI, 'packshot', 'wearing_model_size', @@ -38,7 +38,10 @@ public function test_upsert_asset_family_attribute_option() $api = $this->createClientByPassword()->getAssetAttributeOptionApi(); $response = $api->upsert('packshot', 'wearing_model_size', 'size_27', $assetFamilyAttributeOption); - Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($assetFamilyAttributeOption)); + Assert::assertSame( + $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], + json_encode($assetFamilyAttributeOption) + ); Assert::assertSame(204, $response); } } diff --git a/tests/Api/AssetFamily/GetAssetFamilyIntegration.php b/tests/Api/AssetFamily/GetAssetFamilyIntegration.php index 841339da..4e43a281 100644 --- a/tests/Api/AssetFamily/GetAssetFamilyIntegration.php +++ b/tests/Api/AssetFamily/GetAssetFamilyIntegration.php @@ -5,6 +5,7 @@ namespace Akeneo\Pim\ApiClient\tests\Api\AssetFamily; use Akeneo\Pim\ApiClient\Api\AssetManager\AssetFamilyApi; +use Akeneo\Pim\ApiClient\Exception\NotFoundHttpException; use Akeneo\Pim\ApiClient\tests\Api\ApiTestCase; use donatj\MockWebServer\RequestInfo; use donatj\MockWebServer\Response; @@ -16,7 +17,7 @@ class GetAssetFamilyIntegration extends ApiTestCase public function test_get_asset_family() { $this->server->setResponseOfPath( - '/'. sprintf(AssetFamilyApi::ASSET_FAMILY_URI, 'packshot'), + '/' . sprintf(AssetFamilyApi::ASSET_FAMILY_URI, 'packshot'), new ResponseStack( new Response($this->getPackshot(), [], 200) ) @@ -29,20 +30,20 @@ public function test_get_asset_family() Assert::assertEquals($product, json_decode($this->getPackshot(), true)); } - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - * @expectedExceptionMessage Asset family "foo" does not exist. - */ public function test_get_unknown_asset_family() { $this->server->setResponseOfPath( - '/'. sprintf(AssetFamilyApi::ASSET_FAMILY_URI, 'foo'), + '/' . sprintf(AssetFamilyApi::ASSET_FAMILY_URI, 'foo'), new ResponseStack( new Response('{"code": 404, "message":"Asset family \"foo\" does not exist."}', [], 404) ) ); $api = $this->createClientByPassword()->getAssetFamilyApi(); + + $this->expectException(NotFoundHttpException::class); + $this->expectExceptionMessage('Asset family "foo" does not exist.'); + $api->get('foo'); } diff --git a/tests/Api/AssetFamily/ListAllAssetFamiliesIntegration.php b/tests/Api/AssetFamily/ListAllAssetFamiliesIntegration.php index a95103e6..a60bed80 100644 --- a/tests/Api/AssetFamily/ListAllAssetFamiliesIntegration.php +++ b/tests/Api/AssetFamily/ListAllAssetFamiliesIntegration.php @@ -15,7 +15,7 @@ class ListAllAssetFamiliesIntegration extends ApiTestCase public function test_list_per_page() { $this->server->setResponseOfPath( - '/' . sprintf(AssetFamilyApi::ASSET_FAMILIES_URI), + '/' . AssetFamilyApi::ASSET_FAMILIES_URI, new ResponseStack( new Response($this->getFirstPage(), [], 200), new Response($this->getSecondPage(), [], 200) diff --git a/tests/Api/AssetFamily/UpsertAssetFamilyIntegration.php b/tests/Api/AssetFamily/UpsertAssetFamilyIntegration.php index 8a3d3110..71043513 100644 --- a/tests/Api/AssetFamily/UpsertAssetFamilyIntegration.php +++ b/tests/Api/AssetFamily/UpsertAssetFamilyIntegration.php @@ -14,7 +14,7 @@ class UpsertAssetFamilyIntegration extends ApiTestCase public function test_upsert_asset_family() { $this->server->setResponseOfPath( - '/'. sprintf(AssetFamilyApi::ASSET_FAMILY_URI, 'packshot'), + '/' . sprintf(AssetFamilyApi::ASSET_FAMILY_URI, 'packshot'), new ResponseStack( new Response('', [], 201) ) diff --git a/tests/Api/AssetReferenceFile/DownloadAssetReferenceFileIntegration.php b/tests/Api/AssetReferenceFile/DownloadAssetReferenceFileIntegration.php index 125af370..5e01783e 100644 --- a/tests/Api/AssetReferenceFile/DownloadAssetReferenceFileIntegration.php +++ b/tests/Api/AssetReferenceFile/DownloadAssetReferenceFileIntegration.php @@ -17,7 +17,7 @@ public function test_download_a_localizable_asset_reference_file() $expectedFilePath = realpath(__DIR__ . '/../../fixtures/ziggy.png'); $this->server->setResponseOfPath( - '/'. sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_DOWNLOAD_URI, 'ziggy', 'en_US'), + '/' . sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_DOWNLOAD_URI, 'ziggy', 'en_US'), new ResponseStack( new Response(file_get_contents($expectedFilePath), [], 201) ) @@ -37,7 +37,11 @@ public function test_download_a_not_localizable_asset_reference_file() $expectedFilePath = realpath(__DIR__ . '/../../fixtures/ziggy-certification.jpg'); $this->server->setResponseOfPath( - '/'. sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_DOWNLOAD_URI, 'ziggy_certif', AssetReferenceFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE), + '/' . sprintf( + AssetReferenceFileApi::ASSET_REFERENCE_FILE_DOWNLOAD_URI, + 'ziggy_certif', + AssetReferenceFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE + ), new ResponseStack( new Response(file_get_contents($expectedFilePath), [], 201) ) @@ -58,7 +62,7 @@ public function test_download_a_not_localizable_asset_reference_file() public function test_download_from_localizable_asset_not_found() { $this->server->setResponseOfPath( - '/'. sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_DOWNLOAD_URI, 'ziggy', 'en_US'), + '/' . sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_DOWNLOAD_URI, 'ziggy', 'en_US'), new ResponseStack( new Response('{"code": 404, "message":"Not found"}', [], 404) ) @@ -74,7 +78,11 @@ public function test_download_from_localizable_asset_not_found() public function test_download_from_not_localizable_asset_not_found() { $this->server->setResponseOfPath( - '/'. sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_DOWNLOAD_URI, 'ziggy_certif', AssetReferenceFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE), + '/' . sprintf( + AssetReferenceFileApi::ASSET_REFERENCE_FILE_DOWNLOAD_URI, + 'ziggy_certif', + AssetReferenceFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE + ), new ResponseStack( new Response('{"code": 404, "message":"Not found"}', [], 404) ) diff --git a/tests/Api/AssetReferenceFile/UploadAssetReferenceFileIntegration.php b/tests/Api/AssetReferenceFile/UploadAssetReferenceFileIntegration.php index ddef901d..a07b2c50 100644 --- a/tests/Api/AssetReferenceFile/UploadAssetReferenceFileIntegration.php +++ b/tests/Api/AssetReferenceFile/UploadAssetReferenceFileIntegration.php @@ -16,7 +16,7 @@ public function test_upload_a_localizable_asset_reference_file() $filePath = realpath(__DIR__ . '/../../fixtures/ziggy.png'); $this->server->setResponseOfPath( - '/'. sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_URI, 'ziggy', 'en_US'), + '/' . sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_URI, 'ziggy', 'en_US'), new ResponseStack( new Response(file_get_contents($filePath), [], 201), new Response(json_encode($this->fakeUploadLocalizableInformations()), [], 201) @@ -45,7 +45,11 @@ public function test_upload_a_not_localizable_asset_reference_file() $filePath = realpath(__DIR__ . '/../../fixtures/ziggy-certification.jpg'); $this->server->setResponseOfPath( - '/'. sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_URI, 'ziggy-certification', AssetReferenceFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE), + '/' . sprintf( + AssetReferenceFileApi::ASSET_REFERENCE_FILE_URI, + 'ziggy-certification', + AssetReferenceFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE + ), new ResponseStack( new Response(file_get_contents($filePath), [], 201), new Response(json_encode($this->fakeUploadNotLocalizableInformations()), [], 201) @@ -57,7 +61,10 @@ public function test_upload_a_not_localizable_asset_reference_file() Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'POST'); Assert::assertNotEmpty($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']); - Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['name'], 'ziggy-certification.jpg'); + Assert::assertSame( + $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['name'], + 'ziggy-certification.jpg' + ); Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['type'], 'image/jpeg'); Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['size'], 10513); @@ -75,7 +82,7 @@ public function test_upload_from_resource_file() $file = fopen($filePath, 'rb'); $this->server->setResponseOfPath( - '/'. sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_URI, 'ziggy', 'en_US'), + '/' . sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_URI, 'ziggy', 'en_US'), new ResponseStack( new Response(file_get_contents($filePath), [], 201), new Response(json_encode($this->fakeUploadLocalizableInformations()), [], 201) @@ -107,7 +114,7 @@ public function test_upload_for_an_unknown_asset() $filePath = realpath(__DIR__ . '/../../fixtures/ziggy.png'); $this->server->setResponseOfPath( - '/'. sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_URI, 'unknown_asset', 'en_US'), + '/' . sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_URI, 'unknown_asset', 'en_US'), new ResponseStack( new Response('{"code": 404, "message":"Not found"}', [], 404) ) @@ -126,7 +133,11 @@ public function test_upload_a_file_that_cannot_be_transformed_for_the_variations $filePath = realpath(__DIR__ . '/../../fixtures/unicorn.png'); $this->server->setResponseOfPath( - '/'. sprintf(AssetReferenceFileApi::ASSET_REFERENCE_FILE_URI, 'unicorn', AssetReferenceFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE), + '/' . sprintf( + AssetReferenceFileApi::ASSET_REFERENCE_FILE_URI, + 'unicorn', + AssetReferenceFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE + ), new ResponseStack( new Response(json_encode($this->generateMessageForUploadAssetReferenceFileErrorException())) ) @@ -137,23 +148,25 @@ public function test_upload_a_file_that_cannot_be_transformed_for_the_variations $api->uploadForNotLocalizableAsset($filePath, 'unicorn'); } - protected function fakeUploadLocalizableInformations(){ + protected function fakeUploadLocalizableInformations() + { return [ - 'code' => '5/c/8/3/5c835e7785cb174d8e7e39d7ee63be559f233be0_ziggy.jpg', + 'code' => '5/c/8/3/5c835e7785cb174d8e7e39d7ee63be559f233be0_ziggy.jpg', 'locale' => 'en_US', - '_link' => [ + '_link' => [ 'download' => [ - 'href' => '/api/rest/v1/assets/ziggy/reference-files/en_US/download' + 'href' => '/api/rest/v1/assets/ziggy/reference-files/en_US/download' ] ], ]; } - protected function fakeUploadNotLocalizableInformations(){ + protected function fakeUploadNotLocalizableInformations() + { return [ - 'code' => '5/c/8/3/5c835e7785cb174d8e7e39d7ee63be559f233be0_ziggy_certification.jpg', + 'code' => '5/c/8/3/5c835e7785cb174d8e7e39d7ee63be559f233be0_ziggy_certification.jpg', 'locale' => null, - '_link' => [ + '_link' => [ 'download' => [ 'href' => '/api/rest/v1/assets/ziggy_certif/reference-files/no-locale/download' ] @@ -161,7 +174,8 @@ protected function fakeUploadNotLocalizableInformations(){ ]; } - protected function generateMessageForUploadAssetReferenceFileErrorException(){ + protected function generateMessageForUploadAssetReferenceFileErrorException() + { return [ 'message' => 'Some variation files were not generated properly.', 'errors' => [ diff --git a/tests/Api/AssetVariationFile/DownloadAssetVariationFileApiIntegration.php b/tests/Api/AssetVariationFile/DownloadAssetVariationFileApiIntegration.php index 9e3eb3a4..26561a96 100644 --- a/tests/Api/AssetVariationFile/DownloadAssetVariationFileApiIntegration.php +++ b/tests/Api/AssetVariationFile/DownloadAssetVariationFileApiIntegration.php @@ -12,13 +12,12 @@ class DownloadAssetVariationFileApiIntegration extends ApiTestCase { - public function test_download_a_localizable_asset_variation_file() { $expectedFilePath = realpath(__DIR__ . '/../../fixtures/ziggy.png'); $this->server->setResponseOfPath( - '/'. sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_DOWNLOAD_URI, 'ziggy', 'ecommerce', 'en_US'), + '/' . sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_DOWNLOAD_URI, 'ziggy', 'ecommerce', 'en_US'), new ResponseStack( new Response(file_get_contents($expectedFilePath), [], 201) ) @@ -39,7 +38,12 @@ public function test_download_a_not_localizable_asset_variation_file() $expectedFilePath = realpath(__DIR__ . '/../../fixtures/ziggy-certification.jpg'); $this->server->setResponseOfPath( - '/'. sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_DOWNLOAD_URI, 'ziggy_certif', 'ecommerce', AssetVariationFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE), + '/' . sprintf( + AssetVariationFileApi::ASSET_VARIATION_FILE_DOWNLOAD_URI, + 'ziggy_certif', + 'ecommerce', + AssetVariationFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE + ), new ResponseStack( new Response(file_get_contents($expectedFilePath), [], 201) ) @@ -60,7 +64,7 @@ public function test_download_a_not_localizable_asset_variation_file() public function test_download_from_localizable_asset_not_found() { $this->server->setResponseOfPath( - '/'. sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_DOWNLOAD_URI, 'ziggy', 'mobile', 'en_US'), + '/' . sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_DOWNLOAD_URI, 'ziggy', 'mobile', 'en_US'), new ResponseStack( new Response('{"code": 404, "message":"Not found"}', [], 404) ) @@ -76,7 +80,12 @@ public function test_download_from_localizable_asset_not_found() public function test_download_from_not_localizable_asset_not_found() { $this->server->setResponseOfPath( - '/'. sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_DOWNLOAD_URI, 'ziggy_certif', 'mobile', AssetVariationFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE), + '/' . sprintf( + AssetVariationFileApi::ASSET_VARIATION_FILE_DOWNLOAD_URI, + 'ziggy_certif', + 'mobile', + AssetVariationFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE + ), new ResponseStack( new Response('{"code": 404, "message":"Not found"}', [], 404) ) diff --git a/tests/Api/AssetVariationFile/UploadAssetVariationFileApiIntegration.php b/tests/Api/AssetVariationFile/UploadAssetVariationFileApiIntegration.php index 20da16fa..58a0502a 100644 --- a/tests/Api/AssetVariationFile/UploadAssetVariationFileApiIntegration.php +++ b/tests/Api/AssetVariationFile/UploadAssetVariationFileApiIntegration.php @@ -16,7 +16,7 @@ public function test_upload_a_localizable_asset_variation_file() $filePath = realpath(__DIR__ . '/../../fixtures/ziggy.png'); $this->server->setResponseOfPath( - '/'. sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_URI, 'ziggy', 'ecommerce', 'en_US'), + '/' . sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_URI, 'ziggy', 'ecommerce', 'en_US'), new ResponseStack( new Response(file_get_contents($filePath), [], 201), new Response(json_encode($this->fakeUploadLocalizableInformations()), [], 201) @@ -46,7 +46,12 @@ public function test_upload_a_not_localizable_asset_variation_file() $filePath = realpath(__DIR__ . '/../../fixtures/ziggy-certification.jpg'); $this->server->setResponseOfPath( - '/'. sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_URI, 'ziggy_certif', 'ecommerce', AssetVariationFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE), + '/' . sprintf( + AssetVariationFileApi::ASSET_VARIATION_FILE_URI, + 'ziggy_certif', + 'ecommerce', + AssetVariationFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE + ), new ResponseStack( new Response(file_get_contents($filePath), [], 201), new Response(json_encode($this->fakeUploadNotLocalizableInformations()), [], 201) @@ -58,7 +63,10 @@ public function test_upload_a_not_localizable_asset_variation_file() Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'POST'); Assert::assertNotEmpty($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']); - Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['name'], 'ziggy-certification.jpg'); + Assert::assertSame( + $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['name'], + 'ziggy-certification.jpg' + ); Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['type'], 'image/jpeg'); Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['size'], 10513); @@ -76,7 +84,7 @@ public function test_upload_from_resource_file() $file = fopen($filePath, 'rb'); $this->server->setResponseOfPath( - '/'. sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_URI, 'ziggy', 'ecommerce', 'en_US'), + '/' . sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_URI, 'ziggy', 'ecommerce', 'en_US'), new ResponseStack( new Response(file_get_contents($filePath), [], 201), new Response(json_encode($this->fakeUploadLocalizableInformations()), [], 201) @@ -108,7 +116,7 @@ public function test_upload_for_an_unknown_asset() $filePath = realpath(__DIR__ . '/../../fixtures/ziggy.png'); $this->server->setResponseOfPath( - '/'. sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_URI, 'unknown_asset', 'ecommerce', 'en_US'), + '/' . sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_URI, 'unknown_asset', 'ecommerce', 'en_US'), new ResponseStack( new Response('{"code": 404, "message":"Not found"}', [], 404) ) @@ -127,7 +135,12 @@ public function test_upload_for_an_asset_that_should_be_localizable() $filePath = realpath(__DIR__ . '/../../fixtures/unicorn.png'); $this->server->setResponseOfPath( - '/'. sprintf(AssetVariationFileApi::ASSET_VARIATION_FILE_URI, 'unicorn', 'ecommerce', AssetVariationFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE), + '/' . sprintf( + AssetVariationFileApi::ASSET_VARIATION_FILE_URI, + 'unicorn', + 'ecommerce', + AssetVariationFileApi::NOT_LOCALIZABLE_ASSET_LOCALE_CODE + ), new ResponseStack( new Response('{"code": 422, "message":"Unprocessable Entity"}', [], 422) ) @@ -138,11 +151,12 @@ public function test_upload_for_an_asset_that_should_be_localizable() $api->uploadForNotLocalizableAsset($filePath, 'unicorn', 'ecommerce'); } - protected function fakeUploadLocalizableInformations(){ + protected function fakeUploadLocalizableInformations() + { return [ - 'code' => '5/c/8/3/5c835e7785cb174d8e7e39d7ee63be559f233be0_ziggy_ecommerce.jpg', + 'code' => '5/c/8/3/5c835e7785cb174d8e7e39d7ee63be559f233be0_ziggy_ecommerce.jpg', 'locale' => 'en_US', - '_link' => [ + '_link' => [ 'download' => [ 'href' => '/api/rest/v1/assets/ziggy/variation-files/ecommerce/en_US/download' ] @@ -150,11 +164,12 @@ protected function fakeUploadLocalizableInformations(){ ]; } - protected function fakeUploadNotLocalizableInformations(){ + protected function fakeUploadNotLocalizableInformations() + { return [ - 'code' => '2/9/b/f/29bfa18ced500c5fca2072dab978737576ca47ca_ziggy_certification_ecommerce.jpg', + 'code' => '2/9/b/f/29bfa18ced500c5fca2072dab978737576ca47ca_ziggy_certification_ecommerce.jpg', 'locale' => null, - '_link' => [ + '_link' => [ 'download' => [ 'href' => '/api/rest/v1/assets/ziggy_certif/variation-files/ecommerce/no-locale/download' ] diff --git a/tests/Api/CreateProductMediaFileTest.php b/tests/Api/CreateProductMediaFileTest.php index ce91a44a..5b843455 100644 --- a/tests/Api/CreateProductMediaFileTest.php +++ b/tests/Api/CreateProductMediaFileTest.php @@ -12,9 +12,9 @@ class CreateProductMediaFileTest extends ApiTestCase { public function test_create_media_file() { - $mediaFileURI = $this->server->getServerRoot(). '/' . ProductMediaFileApi::MEDIA_FILES_URI.'/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png'; + $mediaFileURI = $this->server->getServerRoot() . '/' . ProductMediaFileApi::MEDIA_FILES_URI . '/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png'; $this->server->setResponseOfPath( - '/'. ProductMediaFileApi::MEDIA_FILES_URI, + '/' . ProductMediaFileApi::MEDIA_FILES_URI, new ResponseStack( new Response('', ['Location' => $mediaFileURI], 201) ) @@ -25,9 +25,9 @@ public function test_create_media_file() $productInfos = [ 'identifier' => 'medium_boot', - 'attribute' => 'side_view', - 'scope' => null, - 'locale' => null, + 'attribute' => 'side_view', + 'scope' => null, + 'locale' => null, ]; $response = $api->create($mediaFile, $productInfos); @@ -45,7 +45,7 @@ public function test_create_media_file() public function test_get_created_media_file_location_regardless_of_the_header_case() { $mediaFileURI = $this->server->getServerRoot( - ) . '/' . ProductMediaFileApi::MEDIA_FILES_URI . '/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png'; + ) . '/' . ProductMediaFileApi::MEDIA_FILES_URI . '/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png'; $this->server->setResponseOfPath( '/' . ProductMediaFileApi::MEDIA_FILES_URI, new ResponseStack( diff --git a/tests/Api/CreateProductTest.php b/tests/Api/CreateProductTest.php index c560d090..e761b043 100644 --- a/tests/Api/CreateProductTest.php +++ b/tests/Api/CreateProductTest.php @@ -13,7 +13,7 @@ class CreateProductTest extends ApiTestCase public function test_create_product() { $this->server->setResponseOfPath( - '/'. ProductApi::PRODUCTS_URI, + '/' . ProductApi::PRODUCTS_URI, new ResponseStack( new Response('', [], 201) ) @@ -22,7 +22,10 @@ public function test_create_product() $api = $this->createClientByPassword()->getProductApi(); $response = $api->create('new_shoes', $this->newProduct()); - Assert::assertSame(json_encode($this->expectedProduct()), $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT]); + Assert::assertSame( + json_encode($this->expectedProduct()), + $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT] + ); Assert::assertSame(201, $response); } @@ -30,11 +33,15 @@ public function test_create_product() public function test_create_invalid_product() { $this->server->setResponseOfPath( - '/'. ProductApi::PRODUCTS_URI, + '/' . ProductApi::PRODUCTS_URI, new ResponseStack( - new Response('{"code": 422, "message":"The value black_sneakers is already set on another product for the unique attribute sku"}', [], 422) + new Response( + '{"code": 422, "message":"The value black_sneakers is already set on another product for the unique attribute sku"}', + [], + 422 ) - ); + ) + ); $this->expectException(\Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException::class); $this->expectExceptionMessage('The value black_sneakers is already set on another product for the unique attribute sku'); @@ -46,20 +53,20 @@ public function test_create_invalid_product() private function newProduct(): array { return [ - 'enabled' => false, - 'family' => 'sandals', + 'enabled' => false, + 'family' => 'sandals', 'categories' => ['summer_collection'], - 'values' => [ + 'values' => [ 'name' => [ [ - 'data' => 'The pumps', + 'data' => 'The pumps', 'locale' => 'en_US', - 'scope' => null, + 'scope' => null, ], [ - 'data' => 'Les pumps', + 'data' => 'Les pumps', 'locale' => 'fr_FR', - 'scope' => null, + 'scope' => null, ] ] ] @@ -69,20 +76,20 @@ private function newProduct(): array private function expectedProduct(): array { return [ - 'enabled' => false, - 'family' => 'sandals', + 'enabled' => false, + 'family' => 'sandals', 'categories' => ['summer_collection'], - 'values' => [ + 'values' => [ 'name' => [ [ - 'data' => 'The pumps', + 'data' => 'The pumps', 'locale' => 'en_US', - 'scope' => null, + 'scope' => null, ], [ - 'data' => 'Les pumps', + 'data' => 'Les pumps', 'locale' => 'fr_FR', - 'scope' => null, + 'scope' => null, ] ] ], diff --git a/tests/Api/DeleteProductModelTest.php b/tests/Api/DeleteProductModelTest.php index fa152f91..19f69fa2 100644 --- a/tests/Api/DeleteProductModelTest.php +++ b/tests/Api/DeleteProductModelTest.php @@ -13,7 +13,7 @@ class DeleteProductModelTest extends ApiTestCase public function test_delete_product_model() { $this->server->setResponseOfPath( - '/'. sprintf(ProductModelApi::PRODUCT_MODEL_URI, 'docks_white'), + '/' . sprintf(ProductModelApi::PRODUCT_MODEL_URI, 'docks_white'), new ResponseStack( new Response('', [], 204) ) diff --git a/tests/Api/DeleteProductTest.php b/tests/Api/DeleteProductTest.php index 9fd5d4ab..324a3f9c 100644 --- a/tests/Api/DeleteProductTest.php +++ b/tests/Api/DeleteProductTest.php @@ -13,7 +13,7 @@ class DeleteProductTest extends ApiTestCase public function test_create_product() { $this->server->setResponseOfPath( - '/'. sprintf(ProductApi::PRODUCT_URI, 'docks_white'), + '/' . sprintf(ProductApi::PRODUCT_URI, 'docks_white'), new ResponseStack( new Response('', [], 204) ) diff --git a/tests/Api/DownloadProductMediaFileTest.php b/tests/Api/DownloadProductMediaFileTest.php index 1b8b02e0..338fbfc2 100644 --- a/tests/Api/DownloadProductMediaFileTest.php +++ b/tests/Api/DownloadProductMediaFileTest.php @@ -16,7 +16,7 @@ public function test_download_media_file() $expectedMediaFilePath = realpath(__DIR__ . '/../fixtures/akeneo.png'); $this->server->setResponseOfPath( - '/'. sprintf(ProductMediaFileApi::MEDIA_FILE_DOWNLOAD_URI, '/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png'), + '/' . sprintf(ProductMediaFileApi::MEDIA_FILE_DOWNLOAD_URI, '/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png'), new ResponseStack( new Response(file_get_contents($expectedMediaFilePath), [], 201) ) diff --git a/tests/Api/GetProductTest.php b/tests/Api/GetProductTest.php index 44f11fd7..f804918a 100644 --- a/tests/Api/GetProductTest.php +++ b/tests/Api/GetProductTest.php @@ -13,7 +13,7 @@ class GetProductTest extends ApiTestCase public function test_get_product() { $this->server->setResponseOfPath( - '/'. sprintf(ProductApi::PRODUCT_URI, 'black_sneakers'), + '/' . sprintf(ProductApi::PRODUCT_URI, 'black_sneakers'), new ResponseStack( new Response($this->getProduct(), [], 200) ) @@ -30,7 +30,7 @@ public function test_get_product() public function test_get_unknow_product() { $this->server->setResponseOfPath( - '/'. sprintf(ProductApi::PRODUCT_URI, 'black_sneakers'), + '/' . sprintf(ProductApi::PRODUCT_URI, 'black_sneakers'), new ResponseStack( new Response('{"code": 404, "message":"Resource `black_sneakers` does not exist."}', [], 404) ) diff --git a/tests/Api/ListPerPageProductTest.php b/tests/Api/ListPerPageProductTest.php index 10d44a7c..2ad84545 100644 --- a/tests/Api/ListPerPageProductTest.php +++ b/tests/Api/ListPerPageProductTest.php @@ -14,7 +14,7 @@ class ListPerPageProductTest extends ApiTestCase public function test_list_per_page() { $this->server->setResponseOfPath( - '/'. ProductApi::PRODUCTS_URI, + '/' . ProductApi::PRODUCTS_URI, new ResponseStack( new Response($this->getFirstPage(), [], 200), new Response($this->getSecondPage(), [], 200) @@ -24,7 +24,10 @@ public function test_list_per_page() $api = $this->createClientByPassword()->getProductApi(); $firstPage = $api->listPerPage(10, true, []); - Assert::assertSame(['limit' => '10', 'with_count' => 'true'], $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_GET]); + Assert::assertSame( + ['limit' => '10', 'with_count' => 'true'], + $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_GET] + ); Assert::assertInstanceOf(PageInterface::class, $firstPage); Assert::assertEquals(11, $firstPage->getCount()); @@ -32,7 +35,10 @@ public function test_list_per_page() Assert::assertNull($firstPage->getPreviousPage()); Assert::assertFalse($firstPage->hasPreviousPage()); Assert::assertTrue($firstPage->hasNextPage()); - Assert::assertSame($this->server->getServerRoot() . '/api/rest/v1/products?page=2&with_count=true&pagination_type=page&limit=10', $firstPage->getNextLink()); + Assert::assertSame( + $this->server->getServerRoot() . '/api/rest/v1/products?page=2&with_count=true&pagination_type=page&limit=10', + $firstPage->getNextLink() + ); Assert::assertEquals(10, count($firstPage->getItems())); $secondPage = $firstPage->getNextPage(); @@ -50,7 +56,10 @@ public function test_list_per_page() Assert::assertNull($secondPage->getNextPage()); Assert::assertFalse($secondPage->hasNextPage()); Assert::assertTrue($secondPage->hasPreviousPage()); - Assert::assertSame($this->server->getServerRoot() . '/api/rest/v1/products?page=1&with_count=true&pagination_type=page&limit=10', $secondPage->getPreviousLink()); + Assert::assertSame( + $this->server->getServerRoot() . '/api/rest/v1/products?page=1&with_count=true&pagination_type=page&limit=10', + $secondPage->getPreviousLink() + ); Assert::assertEquals(1, count($secondPage->getItems())); } diff --git a/tests/Api/ProductDraftUuid/GetProductDraftUuidIntegration.php b/tests/Api/ProductDraftUuid/GetProductDraftUuidIntegration.php index cffdc4eb..531b6303 100644 --- a/tests/Api/ProductDraftUuid/GetProductDraftUuidIntegration.php +++ b/tests/Api/ProductDraftUuid/GetProductDraftUuidIntegration.php @@ -19,7 +19,7 @@ class GetProductDraftUuidIntegration extends ApiTestCase public function test_get_product() { $this->server->setResponseOfPath( - '/'.sprintf(ProductDraftUuidApi::PRODUCT_DRAFT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), + '/' . sprintf(ProductDraftUuidApi::PRODUCT_DRAFT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), new ResponseStack( new Response($this->getProductDraft(), [], HttpClient::HTTP_OK) ) @@ -35,7 +35,7 @@ public function test_get_product() public function test_get_unknown_product() { $this->server->setResponseOfPath( - '/'.sprintf(ProductDraftUuidApi::PRODUCT_DRAFT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), + '/' . sprintf(ProductDraftUuidApi::PRODUCT_DRAFT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), new ResponseStack( new Response('{"code": 404, "message":"Resource `12951d98-210e-4bRC-ab18-7fdgf1bd14f3` does not exist."}', [], 404) ) diff --git a/tests/Api/ProductUuid/CreateProductUuidIntegration.php b/tests/Api/ProductUuid/CreateProductUuidIntegration.php index d9278435..51f8f8bb 100644 --- a/tests/Api/ProductUuid/CreateProductUuidIntegration.php +++ b/tests/Api/ProductUuid/CreateProductUuidIntegration.php @@ -20,7 +20,7 @@ class CreateProductUuidIntegration extends ApiTestCase public function test_create_product() { $this->server->setResponseOfPath( - '/'.ProductUuidApi::PRODUCTS_UUID_URI, + '/' . ProductUuidApi::PRODUCTS_UUID_URI, new ResponseStack( new Response('', [], HttpClient::HTTP_CREATED) ) @@ -40,7 +40,7 @@ public function test_create_product() public function test_create_invalid_product() { $this->server->setResponseOfPath( - '/'.ProductUuidApi::PRODUCTS_UUID_URI, + '/' . ProductUuidApi::PRODUCTS_UUID_URI, new ResponseStack( new Response( '{"code": 422, "message":"The value 12951d98-210e-4bRC-ab18-7fdgf1bd14f3 is already set on another product for the uuid"}', diff --git a/tests/Api/ProductUuid/DeleteProductUuidIntegration.php b/tests/Api/ProductUuid/DeleteProductUuidIntegration.php index 3059c517..3bf2337f 100644 --- a/tests/Api/ProductUuid/DeleteProductUuidIntegration.php +++ b/tests/Api/ProductUuid/DeleteProductUuidIntegration.php @@ -19,7 +19,7 @@ class DeleteProductUuidIntegration extends ApiTestCase public function test_create_product() { $this->server->setResponseOfPath( - '/'. sprintf(ProductUuidApi::PRODUCT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), + '/' . sprintf(ProductUuidApi::PRODUCT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), new ResponseStack( new Response('', [], HttpClient::HTTP_NO_CONTENT) ) diff --git a/tests/Api/ProductUuid/GetProductUuidIntegration.php b/tests/Api/ProductUuid/GetProductUuidIntegration.php index b9ca786f..84f08288 100644 --- a/tests/Api/ProductUuid/GetProductUuidIntegration.php +++ b/tests/Api/ProductUuid/GetProductUuidIntegration.php @@ -19,7 +19,7 @@ class GetProductUuidIntegration extends ApiTestCase public function test_get_product() { $this->server->setResponseOfPath( - '/'.sprintf(ProductUuidApi::PRODUCT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), + '/' . sprintf(ProductUuidApi::PRODUCT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), new ResponseStack( new Response($this->getProduct(), [], HttpClient::HTTP_OK) ) @@ -35,7 +35,7 @@ public function test_get_product() public function test_get_unknown_product() { $this->server->setResponseOfPath( - '/'.sprintf(ProductUuidApi::PRODUCT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), + '/' . sprintf(ProductUuidApi::PRODUCT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), new ResponseStack( new Response('{"code": 404, "message":"Resource `12951d98-210e-4bRC-ab18-7fdgf1bd14f3` does not exist."}', [], 404) ) diff --git a/tests/Api/ProductUuid/ListPerPageProductUuidIntegration.php b/tests/Api/ProductUuid/ListPerPageProductUuidIntegration.php index 5def2bb9..5a64ca5d 100644 --- a/tests/Api/ProductUuid/ListPerPageProductUuidIntegration.php +++ b/tests/Api/ProductUuid/ListPerPageProductUuidIntegration.php @@ -2,7 +2,6 @@ namespace Akeneo\Pim\ApiClient\tests\Api\ProductUuid; - use Akeneo\Pim\ApiClient\Api\ProductUuidApi; use Akeneo\Pim\ApiClient\Client\HttpClient; use Akeneo\Pim\ApiClient\Pagination\PageInterface; @@ -21,7 +20,7 @@ class ListPerPageProductUuidIntegration extends ApiTestCase public function test_list_per_page() { $this->server->setResponseOfPath( - '/'. ProductUuidApi::PRODUCTS_UUID_URI, + '/' . ProductUuidApi::PRODUCTS_UUID_URI, new ResponseStack( new Response($this->getFirstPage(), [], HttpClient::HTTP_OK), new Response($this->getSecondPage(), [], HttpClient::HTTP_OK) @@ -31,8 +30,10 @@ public function test_list_per_page() $api = $this->createClientByPassword()->getProductUuidApi(); $firstPage = $api->listPerPage(10, true, []); - Assert::assertSame(['limit' => '10', 'with_count' => 'true'], - $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_GET]); + Assert::assertSame( + ['limit' => '10', 'with_count' => 'true'], + $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_GET] + ); Assert::assertInstanceOf(PageInterface::class, $firstPage); Assert::assertEquals(11, $firstPage->getCount()); @@ -40,7 +41,10 @@ public function test_list_per_page() Assert::assertNull($firstPage->getPreviousPage()); Assert::assertFalse($firstPage->hasPreviousPage()); Assert::assertTrue($firstPage->hasNextPage()); - Assert::assertSame($this->server->getServerRoot() . '/api/rest/v1/products-uuid?page=2&with_count=true&pagination_type=page&limit=10', $firstPage->getNextLink()); + Assert::assertSame( + $this->server->getServerRoot() . '/api/rest/v1/products-uuid?page=2&with_count=true&pagination_type=page&limit=10', + $firstPage->getNextLink() + ); Assert::assertCount(10, $firstPage->getItems()); $secondPage = $firstPage->getNextPage(); @@ -58,7 +62,10 @@ public function test_list_per_page() Assert::assertNull($secondPage->getNextPage()); Assert::assertFalse($secondPage->hasNextPage()); Assert::assertTrue($secondPage->hasPreviousPage()); - Assert::assertSame($this->server->getServerRoot() . '/api/rest/v1/products-uuid?page=1&with_count=true&pagination_type=page&limit=10', $secondPage->getPreviousLink()); + Assert::assertSame( + $this->server->getServerRoot() . '/api/rest/v1/products-uuid?page=1&with_count=true&pagination_type=page&limit=10', + $secondPage->getPreviousLink() + ); Assert::assertCount(1, $secondPage->getItems()); } diff --git a/tests/Api/ProductUuid/UpsertListProductUuidIntegration.php b/tests/Api/ProductUuid/UpsertListProductUuidIntegration.php index cfdc2dd1..20870cd3 100644 --- a/tests/Api/ProductUuid/UpsertListProductUuidIntegration.php +++ b/tests/Api/ProductUuid/UpsertListProductUuidIntegration.php @@ -21,7 +21,7 @@ public function setUp(): void { parent::setUp(); $this->server->setResponseOfPath( - '/'.ProductUuidApi::PRODUCTS_UUID_URI, + '/' . ProductUuidApi::PRODUCTS_UUID_URI, new ResponseStack( new Response($this->getResults(), [], HttpClient::HTTP_OK) ) diff --git a/tests/Api/ProductUuid/UpsertProductUuidIntegration.php b/tests/Api/ProductUuid/UpsertProductUuidIntegration.php index 6e4b1b81..5266c49a 100644 --- a/tests/Api/ProductUuid/UpsertProductUuidIntegration.php +++ b/tests/Api/ProductUuid/UpsertProductUuidIntegration.php @@ -19,7 +19,7 @@ class UpsertProductUuidIntegration extends ApiTestCase public function test_upsert_product() { $this->server->setResponseOfPath( - '/'. sprintf(ProductUuidApi::PRODUCT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), + '/' . sprintf(ProductUuidApi::PRODUCT_UUID_URI, '12951d98-210e-4bRC-ab18-7fdgf1bd14f3'), new ResponseStack( new Response('', [], HttpClient::HTTP_NO_CONTENT) ) @@ -30,12 +30,12 @@ public function test_upsert_product() $parameters = [ 'identifier' => 'black_docks', 'enabled' => false, - 'values' => [ + 'values' => [ 'name' => [ [ 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black Docks', + 'scope' => null, + 'data' => 'Black Docks', ], ], ] @@ -46,5 +46,4 @@ public function test_upsert_product() Assert::assertSame(HttpClient::HTTP_NO_CONTENT, $response); } - } diff --git a/tests/Api/ReferenceEntity/GetReferenceEntityIntegration.php b/tests/Api/ReferenceEntity/GetReferenceEntityIntegration.php index b4289a96..9ba52743 100644 --- a/tests/Api/ReferenceEntity/GetReferenceEntityIntegration.php +++ b/tests/Api/ReferenceEntity/GetReferenceEntityIntegration.php @@ -16,7 +16,7 @@ class GetReferenceEntityIntegration extends ApiTestCase public function test_get_reference_entity() { $this->server->setResponseOfPath( - '/'. sprintf(ReferenceEntityApi::REFERENCE_ENTITY_URI, 'brand'), + '/' . sprintf(ReferenceEntityApi::REFERENCE_ENTITY_URI, 'brand'), new ResponseStack( new Response($this->getBrand(), [], 200) ) @@ -32,7 +32,7 @@ public function test_get_reference_entity() public function test_get_unknown_reference_entity() { $this->server->setResponseOfPath( - '/'. sprintf(ReferenceEntityApi::REFERENCE_ENTITY_URI, 'foo'), + '/' . sprintf(ReferenceEntityApi::REFERENCE_ENTITY_URI, 'foo'), new ResponseStack( new Response('{"code": 404, "message":"Reference entity \"foo\" does not exist."}', [], 404) ) diff --git a/tests/Api/ReferenceEntity/ListAllReferenceEntitiesIntegration.php b/tests/Api/ReferenceEntity/ListAllReferenceEntitiesIntegration.php index d9c6f70e..4168af51 100644 --- a/tests/Api/ReferenceEntity/ListAllReferenceEntitiesIntegration.php +++ b/tests/Api/ReferenceEntity/ListAllReferenceEntitiesIntegration.php @@ -15,7 +15,7 @@ class ListAllReferenceEntitiesIntegration extends ApiTestCase public function test_list_per_page() { $this->server->setResponseOfPath( - '/'. ReferenceEntityApi::REFERENCE_ENTITIES_URI, + '/' . ReferenceEntityApi::REFERENCE_ENTITIES_URI, new ResponseStack( new Response($this->getFirstPage(), [], 200), new Response($this->getSecondPage(), [], 200) @@ -82,7 +82,6 @@ private function getFirstPage(): string } } JSON; - } private function getSecondPage(): string @@ -120,6 +119,5 @@ private function getSecondPage(): string } } JSON; - } } diff --git a/tests/Api/ReferenceEntity/UpsertReferenceEntityIntegration.php b/tests/Api/ReferenceEntity/UpsertReferenceEntityIntegration.php index 940056c6..a9f96d3c 100644 --- a/tests/Api/ReferenceEntity/UpsertReferenceEntityIntegration.php +++ b/tests/Api/ReferenceEntity/UpsertReferenceEntityIntegration.php @@ -14,7 +14,7 @@ class UpsertReferenceEntityIntegration extends ApiTestCase public function test_upsert_reference_entity() { $this->server->setResponseOfPath( - '/'. sprintf(ReferenceEntityApi::REFERENCE_ENTITY_URI, 'brand'), + '/' . sprintf(ReferenceEntityApi::REFERENCE_ENTITY_URI, 'brand'), new ResponseStack( new Response('', [], 204) ) diff --git a/tests/Api/ReferenceEntityRecord/GetReferenceEntityRecordIntegration.php b/tests/Api/ReferenceEntityRecord/GetReferenceEntityRecordIntegration.php index 7a4d94c3..3576a69d 100644 --- a/tests/Api/ReferenceEntityRecord/GetReferenceEntityRecordIntegration.php +++ b/tests/Api/ReferenceEntityRecord/GetReferenceEntityRecordIntegration.php @@ -16,7 +16,7 @@ class GetReferenceEntityRecordIntegration extends ApiTestCase public function test_get_reference_entity_record() { $this->server->setResponseOfPath( - '/'. sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORD_URI, 'designer', 'starck'), + '/' . sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORD_URI, 'designer', 'starck'), new ResponseStack( new Response($this->getStarckRecord(), [], 200) ) @@ -34,7 +34,7 @@ public function test_get_unknow_product() $this->expectExceptionMessage("Record \"foo\" does not exist for the reference entity \"designer\"."); $this->expectException(\Akeneo\Pim\ApiClient\Exception\NotFoundHttpException::class); $this->server->setResponseOfPath( - '/'. sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORD_URI, 'designer', 'foo'), + '/' . sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORD_URI, 'designer', 'foo'), new ResponseStack( new Response('{"code": 404, "message":"Record \"foo\" does not exist for the reference entity \"designer\"."}', [], 404) ) diff --git a/tests/Api/ReferenceEntityRecord/ListAllReferenceEntityRecordsIntegration.php b/tests/Api/ReferenceEntityRecord/ListAllReferenceEntityRecordsIntegration.php index 336bcda1..d1a6d7dd 100644 --- a/tests/Api/ReferenceEntityRecord/ListAllReferenceEntityRecordsIntegration.php +++ b/tests/Api/ReferenceEntityRecord/ListAllReferenceEntityRecordsIntegration.php @@ -15,7 +15,7 @@ class ListAllReferenceEntityRecordsIntegration extends ApiTestCase public function test_list_per_page() { $this->server->setResponseOfPath( - '/'. sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORDS_URI, 'designer'), + '/' . sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORDS_URI, 'designer'), new ResponseStack( new Response($this->getFirstPage(), [], 200), new Response($this->getSecondPage(), [], 200) @@ -86,7 +86,6 @@ private function getFirstPage(): string } } JSON; - } private function getSecondPage(): string @@ -126,6 +125,5 @@ private function getSecondPage(): string } } JSON; - } } diff --git a/tests/Api/ReferenceEntityRecord/UpsertListReferenceEntityRecordIntegration.php b/tests/Api/ReferenceEntityRecord/UpsertListReferenceEntityRecordIntegration.php index ab5d32c1..8f11902a 100644 --- a/tests/Api/ReferenceEntityRecord/UpsertListReferenceEntityRecordIntegration.php +++ b/tests/Api/ReferenceEntityRecord/UpsertListReferenceEntityRecordIntegration.php @@ -27,7 +27,7 @@ public function test_upsert_a_list_of_reference_entity_records() JSON; $this->server->setResponseOfPath( - '/'. sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORDS_URI, 'designer'), + '/' . sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORDS_URI, 'designer'), new ResponseStack( new Response($responseBody, [], 200) ) @@ -40,8 +40,8 @@ public function test_upsert_a_list_of_reference_entity_records() 'label' => [ [ 'channel' => null, - 'locale' => 'en_US', - 'data' => 'Philippe Starck' + 'locale' => 'en_US', + 'data' => 'Philippe Starck' ], ] ] @@ -52,8 +52,8 @@ public function test_upsert_a_list_of_reference_entity_records() 'label' => [ [ 'channel' => null, - 'locale' => 'en_US', - 'data' => 'James Dyson' + 'locale' => 'en_US', + 'data' => 'James Dyson' ], ] ] @@ -63,11 +63,11 @@ public function test_upsert_a_list_of_reference_entity_records() $expectedResponses = [ [ 'code' => 'starck', - 'status_code' =>204 + 'status_code' => 204 ], [ 'code' => 'dyson', - 'status_code' =>201 + 'status_code' => 201 ], ]; diff --git a/tests/Api/ReferenceEntityRecord/UpsertReferenceEntityRecordIntegration.php b/tests/Api/ReferenceEntityRecord/UpsertReferenceEntityRecordIntegration.php index e7e12048..764523d4 100644 --- a/tests/Api/ReferenceEntityRecord/UpsertReferenceEntityRecordIntegration.php +++ b/tests/Api/ReferenceEntityRecord/UpsertReferenceEntityRecordIntegration.php @@ -14,7 +14,7 @@ class UpsertReferenceEntityRecordIntegration extends ApiTestCase public function test_upsert_reference_entity_record() { $this->server->setResponseOfPath( - '/'. sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORD_URI, 'designer', 'starck'), + '/' . sprintf(ReferenceEntityRecordApi::REFERENCE_ENTITY_RECORD_URI, 'designer', 'starck'), new ResponseStack( new Response('', [], 204) ) @@ -26,8 +26,8 @@ public function test_upsert_reference_entity_record() 'label' => [ [ 'channel' => null, - 'locale' => 'en_US', - 'data' => 'Philippe Starck' + 'locale' => 'en_US', + 'data' => 'Philippe Starck' ], ] ] diff --git a/tests/Api/UpsertListProductTest.php b/tests/Api/UpsertListProductTest.php index 138a0e20..ecad688b 100644 --- a/tests/Api/UpsertListProductTest.php +++ b/tests/Api/UpsertListProductTest.php @@ -15,7 +15,7 @@ public function setUp(): void { parent::setUp(); $this->server->setResponseOfPath( - '/'. ProductApi::PRODUCTS_URI, + '/' . ProductApi::PRODUCTS_URI, new ResponseStack( new Response($this->getResults(), [], 200) ) @@ -35,14 +35,14 @@ public function test_upsert_list() Assert::assertCount(2, $responseLines); Assert::assertSame([ - 'line' => 1, - 'identifier' => 'docks_black', + 'line' => 1, + 'identifier' => 'docks_black', 'status_code' => 204, ], $responseLines[1]); Assert::assertSame([ - 'line' => 2, - 'identifier' => 'pumps', + 'line' => 2, + 'identifier' => 'pumps', 'status_code' => 201, ], $responseLines[2]); } @@ -65,14 +65,14 @@ public function test_upsert_list_from_stream() Assert::assertCount(2, $responseLines); Assert::assertSame([ - 'line' => 1, - 'identifier' => 'docks_black', + 'line' => 1, + 'identifier' => 'docks_black', 'status_code' => 204, ], $responseLines[1]); Assert::assertSame([ - 'line' => 2, - 'identifier' => 'pumps', + 'line' => 2, + 'identifier' => 'pumps', 'status_code' => 201, ], $responseLines[2]); } @@ -90,33 +90,33 @@ private function getProductToUpsert(): array return [ [ 'identifier' => 'docks_black', - 'enabled' => false, - 'values' => [ + 'enabled' => false, + 'values' => [ 'name' => [ [ 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black Docks', + 'scope' => null, + 'data' => 'Black Docks', ], ], ] ], [ 'identifier' => 'pumps', - 'enabled' => false, - 'family' => 'sandals', + 'enabled' => false, + 'family' => 'sandals', 'categories' => ['summer_collection'], - 'values' => [ + 'values' => [ 'name' => [ [ - 'data' => 'The pumps', + 'data' => 'The pumps', 'locale' => 'en_US', - 'scope' => null, + 'scope' => null, ], [ - 'data' => 'Les pumps', + 'data' => 'Les pumps', 'locale' => 'fr_FR', - 'scope' => null, + 'scope' => null, ] ], ] @@ -131,5 +131,4 @@ private function getResults(): string {"line": 2,"identifier": "pumps","status_code": 201} JSON; } - } diff --git a/tests/Api/UpsertProductTest.php b/tests/Api/UpsertProductTest.php index 01172c26..f522bec1 100644 --- a/tests/Api/UpsertProductTest.php +++ b/tests/Api/UpsertProductTest.php @@ -13,7 +13,7 @@ class UpsertProductTest extends ApiTestCase public function test_upsert_product() { $this->server->setResponseOfPath( - '/'. sprintf(ProductApi::PRODUCT_URI, 'docks_black'), + '/' . sprintf(ProductApi::PRODUCT_URI, 'docks_black'), new ResponseStack( new Response('', [], 204) ) @@ -23,12 +23,12 @@ public function test_upsert_product() $parameters = [ 'enabled' => false, - 'values' => [ + 'values' => [ 'name' => [ [ 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black Docks', + 'scope' => null, + 'data' => 'Black Docks', ], ], ] @@ -39,5 +39,4 @@ public function test_upsert_product() Assert::assertSame(204, $response); } - } diff --git a/tests/Cache/AkeneoPimClientBuilderTest.php b/tests/Cache/AkeneoPimClientBuilderTest.php index 75e23fef..09a720cf 100644 --- a/tests/Cache/AkeneoPimClientBuilderTest.php +++ b/tests/Cache/AkeneoPimClientBuilderTest.php @@ -1,4 +1,5 @@ server->setResponseOfPath( - '/'.sprintf(ProductApi::PRODUCT_URI, 'black_sneakers'), + '/' . sprintf(ProductApi::PRODUCT_URI, 'black_sneakers'), new ResponseStack( new Response($this->getProduct(), [], 200) ) diff --git a/tests/Cache/LRUCacheTest.php b/tests/Cache/LRUCacheTest.php index f1d8a639..1b703be8 100644 --- a/tests/Cache/LRUCacheTest.php +++ b/tests/Cache/LRUCacheTest.php @@ -39,4 +39,4 @@ public function testRemovesLru(): void $this->assertSame([4], $cache->get('d')); $this->assertSame([5], $cache->get('e')); } -} \ No newline at end of file +} diff --git a/tests/Client/CachedResourceClientTest.php b/tests/Client/CachedResourceClientTest.php index 849bb78a..443a0a6a 100644 --- a/tests/Client/CachedResourceClientTest.php +++ b/tests/Client/CachedResourceClientTest.php @@ -19,7 +19,7 @@ public function test_get_cached_resource(): void $uri = 'uri'; $uriParameters = ['uriParameter']; - $cacheKey = md5($uri.implode('', $uriParameters)); + $cacheKey = md5($uri . implode('', $uriParameters)); $mockCache ->expects(self::exactly(2)) @@ -42,4 +42,4 @@ public function test_get_cached_resource(): void self::assertSame(['resource'], $cachedResourceClient->getResource($uri, $uriParameters)); self::assertSame(['cachedValue'], $cachedResourceClient->getResource($uri, $uriParameters)); } -} \ No newline at end of file +}