diff --git a/defaults/standard/modules/the_build_utility/the_build_utility.install b/defaults/standard/modules/the_build_utility/the_build_utility.install
index 509ddf61..913472f4 100644
--- a/defaults/standard/modules/the_build_utility/the_build_utility.install
+++ b/defaults/standard/modules/the_build_utility/the_build_utility.install
@@ -5,6 +5,8 @@
* Install, update and uninstall functions for the-build utility module.
*/
+use Drupal\user\Entity\User;
+use Drupal\user\RoleInterface;
use Drupal\shortcut\Entity\Shortcut;
/**
@@ -52,34 +54,23 @@ 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 comment fields so that comment module can be uninstalled.
+ // 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']);
foreach ($fields as $field) {
$field->delete();
}
- // Remove state variable from comment module.
+ // 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',
- ];
+ $uninstall = ['automated_cron', 'big_pipe', 'comment', 'contact', 'history', 'search', 'tour'];
\Drupal::service('module_installer')->uninstall($uninstall);
}
diff --git a/phpcs.xml b/phpcs.xml
deleted file mode 100644
index 43ed5eea..00000000
--- a/phpcs.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-
-
-
-
-
- PHP_CodeSniffer configuration.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- src
- defaults/standard/modules/the_build_utility
-
-
diff --git a/src/TheBuild/Acquia/AcquiaTask.php b/src/TheBuild/Acquia/AcquiaTask.php
index dc53c1c0..9a86a2d4 100644
--- a/src/TheBuild/Acquia/AcquiaTask.php
+++ b/src/TheBuild/Acquia/AcquiaTask.php
@@ -1,43 +1,57 @@
+ * @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;
-/**
- * Phing task for making queries against the Acquia Cloud v1 API.
- */
+use BuildException;
+use HTTP_Request2;
+use PhingFile;
+
abstract class AcquiaTask extends \Task {
/**
- * 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.
- *
+ * 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.
- *
+ * 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 v1 endpoint.
- *
+ * The Acquia Cloud API endpoint. This code is specific to version 1 of the
+ * API.
* @var string
*/
protected $endpoint = 'https://cloudapi.acquia.com/v1';
@@ -53,11 +67,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);
@@ -68,25 +82,22 @@ 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 string $path
- * Acquia Cloud API path.
- *
- * @return \HTTP_Request2
- * Request object.
+ * @param $path
+ * @return HTTP_Request2
*/
- protected function createRequest(string $path) : \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);
@@ -96,13 +107,11 @@ protected function createRequest(string $path) : \HTTP_Request2 {
/**
* Example of how to query the Acquia Cloud API.
*
- * @param string $path
- * Acquia Cloud API path.
- *
+ * @param $path
* @return string
- * API response.
+ * @throws \HTTP_Request2_Exception
*/
- protected function getApiResponseBody(string $path) : string {
+ protected function getApiResponseBody($path) {
$request = $this->createRequest($path);
$this->log('GET ' . $request->getUrl());
@@ -111,16 +120,12 @@ protected function getApiResponseBody(string $path) : string {
}
/**
- * Set the Acquia credentials file.
- *
- * @param \PhingFile $file
- * Acquia credentials 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);
}
}
diff --git a/src/TheBuild/Acquia/GetLatestBackupTask.php b/src/TheBuild/Acquia/GetLatestBackupTask.php
index 3f11cf13..451bb1aa 100644
--- a/src/TheBuild/Acquia/GetLatestBackupTask.php
+++ b/src/TheBuild/Acquia/GetLatestBackupTask.php
@@ -1,64 +1,80 @@
+ *
+ *
+ *
+ * @endcode
+ *
+ * @copyright 2018 Palantir.net, Inc.
+ */
namespace TheBuild\Acquia;
-/**
- * Fetch a recent backup from Acquia.
- */
+use BuildException;
+use PhingFile;
+
+
class GetLatestBackupTask extends AcquiaTask {
/**
- * Required. Directory for storing downloaded database backups.
+ * Directory for storing downloaded database backups.
*
- * @var \PhingFile
+ * Required parameter.
+ * @var PhingFile
*/
protected $dir;
/**
- * Required. The Acquia Cloud hosting realm where the site is running.
- *
- * This also appears in a site's server names, as
- * 'sitename.REALM.hosting.acquia.com'.
+ * The Acquia Cloud hosting realm where the site is running.
* - Acquia Cloud Enterprise: 'prod'
* - Acquia Cloud Professional: 'devcloud'
*
+ * This also appears in a site's server names, as 'sitename.REALM.hosting.acquia.com'.
+ *
+ * Required parameter.
* @var string
*/
protected $realm;
/**
- * Required. The Acquia Cloud site account name.
+ * The Acquia Cloud site account name.
*
+ * Required parameter.
* @var string
*/
protected $site;
/**
- * Required. The Acquia Cloud environment.
- *
- * Generally 'dev', 'test', or 'prod', unless a site has RA or other
- * additional environments.
+ * The Acquia Cloud environment. Generally 'dev', 'test', or 'prod', unless
+ * a site has RA or other additional environments.
*
+ * Required parameter.
* @var string
*/
protected $env;
/**
- * Optional. The name of the database whose backup to download.
- *
- * This will correspond with the site name unless your site uses multiple
- * databases or you are running Drupal multisites.
+ * The name of the database whose backup to download. This will correspond
+ * with the site name unless your site uses multiple databases or you are
+ * running Drupal multisites.
*
+ * Optional parameter; defaults to matching $site.
* @var string
*/
protected $database;
/**
- * Optional. Maximum age of the database backup in hours.
- *
- * If there is no backup matching this age in the current backups.json, the
- * backups.json will be refreshed and the newest backup will be downloaded.
+ * Maximum age of the database backup in hours. If there is no backup matching
+ * this age in the current backups.json, the backups.json will be refreshed
+ * and the newest backup will be downloaded.
*
+ * Optional parameter.
* @var int
*/
protected $maxAge = 24;
@@ -67,24 +83,18 @@ class GetLatestBackupTask extends AcquiaTask {
* Name of a property to populate with the path to the latest database backup.
*
* Optional parameter.
- *
* @var string
*/
protected $propertyName;
/**
- * Where to store the JSON list of database backups.
- *
- * This info is downloaded from the Acquia Cloud API. The file is set to
- * 'backups.json' in the directory specified by $dir.
- *
- * @var \PhingFile
+ * Where to store the JSON list of database backups downloaded from the Acquia
+ * Cloud API. This is set to 'backups.json' in the directory specified by $dir.
+ * @var PhingFile
*/
protected $backupsFile;
/**
- * {@inheritdoc}
- *
* @throws \IOException
* @throws \NullPointerException
*/
@@ -92,8 +102,8 @@ public function main() {
$this->validate();
// Store the Acquia Cloud API JSON database backup records in our backups
- // directory..
- $this->backupsFile = new \PhingFile($this->dir, "backups-{$this->site}-{$this->database}-{$this->env}.json");
+ // directory.
+ $this->backupsFile = new PhingFile($this->dir, "backups-{$this->site}-{$this->database}-{$this->env}.json");
// Check the database backup records for entries within our time window.
$backups = $this->getCurrentBackupRecords();
@@ -102,7 +112,7 @@ public function main() {
$downloaded_backups = [];
foreach ($backups as $backup) {
$filename = basename($backup['path']);
- $file = new \PhingFile($this->dir, $filename);
+ $file = new PhingFile($this->dir, $filename);
if ($file->exists()) {
$downloaded_backups[] = $backup;
@@ -131,15 +141,15 @@ public function main() {
$this->log("Using backup from " . $this->formatBackupTime($newest_backup) . " ({$newest_backup['id']})");
}
- // This means that we didn't have a current record in our backups json, and
- // the Acquia Cloud API returned empty or malformed JSON.
+ // This means that we didn't have a current record in our backups json, and the Acquia Cloud API returned empty or
+ // malformed JSON.
if (empty($newest_backup)) {
- throw new \BuildException('Failed to find a backup record.');
+ throw new BuildException('Failed to find a backup record.');
}
// Download the backup if it does not yet exist on the filesystem.
$filename = basename($newest_backup['path']);
- $file = new \PhingFile($this->dir, $filename);
+ $file = new PhingFile($this->dir, $filename);
if (!$file->exists()) {
$this->log("Downloading the backup to " . $file->getAbsolutePath());
$this->downloadBackup($newest_backup, $file);
@@ -159,14 +169,14 @@ public function main() {
* Download a backup from Acquia Cloud.
*
* @param array $backup
- * Acquia backup info array.
- * @param \PhingFile $destination
- * Destination file for the downloaded backup.
+ * @param PhingFile $destination
+ * @throws \HTTP_Request2_Exception
+ * @throws \HTTP_Request2_LogicException
*/
- protected function downloadBackup(array $backup, \PhingFile $destination) {
+ protected function downloadBackup(array $backup, PhingFile $destination) {
$stream = fopen($destination->getAbsolutePath(), 'wb');
if (!$stream) {
- throw new \BuildException('Can not write to ' . $destination->getAbsolutePath());
+ throw new BuildException('Can not write to ' . $destination->getAbsolutePath());
}
// Use an HTTP_Request2 with the Observer pattern in order to download large
@@ -182,20 +192,18 @@ protected function downloadBackup(array $backup, \PhingFile $destination) {
$response = $request->send();
fclose($stream);
- $this->log("Downloaded " . intval($response->getHeader('content-length')) / 1000000 . "MB to " . $destination->getAbsolutePath());
+ $this->log("Downloaded " . $response->getHeader('content-length')/1000000 . "MB to " . $destination->getAbsolutePath());
}
/**
* Get backup records that are within the desired time window.
- *
* @return array
- * Array of available backups within the specified timeframe.
*/
protected function getCurrentBackupRecords() {
try {
$backups = $this->getBackupRecords($this->backupsFile);
}
- catch (\BuildException $e) {
+ catch (BuildException $e) {
$backups = [];
}
@@ -215,21 +223,14 @@ protected function getCurrentBackupRecords() {
}
/**
- * Get the array of backup records from the Acquia Cloud API JSON output.
- *
- * Sorts records from oldest to newest.
- *
- * @param \PhingFile $file
- * Temp file containing the Acquia Cloud API response.
+ * Get the array of backup records from the Acquia Cloud API JSON output,
+ * sorted from oldest to newest.
*
+ * @param $file
* @return array
- * Acquia backup info array.
- *
- * @throws \BuildException
- *
- * @SuppressWarnings(PHPMD.ShortVariable)
+ * @throws BuildException
*/
- protected function getBackupRecords(\PhingFile $file) {
+ protected function getBackupRecords($file) {
if ($file->exists()) {
$backups = json_decode($file->contents(), TRUE);
@@ -238,10 +239,8 @@ protected function getBackupRecords(\PhingFile $file) {
if (isset($backups[0]['started'])) {
// Sort the backups by start time so that the newest is always last.
- usort($backups, function ($a, $b) {
- if ($a['started'] == $b['started']) {
- return 0;
- }
+ usort($backups, function($a, $b) {
+ if ($a['started'] == $b['started']) { return 0; }
return ($a['started'] < $b['started']) ? -1 : 1;
});
@@ -249,19 +248,16 @@ protected function getBackupRecords(\PhingFile $file) {
}
elseif (count($backups) === 0) {
// The site might not have been backed up yet.
- throw new \BuildException('No Acquia Cloud backups found: ' . $file->getCanonicalPath());
+ throw new BuildException('No Acquia Cloud backups found: ' . $file->getCanonicalPath());
}
}
- throw new \BuildException('Acquia Cloud backup records could not be loaded from JSON: ' . $file->getCanonicalPath());
+ throw new BuildException('Acquia Cloud backup records could not be loaded from JSON: ' . $file->getCanonicalPath());
}
/**
* Download the latest list of backup records from the Acquia Cloud API.
- *
- * @param \PhingFile $backups_file
- * The file where the downloaded backup should be stored.
*/
- protected function downloadBackupRecords(\PhingFile $backups_file) {
+ protected function downloadBackupRecords(PhingFile $backups_file) {
$json = $this->getApiResponseBody("/sites/{$this->realm}:{$this->site}/envs/{$this->env}/dbs/{$this->database}/backups.json");
$writer = new \FileWriter($backups_file);
@@ -271,85 +267,37 @@ protected function downloadBackupRecords(\PhingFile $backups_file) {
/**
* Format the backup time to display in log messages.
*
- * @param array $backup
- * Acquia backup info array.
- *
+ * @param $backup
* @return string
- * A human-readable date.
*/
- protected function formatBackupTime(array $backup) {
+ protected function formatBackupTime($backup) {
$time = new \DateTime('now');
$time->setTimestamp($backup['started']);
return $time->format(DATE_RFC850);
}
/**
- * Set the Acquia realm.
- *
- * @param string $value
- * Acquia realm.
+ * Setter functions.
*/
- public function setRealm(string $value) {
+ public function setRealm($value) {
$this->realm = $value;
}
-
- /**
- * Set the Acquia site name.
- *
- * @param string $value
- * Acquia site name.
- */
- public function setSite(string $value) {
+ public function setSite($value) {
$this->site = $value;
}
-
- /**
- * Set the Acquia environment name.
- *
- * @param string $value
- * Acquia environment name.
- */
- public function setEnv(string $value) {
+ public function setEnv($value) {
$this->env = $value;
}
-
- /**
- * Set the Acquia database name.
- *
- * @param string $value
- * Set the database name.
- */
- public function setDatabase(string $value) {
+ public function setDatabase($value) {
$this->database = $value;
}
-
- /**
- * Set the destination directory.
- *
- * @param string $value
- * Directory path.
- */
- public function setDir(string $value) {
- $this->dir = new \PhingFile($value);
+ public function setDir($value) {
+ $this->dir = new PhingFile($value);
}
-
- /**
- * Set the max age.
- *
- * @param int|string $value
- * Max age in hours.
- */
- public function setMaxAge(int|string $value) {
+ public function setMaxAge($value) {
$this->maxAge = (int) $value;
}
-
- /**
- * Set the property name.
- *
- * @param string $value
- * Property name to use for the result.
- */
- public function setPropertyName(string $value) {
+ public function setPropertyName($value) {
$this->propertyName = $value;
}
@@ -364,7 +312,7 @@ protected function validate() {
// Check the build attributes.
foreach (['dir', 'realm', 'site', 'env'] as $attribute) {
if (empty($this->$attribute)) {
- throw new \BuildException("$attribute attribute is required.", $this->location);
+ throw new BuildException("$attribute attribute is required.", $this->location);
}
}
}
diff --git a/src/TheBuild/CopyPropertiesTask.php b/src/TheBuild/CopyPropertiesTask.php
index c65aa17a..5d8c2379 100644
--- a/src/TheBuild/CopyPropertiesTask.php
+++ b/src/TheBuild/CopyPropertiesTask.php
@@ -1,40 +1,48 @@
+ * @endcode
+ *
+ * @copyright 2018 Palantir.net, Inc.
+ */
namespace TheBuild;
-/**
- * Copy properties matching a prefix to properties with a different prefix.
- */
+use BuildException;
+use StringHelper;
+
+
class CopyPropertiesTask extends \Task {
/**
- * Prefix for properties to copy.
- *
* @var string
+ * Prefix for properties to copy.
*/
protected $fromPrefix = '';
/**
- * Prefix for properties to create/update.
- *
* @var string
+ * Prefix for properties to create/update.
*/
protected $toPrefix = '';
-
+
/**
- * Whether to overwrite the existing properties.
- *
* @var bool
+ * Whether to overwrite the existing properties.
*/
- protected $override = TRUE;
+ protected $override = true;
/**
- * Internal method to use for creating/updating properties.
- *
* @var string
*/
protected $propertyMethod = 'setProperty';
+
/**
* Copy properties.
*/
@@ -54,27 +62,26 @@ public function main() {
}
}
+
/**
* Verify that the required attributes are set.
*/
public function validate() {
if (empty($this->fromPrefix)) {
- throw new \BuildException("fromPrefix attribute is required.", $this->location);
+ throw new BuildException("fromPrefix attribute is required.", $this->location);
}
if (empty($this->toPrefix)) {
- throw new \BuildException("toPrefix attribute is required.", $this->location);
+ throw new BuildException("toPrefix attribute is required.", $this->location);
}
}
+
/**
- * Set the source property prefix.
- *
* @param string $prefix
- * Prefix to copy properties from.
*/
public function setFromPrefix($prefix) {
- if (!\StringHelper::endsWith(".", $prefix)) {
+ if (!StringHelper::endsWith(".", $prefix)) {
$prefix .= ".";
}
@@ -82,13 +89,10 @@ public function setFromPrefix($prefix) {
}
/**
- * Set the destination property prefix.
- *
* @param string $prefix
- * Prefix to copy properties into.
*/
public function setToPrefix($prefix) {
- if (!\StringHelper::endsWith(".", $prefix)) {
+ if (!StringHelper::endsWith(".", $prefix)) {
$prefix .= ".";
}
@@ -96,10 +100,7 @@ public function setToPrefix($prefix) {
}
/**
- * Set override.
- *
* @param bool $override
- * Whether to override existing values.
*/
public function setOverride($override) {
$this->override = $override;
diff --git a/src/TheBuild/ForeachKeyTask.php b/src/TheBuild/ForeachKeyTask.php
index 3c148dc0..c14bd98e 100644
--- a/src/TheBuild/ForeachKeyTask.php
+++ b/src/TheBuild/ForeachKeyTask.php
@@ -1,56 +1,60 @@
+ * @endcode
+ *
+ * @copyright 2018 Palantir.net, Inc.
+ */
namespace TheBuild;
-/**
- * Phing task to run a target for each property in an array.
- */
+use BuildException;
+use StringHelper;
+
+
class ForeachKeyTask extends \Task {
/**
- * Prefix of properties to iterate over.
- *
* @var string
+ * Prefix of properties to iterate over.
*/
protected $prefix = '';
/**
- * Name of target to execute.
- *
* @var string
+ * Name of target to execute.
*/
protected $target = '';
/**
- * Name of parameter to use for the key.
- *
* @var string
+ * Name of parameter to use for the key.
*/
protected $keyParam = '';
/**
- * Name of parameter to use for the prefix.
- *
* @var string
+ * Name of parameter to use for the prefix.
*/
protected $prefixParam = '';
/**
- * Keys to ignore.
- *
* @var array
*/
protected $omitKeys = [];
/**
- * Instance of PhingCallTask to use/run.
- *
* @var \PhingCallTask
*/
protected $callee;
/**
- * {@inheritdoc}
+ *
*/
public function init() {
parent::init();
@@ -69,8 +73,8 @@ public function main() {
$this->validate();
$this->callee->setTarget($this->target);
- $this->callee->setInheritAll(TRUE);
- $this->callee->setInheritRefs(TRUE);
+ $this->callee->setInheritAll(true);
+ $this->callee->setInheritRefs(true);
// Extract matching keys from the properties array.
$keys = [];
@@ -78,8 +82,7 @@ public function main() {
foreach (array_keys($project->getProperties()) as $name) {
if (strpos($name, $this->prefix) === 0) {
$property_children = substr($name, strlen($this->prefix));
- // phpcs:ignore
- [$key] = explode('.', $property_children, 2);
+ list($key, $property_grandchildren) = explode('.', $property_children, 2);
$keys[$key] = $key;
}
}
@@ -90,12 +93,12 @@ public function main() {
// Iterate over each extracted key.
foreach (array_keys($keys) as $key) {
$prop = $this->callee->createProperty();
- $prop->setOverride(TRUE);
+ $prop->setOverride(true);
$prop->setName($this->keyParam);
$prop->setValue($key);
$prop = $this->callee->createProperty();
- $prop->setOverride(TRUE);
+ $prop->setOverride(true);
$prop->setName($this->prefixParam);
$prop->setValue($this->prefix);
@@ -103,25 +106,24 @@ public function main() {
}
}
+
/**
* Verify that the required attributes are set.
*/
public function validate() {
foreach (['prefix', 'target', 'keyParam', 'prefixParam'] as $attribute) {
if (empty($this->$attribute)) {
- throw new \BuildException("$attribute attribute is required.", $this->location);
+ throw new BuildException("$attribute attribute is required.", $this->location);
}
}
}
+
/**
- * Use only keys with a certain prefix.
- *
* @param string $value
- * The key prefix.
*/
public function setPrefix($value) {
- if (!\StringHelper::endsWith(".", $value)) {
+ if (!StringHelper::endsWith(".", $value)) {
$value .= ".";
}
@@ -129,40 +131,28 @@ public function setPrefix($value) {
}
/**
- * Set the target to run for each item.
- *
* @param string $value
- * Name of the target to run for each item.
*/
public function setTarget($value) {
$this->target = $value;
}
/**
- * Set the parameter name to pass to the target.
- *
* @param string $value
- * Name of the parameter to pass to the target.
*/
public function setKeyParam($value) {
$this->keyParam = $value;
}
/**
- * Name of the parameter where we can find the prefix.
- *
* @param string $value
- * The parameter name.
*/
public function setPrefixParam($value) {
$this->prefixParam = $value;
}
/**
- * Remove a list of keys from the set of properties.
- *
* @param string $value
- * A comma-separated list of keys to remove from the array.
*/
public function setOmitKeys($value) {
$this->omitKeys = array_map('trim', explode(',', $value));
diff --git a/src/TheBuild/IncludeResourceTask.php b/src/TheBuild/IncludeResourceTask.php
index aba4328c..1dab83ae 100644
--- a/src/TheBuild/IncludeResourceTask.php
+++ b/src/TheBuild/IncludeResourceTask.php
@@ -1,39 +1,43 @@
log("Replacing existing resource '" . $this->dest->getPath() . "'");
if ($this->dest->delete(TRUE) === FALSE) {
- throw new \BuildException("Failed to delete existing destination '$this->dest'");
+ throw new BuildException("Failed to delete existing destination '$this->dest'");
}
}
@@ -84,61 +89,60 @@ public function main() {
}
}
+
/**
* Verify that the required attributes are set.
*/
public function validate() {
if (!in_array($this->mode, ['symlink', 'copy'])) {
- throw new \BuildException("mode attribute must be either 'symlink' or 'copy'", $this->location);
+ throw new BuildException("mode attribute must be either 'symlink' or 'copy'", $this->location);
}
if (empty($this->source) || empty($this->dest)) {
- throw new \BuildException("Both the 'source' and 'dest' attributes are required.");
+ throw new BuildException("Both the 'source' and 'dest' attributes are required.");
}
}
+
/**
* Set the artifact mode.
*
- * @param string $mode
- * Use 'symlink' to link resources, and 'copy' to copy them.
+ * @param $mode
+ * Use 'symlink' to link resources, and 'copy' to copy them.
*/
- public function setMode(string $mode) {
+ public function setMode($mode) {
$this->mode = $mode;
}
+
/**
* Set the source of the resource to include.
*
* @param \PhingFile $source
- * Source file.
*/
- public function setSource(\PhingFile $source) {
+ public function setSource(PhingFile $source) {
if (!$source->exists()) {
- throw new \BuildException("resource '$source' is not available'");
+ throw new BuildException("resource '$source' is not available'");
}
$this->source = $source;
}
+
/**
* Set the destination for the resource.
- *
- * @param \PhingFile $dest
- * File destination.
+ * @param PhingFile $dest
*/
- public function setDest(\PhingFile $dest) {
+ public function setDest(PhingFile $dest) {
$this->dest = $dest;
}
/**
- * See SymlinkTask.
- *
- * @param bool $relative
- * Whether to make relative symlinks.
+ * @param boolean $relative
*/
- public function setRelative($relative) {
- $this->relative = $relative;
+ public function setRelative($relative)
+ {
+ $this->relative = $relative;
}
}
diff --git a/src/TheBuild/MenuInputRequest.php b/src/TheBuild/MenuInputRequest.php
index 325bc763..2bed0974 100644
--- a/src/TheBuild/MenuInputRequest.php
+++ b/src/TheBuild/MenuInputRequest.php
@@ -1,46 +1,37 @@
options = array_values($options);
}
- /**
- * Generate the menu prompt.
- */
public function getPrompt() {
$prompt = $this->prompt . $this->getPromptChar() . "\r\n";
foreach ($this->options as $i => $option) {
@@ -49,16 +40,10 @@ public function getPrompt() {
return $prompt;
}
- /**
- * Validate the menu selection.
- */
public function isInputValid() {
return (isset($this->options[$this->input]));
}
- /**
- * Return the menu selection.
- */
public function getInput() {
return $this->options[$this->input];
}
diff --git a/src/TheBuild/SelectOneTask.php b/src/TheBuild/SelectOneTask.php
index 2c298356..65bd731c 100644
--- a/src/TheBuild/SelectOneTask.php
+++ b/src/TheBuild/SelectOneTask.php
@@ -1,50 +1,67 @@
+ *
+ *
+ * @endcode
+ *
+ * @copyright 2018 Palantir.net, Inc.
+ */
namespace TheBuild;
-/**
- * Allow the user to select one option from a list.
- */
+use BuildException;
+use Project;
+
+
class SelectOneTask extends \Task {
/**
- * Required. List of values to select among.
- *
* @var string
+ * Required. List of values to select among.
*/
protected $list = '';
/**
- * String to split the list by.
- *
* @var string
+ * String to split the list by.
*/
protected $delimiter = ',';
/**
- * Required. Property to populate with the selected value.
- *
* @var string
+ * Required. Property to populate with the selected value.
*/
protected $propertyName = '';
-
+
/**
- * Message to display to the user when more than one key is available.
- *
* @var string
+ * Message to display to the user when more than one key is available.
*/
protected $message = 'Select one:';
+
/**
* Select menu.
*/
public function main() {
$this->validate();
-
+
$project = $this->getProject();
if ($existing_value = $this->project->getProperty($this->propertyName)) {
- $this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", \Project::MSG_INFO);
+ $this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", Project::MSG_INFO);
return;
}
@@ -63,7 +80,7 @@ public function main() {
}
elseif (count($keys) == 1) {
$value = current($keys);
- $this->log("Using {$this->propertyName} = '{$value}' (one value found)", \Project::MSG_INFO);
+ $this->log("Using {$this->propertyName} = '{$value}' (one value found)", Project::MSG_INFO);
}
if ($value) {
@@ -71,54 +88,43 @@ public function main() {
}
}
+
/**
* Verify that the required attributes are set.
*/
public function validate() {
foreach (['list', 'propertyName'] as $attribute) {
if (empty($this->$attribute)) {
- throw new \BuildException("$attribute attribute is required.", $this->location);
+ throw new BuildException("$attribute attribute is required.", $this->location);
}
}
}
/**
- * Set the list of options.
- *
* @param string $value
- * List of options.
*/
public function setList($value) {
$this->list = $value;
}
/**
- * Set the options delimiter.
- *
* @param string $value
- * A delimiter.
*/
- public function setDelimiter(string $value) {
+ public function setDelimiter($value) {
$this->delimiter = $value;
}
/**
- * Set the name of the result property.
- *
* @param string $value
- * Property name for the result.
*/
- public function setPropertyName(string $value) {
+ public function setPropertyName($value) {
$this->propertyName = $value;
}
/**
- * Set the message.
- *
* @param string $value
- * Message to present with the options.
*/
- public function setMessage(string $value) {
+ public function setMessage($value) {
$this->message = $value;
}
diff --git a/src/TheBuild/SelectPropertyKeyTask.php b/src/TheBuild/SelectPropertyKeyTask.php
index 86ae06bf..6a4ed2be 100644
--- a/src/TheBuild/SelectPropertyKeyTask.php
+++ b/src/TheBuild/SelectPropertyKeyTask.php
@@ -1,40 +1,56 @@
+ * @endcode
+ *
+ * @copyright 2018 Palantir.net, Inc.
+ */
namespace TheBuild;
-/**
- * Interactively select an option from an array of property keys.
- */
+use BuildException;
+use StringHelper;
+use Project;
+
+
class SelectPropertyKeyTask extends \Task {
/**
- * Required. Prefix for properties to copy.
- *
* @var string
+ * Required. Prefix for properties to copy.
*/
protected $prefix = '';
/**
- * Required. Property to populate with the selected value.
- *
* @var string
+ * Required. Property to populate with the selected value.
*/
protected $propertyName = '';
-
+
/**
- * Message to display to the user when more than one key is available.
- *
* @var string
+ * Message to display to the user when more than one key is available.
*/
protected $message = 'Select one:';
/**
- * Keys to ignore.
- *
* @var array
*/
protected $omitKeys = [];
+
/**
* Copy properties.
*/
@@ -43,7 +59,7 @@ public function main() {
$project = $this->getProject();
if ($existing_value = $this->project->getProperty($this->propertyName)) {
- $this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", \Project::MSG_INFO);
+ $this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", Project::MSG_INFO);
return;
}
@@ -52,8 +68,7 @@ public function main() {
foreach ($project->getProperties() as $name => $value) {
if (strpos($name, $this->prefix) === 0) {
$property_children = substr($name, strlen($this->prefix));
- // phpcs:ignore
- [$key] = explode('.', $property_children, 2);
+ list($key, $property_grandchildren) = explode('.', $property_children, 2);
$keys[$key] = $key;
}
}
@@ -74,10 +89,10 @@ public function main() {
}
elseif (count($keys) == 1) {
$value = current($keys);
- $this->log("Using {$this->propertyName} = '{$value}' (one value found)", \Project::MSG_INFO);
+ $this->log("Using {$this->propertyName} = '{$value}' (one value found)", Project::MSG_INFO);
}
else {
- $this->log("No properties found with prefix '{$this->prefix}'", \Project::MSG_WARN);
+ $this->log("No properties found with prefix '{$this->prefix}'", Project::MSG_WARN);
}
if ($value) {
@@ -85,25 +100,24 @@ public function main() {
}
}
+
/**
* Verify that the required attributes are set.
*/
public function validate() {
foreach (['prefix', 'propertyName'] as $attribute) {
if (empty($this->$attribute)) {
- throw new \BuildException("$attribute attribute is required.", $this->location);
+ throw new BuildException("$attribute attribute is required.", $this->location);
}
}
}
+
/**
- * Set the prefix for which options will be shown.
- *
* @param string $value
- * Keys with this prefix will be provided as options.
*/
public function setPrefix($value) {
- if (!\StringHelper::endsWith(".", $value)) {
+ if (!StringHelper::endsWith(".", $value)) {
$value .= ".";
}
@@ -111,30 +125,21 @@ public function setPrefix($value) {
}
/**
- * Set the destination property.
- *
* @param string $value
- * Property name for the selection result.
*/
public function setPropertyName($value) {
$this->propertyName = $value;
}
/**
- * Set the message.
- *
* @param string $value
- * Message to display with the options.
*/
public function setMessage($value) {
$this->message = $value;
}
/**
- * Exclude some of the property keys from the options.
- *
* @param string $value
- * A comma-separated list of keys to exclude.
*/
public function setOmitKeys($value) {
$this->omitKeys = array_map('trim', explode(',', $value));