Skip to content

Commit

Permalink
Merge pull request #197 from palantirnet/the-build-coding-standard
Browse files Browse the repository at this point in the history
Update coding standards in the-build.
  • Loading branch information
byrond authored Jan 5, 2023
2 parents 0e54453 + bd356d0 commit 520f344
Show file tree
Hide file tree
Showing 10 changed files with 409 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Install, update and uninstall functions for the-build utility module.
*/

use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Drupal\shortcut\Entity\Shortcut;

/**
Expand Down Expand Up @@ -54,23 +52,34 @@ function the_build_utility_install() {
$date_settings->save(TRUE);

// Install modules that we want but are not included with standard profile.
$install = ['admin_toolbar', 'admin_toolbar_tools', 'config_split', 'devel', 'workbench', 'workbench_tabs'];
$install = [
'admin_toolbar',
'admin_toolbar_tools',
'config_split',
'devel',
'workbench',
'workbench_tabs',
];
\Drupal::service('module_installer')->install($install);

// Remove any entity dependencies so we can uninstall modules.

// Begin Comment module.
// Remove the comment fields.
// Remove comment fields so that comment module can be uninstalled.
$fields = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['type' => 'comment']);
foreach ($fields as $field) {
$field->delete();
}

// Remove state setting.
// Remove state variable from comment module.
\Drupal::state()->delete('comment.node_comment_statistics_scale');
// End Comment module.

// Uninstall the modules from the standard profile that we don't want.
$uninstall = ['automated_cron', 'big_pipe', 'comment', 'contact', 'history', 'search', 'tour'];
$uninstall = [
'automated_cron',
'big_pipe',
'comment',
'contact',
'history',
'search',
'tour',
];
\Drupal::service('module_installer')->uninstall($uninstall);
}
35 changes: 35 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>

<!--
@see https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml#the-annotated-sample-file
@see https://www.drupal.org/docs/develop/standards
@see https://github.com/squizlabs/PHP_CodeSniffer
@see https://www.drupal.org/project/coder
@see vendor/drupal/coder/coder_sniffer/
-->

<ruleset name="palantirnet/the-build">
<description>PHP_CodeSniffer configuration.</description>

<!-- Warnings and errors should throw an exception. -->
<config name="ignore_warnings_on_exit" value="0" />
<config name="ignore_errors_on_exit" value="0" />

<!-- Set extensions to scan. -->
<arg name="extensions" value="php,module,inc,install,test,profile,theme,info,yml,css,js"/>

<!-- Use colors in output. -->
<arg name="colors"/>

<!-- Show progress. -->
<arg value="p"/>

<!-- Include existing standards. -->
<rule ref="Drupal"/>
<rule ref="DrupalPractice"/>

<!-- Directories to scan. -->
<file>src</file>
<file>defaults/standard/modules/the_build_utility</file>

</ruleset>
85 changes: 40 additions & 45 deletions src/TheBuild/Acquia/AcquiaTask.php
Original file line number Diff line number Diff line change
@@ -1,57 +1,43 @@
<?php
/**
* @file AcquiaTask.php
*
* Abastract base task for creating Acquia Cloud API tasks.
*
* Loads the Acquia Cloud credentials from a JSON file and constructs
* authenticated requests against the Cloud API.
*
* This class will use the credentials file at ~/.acquia/cloudapi.conf if none
* is provided in the task call:
*
* @code
* <exampleTask credentialsFile="artifacts/cloudapi.conf" />
* @endcode
*
* Extending classes may also set the 'endpoint' property if it is necessary to
* use the v2 API instead of v1.
*
* @copyright 2018 Palantir.net, Inc.
*/

namespace TheBuild\Acquia;

use BuildException;
use HTTP_Request2;
use PhingFile;

/**
* Phing task for making queries against the Acquia Cloud v1 API.
*/
abstract class AcquiaTask extends \Task {

/**
* Required. The Acquia Cloud credentials file containing a json array with
* 'mail' and 'key' values.
* Required. The Acquia Cloud credentials file.
*
* This file can be downloaded from your Acquia user account area and contains
* a json array with 'mail' and 'key' values.
*
* @var \PhingFile
*/
protected $credentialsFile;

/**
* Email address associated with the Acquia Cloud access. This value is set
* from the credentials file.
* Email address associated with the Acquia Cloud access.
*
* This value is set from the credentials file.
*
* @var string
*/
protected $mail;

/**
* Secure key associated with the Acquia Cloud access. This value is set from
* the credentials file.
* Secure key associated with the Acquia Cloud access.
*
* This value is set from the credentials file.
*
* @var string
*/
protected $key;

/**
* The Acquia Cloud API endpoint. This code is specific to version 1 of the
* API.
* The Acquia Cloud API v1 endpoint.
*
* @var string
*/
protected $endpoint = 'https://cloudapi.acquia.com/v1';
Expand All @@ -65,11 +51,11 @@ abstract class AcquiaTask extends \Task {
protected function loadCredentials() {
if (empty($this->mail) || empty($this->key)) {
if (empty($this->credentialsFile)) {
$this->credentialsFile = new PhingFile($_SERVER['HOME'] . '/.acquia/cloudapi.conf');
$this->credentialsFile = new \PhingFile($_SERVER['HOME'] . '/.acquia/cloudapi.conf');
}

if (!file_exists($this->credentialsFile) || !is_readable($this->credentialsFile)) {
throw new BuildException("Acquia Cloud credentials file '{$this->credentialsFile}' is not available.");
throw new \BuildException("Acquia Cloud credentials file '{$this->credentialsFile}' is not available.");
}

$contents = file_get_contents($this->credentialsFile);
Expand All @@ -80,22 +66,25 @@ protected function loadCredentials() {
}

if (empty($this->mail) || empty($this->key)) {
throw new BuildException('Missing Acquia Cloud API credentials.');
throw new \BuildException('Missing Acquia Cloud API credentials.');
}
}

/**
* Build an HTTP request object against the Acquia Cloud API.
*
* @param $path
* @return HTTP_Request2
* @param string $path
* Acquia Cloud API path.
*
* @return \HTTP_Request2
* Request object.
*/
protected function createRequest($path) {
protected function createRequest(string $path) : \HTTP_Request2 {
$this->loadCredentials();

$uri = $this->endpoint . '/' . ltrim($path, '/');

$request = new HTTP_Request2($uri);
$request = new \HTTP_Request2($uri);
$request->setConfig('follow_redirects', TRUE);
$request->setAuth($this->mail, $this->key);

Expand All @@ -105,11 +94,13 @@ protected function createRequest($path) {
/**
* Example of how to query the Acquia Cloud API.
*
* @param $path
* @param string $path
* Acquia Cloud API path.
*
* @return string
* @throws \HTTP_Request2_Exception
* API response.
*/
protected function getApiResponseBody($path) {
protected function getApiResponseBody(string $path) : string {
$request = $this->createRequest($path);

$this->log('GET ' . $request->getUrl());
Expand All @@ -118,12 +109,16 @@ protected function getApiResponseBody($path) {
}

/**
* @param PhingFile $file
* Set the Acquia credentials file.
*
* @param \PhingFile $file
* Acquia credentials file.
*
* @throws \IOException
* @throws \NullPointerException
*/
public function setCredentialsFile(PhingFile $file) {
$this->credentialsFile = new PhingFile($file);
public function setCredentialsFile(\PhingFile $file) {
$this->credentialsFile = new \PhingFile($file);
}

}
Loading

0 comments on commit 520f344

Please sign in to comment.