Skip to content

Commit

Permalink
ACMS-3507: Fix PHPCS issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalkhode1 committed Jan 25, 2024
1 parent 076c365 commit 339b291
Show file tree
Hide file tree
Showing 18 changed files with 171 additions and 184 deletions.
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<exclude-pattern>var/</exclude-pattern>
<exclude-pattern>vendor/</exclude-pattern>

<rule ref="AcquiaDrupalStrict"/>
<rule ref="AcquiaPHP"/>

</ruleset>
1 change: 0 additions & 1 deletion settings/site/default.local.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

use Acquia\Drupal\RecommendedSettings\Helpers\EnvironmentDetector;
use Drupal\Component\Assertion\Handle;

$db_name = '${drupal.db.database}';

Expand Down
37 changes: 20 additions & 17 deletions src/Common/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

namespace Acquia\Drupal\RecommendedSettings\Common;

use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException;
use Acquia\Drupal\RecommendedSettings\Robo\Config\ConfigAwareTrait;
use GuzzleHttp\Client;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Robo\Collection\CollectionBuilder;
use Robo\Common\ProcessExecutor;
use Robo\Contract\ConfigAwareInterface;
use Robo\Contract\IOAwareInterface;
use Robo\Robo;
use Robo\Task\Base\Exec;
use Robo\Tasks;
use Symfony\Component\Process\Process;

/**
Expand All @@ -26,13 +29,13 @@ class Executor implements ConfigAwareInterface, LoggerAwareInterface {
/**
* A copy of the Robo builder.
*
* @var \Acquia\Blt\Robo\BltTasks*/
protected $builder;
*/
protected \Robo\Tasks $builder;

