Skip to content

Commit

Permalink
Coding standards v3
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Jul 2, 2024
1 parent 7a9aa99 commit 0877591
Show file tree
Hide file tree
Showing 245 changed files with 22,374 additions and 21,380 deletions.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"role": "Maintainer"
}
],
"repositories": [{
"type": "path",
"url": "../coding-standards-php"
}
],
"minimum-stability": "dev",
"require": {
"php": "^8.1",
Expand Down Expand Up @@ -53,7 +58,7 @@
"zumba/amplitude-php": "^1.0.4"
},
"require-dev": {
"acquia/coding-standards": "^2",
"acquia/coding-standards": "*",
"brianium/paratest": "^6.6",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"dominikb/composer-license-checker": "^2.4",
Expand Down
25 changes: 10 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 2 additions & 31 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,7 @@
<!-- @see https://github.com/squizlabs/PHP_CodeSniffer/issues/981 -->
<exclude-pattern>tests/fixtures/*</exclude-pattern>

<rule ref="AcquiaPHP" />

<rule ref="Drupal.Commenting.InlineComment"/>
<rule ref="SlevomatCodingStandard.Arrays.AlphabeticallySortedByKeys" />
<rule ref="SlevomatCodingStandard.Arrays.DisallowImplicitArrayCreation"/>
<rule ref="SlevomatCodingStandard.Arrays.MultiLineArrayEndBracketPlacement"/>
<rule ref="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace"/>
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>

<rule ref="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion" />
<rule ref="SlevomatCodingStandard.Commenting.DeprecatedAnnotationDeclaration" />
<rule ref="SlevomatCodingStandard.Commenting.DisallowCommentAfterCode" />
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing" />
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment" />
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
<properties>
<property name="forbiddenAnnotations" type="array" value="@author,@created,@version,@package,@copyright,@license,@throws" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenComments">
<properties>
<property name="forbiddenCommentPatterns" type="array" value="/Class .*/" />
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration" />
<rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment" />
<rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment" />
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes" />
<rule ref="AcquiaPHPStrict" />

<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
Expand All @@ -62,4 +32,5 @@
</property>
</properties>
</rule>

</ruleset>
54 changes: 27 additions & 27 deletions src/AcsfApi/AcsfClient.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace Acquia\Cli\AcsfApi;

use AcquiaCloudApi\Connector\Client;
use AcquiaCloudApi\Exception\ApiErrorException;
use Psr\Http\Message\ResponseInterface;

class AcsfClient extends Client {

public function processResponse(ResponseInterface $response): mixed {
$bodyJson = $response->getBody();
$body = json_decode((string) $bodyJson, FALSE, 512, JSON_THROW_ON_ERROR);

// ACSF sometimes returns an array rather than an object.
if (is_array($body)) {
return $body;
class AcsfClient extends Client
{
public function processResponse(ResponseInterface $response): mixed
{
$bodyJson = $response->getBody();
$body = json_decode((string) $bodyJson, false, 512, JSON_THROW_ON_ERROR);

// ACSF sometimes returns an array rather than an object.
if (is_array($body)) {
return $body;
}

if (property_exists($body, '_embedded') && property_exists($body->_embedded, 'items')) {
return $body->_embedded->items;
}

if (property_exists($body, 'error') && property_exists($body, 'message')) {
throw new ApiErrorException($body);
}
// Throw error for 4xx and 5xx responses.
if (property_exists($body, 'message') && in_array(substr((string) $response->getStatusCode(), 0, 1), ['4', '5'], true)) {
$body->error = $response->getStatusCode();
throw new ApiErrorException($body);
}

return $body;
}

if (property_exists($body, '_embedded') && property_exists($body->_embedded, 'items')) {
return $body->_embedded->items;
}

if (property_exists($body, 'error') && property_exists($body, 'message')) {
throw new ApiErrorException($body);
}
// Throw error for 4xx and 5xx responses.
if (property_exists($body, 'message') && in_array(substr((string) $response->getStatusCode(), 0, 1), ['4', '5'], TRUE)) {
$body->error = $response->getStatusCode();
throw new ApiErrorException($body);
}

return $body;
}

}
38 changes: 20 additions & 18 deletions src/AcsfApi/AcsfClientService.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace Acquia\Cli\AcsfApi;

use Acquia\Cli\Application;
use Acquia\Cli\CloudApi\ClientService;

class AcsfClientService extends ClientService {

public function __construct(AcsfConnectorFactory $connectorFactory, Application $application, AcsfCredentials $cloudCredentials) {
parent::__construct($connectorFactory, $application, $cloudCredentials);
}

public function getClient(): AcsfClient {
$client = AcsfClient::factory($this->connector);
$this->configureClient($client);

return $client;
}

protected function checkAuthentication(): bool {
return ($this->credentials->getCloudKey() && $this->credentials->getCloudSecret());
}

class AcsfClientService extends ClientService
{
public function __construct(AcsfConnectorFactory $connectorFactory, Application $application, AcsfCredentials $cloudCredentials)
{
parent::__construct($connectorFactory, $application, $cloudCredentials);
}

public function getClient(): AcsfClient
{
$client = AcsfClient::factory($this->connector);
$this->configureClient($client);

return $client;
}

protected function checkAuthentication(): bool
{
return ($this->credentials->getCloudKey() && $this->credentials->getCloudSecret());
}
}
51 changes: 26 additions & 25 deletions src/AcsfApi/AcsfConnector.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace Acquia\Cli\AcsfApi;

use AcquiaCloudApi\Connector\Connector;
use GuzzleHttp\Client as GuzzleClient;
use Psr\Http\Message\ResponseInterface;

class AcsfConnector extends Connector {

/**
* @param array<string> $config
* @param string|null $baseUri
* @param string|null $urlAccessToken
*/
public function __construct(array $config, string $baseUri = NULL, string $urlAccessToken = NULL) {
parent::__construct($config, $baseUri, $urlAccessToken);

$this->client = new GuzzleClient([
'auth' => [
class AcsfConnector extends Connector
{
/**
* @param array<string> $config
* @param string|null $baseUri
* @param string|null $urlAccessToken
*/
public function __construct(array $config, string $baseUri = null, string $urlAccessToken = null)
{
parent::__construct($config, $baseUri, $urlAccessToken);

$this->client = new GuzzleClient([
'auth' => [
$config['key'],
$config['secret'],
],
'base_uri' => $this->getBaseUri(),
]);
}

/**
* @param array<string> $options
*/
public function sendRequest(string $verb, string $path, array $options): ResponseInterface {
return $this->client->request($verb, $path, $options);
}

],
'base_uri' => $this->getBaseUri(),
]);
}

/**
* @param array<string> $options
*/
public function sendRequest(string $verb, string $path, array $options): ResponseInterface
{
return $this->client->request($verb, $path, $options);
}
}
25 changes: 13 additions & 12 deletions src/AcsfApi/AcsfConnectorFactory.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace Acquia\Cli\AcsfApi;

use Acquia\Cli\ConnectorFactoryInterface;

class AcsfConnectorFactory implements ConnectorFactoryInterface {

/**
* @param array<string> $config
*/
public function __construct(protected array $config, protected ?string $baseUri = NULL) {
}

public function createConnector(): AcsfConnector {
return new AcsfConnector($this->config, $this->baseUri);
}
class AcsfConnectorFactory implements ConnectorFactoryInterface
{
/**
* @param array<string> $config
*/
public function __construct(protected array $config, protected ?string $baseUri = null)
{
}

public function createConnector(): AcsfConnector
{
return new AcsfConnector($this->config, $this->baseUri);
}
}
Loading

0 comments on commit 0877591

Please sign in to comment.