Skip to content

Commit

Permalink
refact(API-1925): Run ECS
Browse files Browse the repository at this point in the history
  • Loading branch information
LevFlavien committed Nov 7, 2022
1 parent 2427e6c commit f12cd6f
Show file tree
Hide file tree
Showing 103 changed files with 563 additions and 293 deletions.
42 changes: 40 additions & 2 deletions src/AkeneoPimClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,46 @@
*/
class AkeneoPimClient implements AkeneoPimClientInterface
{
public function __construct(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)
{
public function __construct(
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
) {
}

/**
Expand Down
22 changes: 16 additions & 6 deletions src/AkeneoPimClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ class AkeneoPimClientBuilder
/**
* @param string $baseUri Base uri to request the API
*/
public function __construct(protected string $baseUri, array $options = [])
{
public function __construct(
protected string $baseUri,
array $options = []
) {
$this->options = Options::fromArray($options);
}

Expand Down Expand Up @@ -142,8 +144,12 @@ public function setFileSystem(FileSystemInterface $fileSystem): self
* @param string $username Username to use for the authentication
* @param string $password Password associated to the username
*/
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);
Expand All @@ -164,8 +170,12 @@ public function buildAuthenticatedByAppToken(string $token): AkeneoPimClientInte
* @param string $token Token to use for the authentication
* @param string $refreshToken Token to use to refresh the access token
*/
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);
Expand Down
7 changes: 5 additions & 2 deletions src/Api/AppCatalog/AppCatalogApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ class AppCatalogApi implements AppCatalogApiInterface
public const APP_CATALOGS_URI = 'api/rest/v1/catalogs';
public const APP_CATALOG_URI = 'api/rest/v1/catalogs/%s';

public function __construct(protected ResourceClientInterface $resourceClient, protected PageFactoryInterface $pageFactory, protected ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
protected ResourceClientInterface $resourceClient,
protected PageFactoryInterface $pageFactory,
protected ResourceCursorFactoryInterface $cursorFactory
) {
}

public function listPerPage(int $limit = 100, bool $withCount = false, array $queryParameters = []): PageInterface
Expand Down
7 changes: 5 additions & 2 deletions src/Api/AppCatalog/AppCatalogProductApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ class AppCatalogProductApi implements AppCatalogProductApiInterface
{
public const APP_CATALOG_PRODUCT_URI = '/api/rest/v1/catalogs/%s/product-uuids';

public function __construct(protected ResourceClientInterface $resourceClient, protected PageFactoryInterface $pageFactory, protected ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
protected ResourceClientInterface $resourceClient,
protected PageFactoryInterface $pageFactory,
protected ResourceCursorFactoryInterface $cursorFactory
) {
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Api/AssetApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ class AssetApi implements AssetApiInterface
public const ASSETS_URI = '/api/rest/v1/assets';
public const ASSET_URI = '/api/rest/v1/assets/%s';

public function __construct(private ResourceClientInterface $resourceClient, private PageFactoryInterface $pageFactory, private ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
private ResourceClientInterface $resourceClient,
private PageFactoryInterface $pageFactory,
private ResourceCursorFactoryInterface $cursorFactory
) {
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Api/AssetCategoryApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ class AssetCategoryApi implements AssetCategoryApiInterface
public const ASSET_CATEGORIES_URI = '/api/rest/v1/asset-categories';
public const ASSET_CATEGORY_URI = '/api/rest/v1/asset-categories/%s';

public function __construct(private ResourceClientInterface $resourceClient, private PageFactoryInterface $pageFactory, private ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
private ResourceClientInterface $resourceClient,
private PageFactoryInterface $pageFactory,
private ResourceCursorFactoryInterface $cursorFactory
) {
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Api/AssetManager/AssetApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

class AssetApi implements AssetApiInterface
{
public const ASSET_URI= 'api/rest/v1/asset-families/%s/assets/%s';
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(private ResourceClientInterface $resourceClient, private PageFactoryInterface $pageFactory, private ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
private ResourceClientInterface $resourceClient,
private PageFactoryInterface $pageFactory,
private ResourceCursorFactoryInterface $cursorFactory
) {
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Api/AssetManager/AssetAttributeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class AssetAttributeApi implements AssetAttributeApiInterface
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';

public function __construct(private ResourceClientInterface $resourceClient)
{
public function __construct(
private ResourceClientInterface $resourceClient
) {
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Api/AssetManager/AssetAttributeOptionApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class AssetAttributeOptionApi implements AssetAttributeOptionApiInterface
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';

public function __construct(private ResourceClientInterface $resourceClient)
{
public function __construct(
private ResourceClientInterface $resourceClient
) {
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Api/AssetManager/AssetFamilyApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
class AssetFamilyApi implements AssetFamilyApiInterface
{
public const ASSET_FAMILY_URI = 'api/rest/v1/asset-families/%s';
public const ASSET_FAMILIES_URI= 'api/rest/v1/asset-families';
public const ASSET_FAMILIES_URI = 'api/rest/v1/asset-families';

public function __construct(private ResourceClientInterface $resourceClient, private PageFactoryInterface $pageFactory, private ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
private ResourceClientInterface $resourceClient,
private PageFactoryInterface $pageFactory,
private ResourceCursorFactoryInterface $cursorFactory
) {
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Api/AssetManager/AssetMediaFileApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class AssetMediaFileApi implements AssetMediaFileApiInterface
public const MEDIA_FILE_DOWNLOAD_URI = 'api/rest/v1/asset-media-files/%s';
public const MEDIA_FILE_CREATE_URI = 'api/rest/v1/asset-media-files';

public function __construct(private ResourceClientInterface $resourceClient, private FileSystemInterface $fileSystem)
{
public function __construct(
private ResourceClientInterface $resourceClient,
private FileSystemInterface $fileSystem
) {
}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/Api/AssetReferenceFileApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ class AssetReferenceFileApi implements AssetReferenceFileApiInterface
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)
{
public function __construct(
private ResourceClientInterface $resourceClient,
private FileSystemInterface $fileSystem
) {
}

/**
Expand Down Expand Up @@ -92,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();
Expand Down
7 changes: 5 additions & 2 deletions src/Api/AssetTagApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ class AssetTagApi implements AssetTagApiInterface
public const ASSET_TAGS_URI = '/api/rest/v1/asset-tags';
public const ASSET_TAG_URI = '/api/rest/v1/asset-tags/%s';

public function __construct(private ResourceClientInterface $resourceClient, private PageFactoryInterface $pageFactory, private ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
private ResourceClientInterface $resourceClient,
private PageFactoryInterface $pageFactory,
private ResourceCursorFactoryInterface $cursorFactory
) {
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Api/AssetVariationFileApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class AssetVariationFileApi implements AssetVariationFileApiInterface
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)
{
public function __construct(
private ResourceClientInterface $resourceClient,
private FileSystemInterface $fileSystem
) {
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Api/AssociationTypeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ class AssociationTypeApi implements AssociationTypeApiInterface
public const ASSOCIATION_TYPES_URI = 'api/rest/v1/association-types';
public const ASSOCIATION_TYPE_URI = 'api/rest/v1/association-types/%s';

public function __construct(protected ResourceClientInterface $resourceClient, protected PageFactoryInterface $pageFactory, protected ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
protected ResourceClientInterface $resourceClient,
protected PageFactoryInterface $pageFactory,
protected ResourceCursorFactoryInterface $cursorFactory
) {
}
/**
* {@inheritdoc}
Expand Down
7 changes: 5 additions & 2 deletions src/Api/AttributeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ class AttributeApi implements AttributeApiInterface
public const ATTRIBUTES_URI = 'api/rest/v1/attributes';
public const ATTRIBUTE_URI = 'api/rest/v1/attributes/%s';

public function __construct(protected ResourceClientInterface $resourceClient, protected PageFactoryInterface $pageFactory, protected ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
protected ResourceClientInterface $resourceClient,
protected PageFactoryInterface $pageFactory,
protected ResourceCursorFactoryInterface $cursorFactory
) {
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Api/AttributeGroupApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ class AttributeGroupApi implements AttributeGroupApiInterface
public const ATTRIBUTE_GROUP_URI = 'api/rest/v1/attribute-groups/%s';
public const ATTRIBUTE_GROUPS_URI = 'api/rest/v1/attribute-groups';

public function __construct(protected ResourceClientInterface $resourceClient, protected PageFactoryInterface $pageFactory, protected ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
protected ResourceClientInterface $resourceClient,
protected PageFactoryInterface $pageFactory,
protected ResourceCursorFactoryInterface $cursorFactory
) {
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Api/AttributeOptionApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ class AttributeOptionApi implements AttributeOptionApiInterface
public const ATTRIBUTE_OPTIONS_URI = 'api/rest/v1/attributes/%s/options';
public const ATTRIBUTE_OPTION_URI = 'api/rest/v1/attributes/%s/options/%s';

public function __construct(protected ResourceClientInterface $resourceClient, protected PageFactoryInterface $pageFactory, protected ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
protected ResourceClientInterface $resourceClient,
protected PageFactoryInterface $pageFactory,
protected ResourceCursorFactoryInterface $cursorFactory
) {
}

/**
Expand Down
14 changes: 8 additions & 6 deletions src/Api/AuthenticationApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class AuthenticationApi implements AuthenticationApiInterface
{
public const TOKEN_URI = 'api/oauth/v1/token';

public function __construct(protected HttpClient $httpClient, protected UriGeneratorInterface $uriGenerator)
{
public function __construct(
protected HttpClient $httpClient,
protected UriGeneratorInterface $uriGenerator
) {
}

/**
Expand All @@ -27,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);
Expand All @@ -40,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
];

Expand All @@ -59,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)),
];

Expand Down
7 changes: 5 additions & 2 deletions src/Api/CategoryApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ class CategoryApi implements CategoryApiInterface
public const CATEGORY_URI = 'api/rest/v1/categories/%s';
public const CATEGORIES_URI = 'api/rest/v1/categories';

public function __construct(protected ResourceClientInterface $resourceClient, protected PageFactoryInterface $pageFactory, protected ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
protected ResourceClientInterface $resourceClient,
protected PageFactoryInterface $pageFactory,
protected ResourceCursorFactoryInterface $cursorFactory
) {
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Api/ChannelApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ class ChannelApi implements ChannelApiInterface
public const CHANNELS_URI = 'api/rest/v1/channels';
public const CHANNEL_URI = 'api/rest/v1/channels/%s';

public function __construct(protected ResourceClientInterface $resourceClient, protected PageFactoryInterface $pageFactory, protected ResourceCursorFactoryInterface $cursorFactory)
{
public function __construct(
protected ResourceClientInterface $resourceClient,
protected PageFactoryInterface $pageFactory,
protected ResourceCursorFactoryInterface $cursorFactory
) {
}

/**
Expand Down
Loading

0 comments on commit f12cd6f

Please sign in to comment.