Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds php coding standards config #204

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
version: 2.1
jobs:
build:
working_directory: ~/example
working_directory: ~/project
docker:
- image: cimg/php:8.1-browsers
- image: cimg/mysql:5.7
Expand All @@ -31,6 +31,18 @@ jobs:
name: Update Composer
command: |
sudo composer self-update

# Run code quality checks
- checkout
- run:
name: Run code reviews
command: |
composer install
vendor/bin/phpcs src --standard="Drupal,DrupalPractice"
vendor/bin/phpmd src text defaults/standard/phpmd.xml "php,inc,module,theme,profile,install,test"
vendor/bin/phpstan analyse src

# Install a drupal test project.
- run:
name: Create artifacts directory
command: mkdir /tmp/artifacts
Expand Down Expand Up @@ -58,6 +70,7 @@ jobs:
- run:
name: Replace the default version of the-build with this one
command: composer require --dev --with-all-dependencies palantirnet/the-build:dev-${CIRCLE_BRANCH}
working_directory: ~/example

# Source cache - update when branch changes
- save_cache:
Expand All @@ -69,16 +82,19 @@ jobs:
- run:
name: Install the-build in the project
command: printf '\n\n\nn' | vendor/bin/the-build-installer
working_directory: ~/example

- run:
name: Wait for DB
# Dockerize is preinstalled in circleci/* docker image
command: dockerize -wait tcp://127.0.0.1:3306 -timeout 120s
working_directory: ~/example

# Install Drupal (separately, so that we can see it fail separately)
- run:
name: Install Drupal
command: printf 'y' | vendor/bin/phing install -Ddrupal.validate_clean_config.bypass=yes
working_directory: ~/example

# Composer package cache - update when the contents of the Composer cache directory
# change. This cache is saved after installing Drupal, as the install process uses
Expand All @@ -93,12 +109,14 @@ jobs:
- run:
name: Add a multisite to the project
command: printf 'intranet\nintranet.example.ddev.site' | vendor/bin/phing drupal-add-multisite
working_directory: ~/example

- run:
name: Run Behat tests
command: |
nohup php -S example.ddev.site:8000 -t $(pwd)/${DRUPAL_ROOT}/ > /tmp/artifacts/phpd.log 2>&1 &
vendor/bin/phing test -Dbuild.env=circleci
working_directory: ~/example

- store_artifacts:
path: /tmp/artifacts
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vendor/
.idea
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 @@ -58,7 +56,6 @@ function the_build_utility_install() {
\Drupal::service('module_installer')->install($install);

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

// Begin Comment module.
// Remove the comment fields.
$fields = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['type' => 'comment']);
Expand All @@ -69,7 +66,6 @@ function the_build_utility_install() {
// Remove state setting.
\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'];
\Drupal::service('module_installer')->uninstall($uninstall);
Expand Down
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>
50 changes: 18 additions & 32 deletions src/TheBuild/Acquia/AcquiaTask.php
Original file line number Diff line number Diff line change
@@ -1,57 +1,40 @@
<?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;

/**
*
*/
abstract class AcquiaTask extends \Task {

/**
* Required. The Acquia Cloud credentials file containing 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.
*
* @var string
*/
protected $mail;

/**
* 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.
*
* @var string
*/
protected $endpoint = 'https://cloudapi.acquia.com/v1';
Expand All @@ -65,11 +48,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 +63,23 @@ 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
*
* @return \HTTP_Request2
*/
protected function createRequest($path) {
$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 @@ -106,7 +90,9 @@ protected function createRequest($path) {
* Example of how to query the Acquia Cloud API.
*
* @param $path
*
* @return string
*
* @throws \HTTP_Request2_Exception
*/
protected function getApiResponseBody($path) {
Expand All @@ -118,12 +104,12 @@ protected function getApiResponseBody($path) {
}

/**
* @param PhingFile $file
* @param \PhingFile $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