/**
* Executor constructor.
*
* @param \Robo\Collection\CollectionBuilder $builder
* @param \Robo\Tasks $builder
* This is a copy of the collection builder, required for calling various
* Robo tasks from non-command files.
*/
Expand All @@ -43,10 +46,10 @@ public function __construct(CollectionBuilder $builder) {
/**
* Returns $this->builder.
*
* @return \Acquia\Blt\Robo\BltTasks
* @return \Robo\Tasks
* The builder.
*/
public function getBuilder() {
public function getBuilder(): Tasks {
return $this->builder;
}

Expand All @@ -60,7 +63,7 @@ public function getBuilder() {
* @return \Robo\Task\Base\Exec
* The task. You must call run() on this to execute it!
*/
public function taskExec($command) {
public function taskExec(string $command): Exec {
return $this->builder->taskExec($command);
}

Expand All @@ -73,7 +76,7 @@ public function taskExec($command) {
* @return \Robo\Common\ProcessExecutor
* The unexecuted process.
*/
public function drush($command) {
public function drush(mixed $command): ProcessExecutor {
$drush_array = [];
// @todo Set to silent if verbosity is less than very verbose.
$drush_array[] = $this->getConfigValue('composer.bin') . DIRECTORY_SEPARATOR . "drush";
Expand Down Expand Up @@ -108,7 +111,7 @@ public function drush($command) {
* @return \Robo\Common\ProcessExecutor
* The unexecuted command.
*/
public function execute($command) {
public function execute(mixed $command): ProcessExecutor {
// Backwards compatibility check for legacy commands.
if (!is_array($command)) {
$this->say($command);
Expand All @@ -132,7 +135,7 @@ public function execute($command) {
* @return \Robo\Common\ProcessExecutor
* The unexecuted command.
*/
public function executeShell($command) {
public function executeShell(string $command): ProcessExecutor {
$process_executor = Robo::process(Process::fromShellCommandline($command));
return $process_executor->dir($this->getConfigValue('repo.root'))
->printOutput(FALSE)
Expand All @@ -146,7 +149,7 @@ public function executeShell($command) {
* @param string $port
* The port number.
*/
public function killProcessByPort($port) {
public function killProcessByPort(string $port): void {
$this->logger->info("Killing all processes on port '$port'...");
// This is allowed to fail.
// @todo Replace with standardized call to Symfony Process.
Expand All @@ -162,7 +165,7 @@ public function killProcessByPort($port) {
* @param string $name
* The name of the process.
*/
public function killProcessByName($name) {
public function killProcessByName(string $name): void {
$this->logger->info("Killing all processing containing string '$name'...");
// This is allowed to fail.
// @todo Replace with standardized call to Symfony Process.
Expand All @@ -179,7 +182,7 @@ public function killProcessByName($name) {
* @param string $url
* The URL to wait for.
*/
public function waitForUrlAvailable($url) {
public function waitForUrlAvailable(string $url): void {
$this->wait([$this, 'checkUrl'], [$url], "Waiting for non-50x response from $url...");
}

Expand All @@ -190,7 +193,7 @@ public function waitForUrlAvailable($url) {
*
* @param callable $callable
* The method/function to wait for a TRUE response from.
* @param array $args
* @param string[] $args
* Arguments to pass to $callable.
* @param string $message
* The message to display when this function is called.
Expand All @@ -200,7 +203,7 @@ public function waitForUrlAvailable($url) {
*
* @throws \Exception
*/
public function wait(callable $callable, array $args, $message = '') {
public function wait(callable $callable, array $args, string $message = ''): bool {
$maxWait = 60 * 1000;
$checkEvery = 1 * 1000;
$start = microtime(TRUE) * 1000;
Expand All @@ -225,7 +228,7 @@ public function wait(callable $callable, array $args, $message = '') {
usleep($checkEvery * 1000);
}

throw new BltException("Timed out.");
throw new SettingsException("Timed out.");
}

/**
Expand All @@ -237,7 +240,7 @@ public function wait(callable $callable, array $args, $message = '') {
* @return bool
* TRUE if URL responded with a non-50x response.
*/
public function checkUrl($url) {
public function checkUrl(string $url): bool {
try {
$client = new Client();
$res = $client->request('GET', $url, [
Expand Down
22 changes: 11 additions & 11 deletions src/Common/IO.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait IO {
* @param string $text
* The text to write.
*/
protected function say($text) {
protected function say(string $text): void {
$this->writeln($text);
}

Expand All @@ -32,7 +32,7 @@ protected function say($text) {
* @param string $color
* The color of the text.
*/
protected function yell($text, $length = 40, $color = 'green') {
protected function yell(string $text, int $length = 40, string $color = 'green'): void {
$format = "<fg=white;bg=$color;options=bold>%s</fg=white;bg=$color;options=bold>";
$this->formattedOutput($text, $length, $format);
}
Expand All @@ -46,7 +46,7 @@ protected function yell($text, $length = 40, $color = 'green') {
* @return string
* The formatted question text.
*/
protected function formatQuestion($message) {
protected function formatQuestion(string $message): string {
return "<question> $message</question> ";
}

Expand All @@ -55,15 +55,15 @@ protected function formatQuestion($message) {
*
* @param string $question
* The question text.
* @param array $options
* @param string[] $options
* An array of available options.
* @param mixed $default
* Default.
*
* @return string
* The chosen option.
*/
protected function askChoice($question, array $options, $default = NULL) {
protected function askChoice(string $question, array $options, mixed $default = NULL): string {
return $this->doAsk(new ChoiceQuestion($this->formatQuestion($question),
$options, $default));
}
Expand All @@ -77,7 +77,7 @@ protected function askChoice($question, array $options, $default = NULL) {
* @return string
* The response.
*/
protected function askRequired($message) {
protected function askRequired(string $message): string {
$question = new Question($this->formatQuestion($message));
$question->setValidator(function ($answer) {
if (empty($answer)) {
Expand All @@ -94,15 +94,15 @@ protected function askRequired($message) {
/**
* Writes an array to the screen as a formatted table.
*
* @param array $array
* @param string[] $array
* The unformatted array.
* @param array $headers
* @param string[] $headers
* The headers for the array. Defaults to ['Property','Value'].
*/
protected function printArrayAsTable(
array $array,
array $headers = ['Property', 'Value']
) {
): void {
$table = new Table($this->output);
$table->setHeaders($headers)
->setRows(ArrayManipulator::convertArrayToFlatTextArray($array))
Expand All @@ -112,14 +112,14 @@ protected function printArrayAsTable(
/**
* Writes a particular configuration key's value to the log.
*
* @param array $array
* @param string[] $array
* The configuration.
* @param string $prefix
* A prefix to add to each row in the configuration.
* @param int $verbosity
* The verbosity level at which to display the logged message.
*/
protected function logConfig(array $array, $prefix = '', $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE) {
protected function logConfig(array $array, string $prefix = '', int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): void {
if ($this->output()->getVerbosity() >= $verbosity) {
if ($prefix) {
$this->output()->writeln("<comment>Configuration for $prefix:</comment>");
Expand Down
18 changes: 9 additions & 9 deletions src/Common/StringManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class StringManipulator {
* @return string
* The trimmed text.
*/
public static function trimEndingLines($text, $num_lines) {
public static function trimEndingLines(string $text, int $num_lines): string {
return implode("\n",
array_slice(explode("\n", $text), 0, count($text) - $num_lines));
}
Expand All @@ -34,7 +34,7 @@ public static function trimEndingLines($text, $num_lines) {
* @return string
* The trimmed text.
*/
public static function trimStartingLines($text, $num_lines) {
public static function trimStartingLines(string $text, int $num_lines): string {
return implode("\n", array_slice(explode("\n", $text), $num_lines));
}

Expand All @@ -43,19 +43,19 @@ public static function trimStartingLines($text, $num_lines) {
*
* @param string $identifier
* Identifier.
* @param array $filter
* @param string[] $filter
* Filter.
*
* @return mixed
* Safe string.
*/
public static function convertStringToMachineSafe($identifier, array $filter = [
public static function convertStringToMachineSafe(string $identifier, array $filter = [
' ' => '_',
'-' => '_',
'/' => '_',
'[' => '_',
']' => '',
]) {
]): mixed {
$identifier = str_replace(array_keys($filter), array_values($filter), $identifier);
// Valid characters are:
// - a-z (U+0030 - U+0039)
Expand Down Expand Up @@ -86,7 +86,7 @@ public static function convertStringToMachineSafe($identifier, array $filter = [
* @return mixed
* Prefix.
*/
public static function convertStringToPrefix($string) {
public static function convertStringToPrefix(string $string): mixed {
$words = explode(' ', $string);
$prefix = '';
foreach ($words as $word) {
Expand All @@ -101,10 +101,10 @@ public static function convertStringToPrefix($string) {
* @param string $command
* The command string to conver to array.
*
* @return array
* @return string[]
* Command array.
*/
public static function commandConvert($command) {
public static function commandConvert(string $command): array {
return explode(" ", $command);
}

Expand All @@ -114,7 +114,7 @@ public static function commandConvert($command) {
* @return string
* The deprecation warning.
*/
public static function stringToArrayMsg() {
public static function stringToArrayMsg(): string {
return "Deprecation Warning: this command is passing a command string and should pass a command array.";
}

Expand Down
2 changes: 0 additions & 2 deletions src/Config/DefaultConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace Acquia\Drupal\RecommendedSettings\Config;

use Consolidation\Config\Config;
use Grasmash\YamlExpander\YamlExpander;
use Psr\Log\NullLogger;

/**
* The configuration for settings.
Expand Down
4 changes: 1 addition & 3 deletions src/Config/DefaultDrushConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Consolidation\Config\Config;
use Drush\Config\DrushConfig;
use Grasmash\YamlExpander\YamlExpander;
use Psr\Log\NullLogger;

/**
* The configuration for settings.
Expand All @@ -24,7 +22,7 @@ public function __construct(DrushConfig $config) {
$config->set('docroot', $config->get("options.root"));
$config->set('composer.bin', $config->get("drush.vendor-dir") . '/bin');
$config->set('drush.uri', $config->get("options.uri"));
$config->set('site', $config->get("options.uri"));
$config->set('site', $config->get("options.uri"));
if ($config->get("options.ansi")) {
$config->set('drush.ansi', $config->get("options.ansi"));
}
Expand Down
Loading

0 comments on commit 339b291

Please sign in to comment.