Skip to content
Snippets Groups Projects
Commit c7a0f104 authored by Jürgen Haas's avatar Jürgen Haas
Browse files

Issue #3396848 by danielspeicher, jurgenhaas: Coding Standards for PHP Stan Level 6 and PHP CS

parent 29225890
No related branches found
No related tags found
No related merge requests found
Pipeline #42255 passed
{
"name": "drupal/drd_agent",
"type": "drupal-module",
"description": "TODO",
"description": "Agent on remote Drupal sites for the main DRD module.",
"keywords": [
"Drupal"
],
"license": "GPL-2.0+",
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/drd_agent",
"authors": [
{
......@@ -27,7 +27,9 @@
"php": ">=8.1"
},
"require-dev": {
"drupal/security_review": "^2.0",
"drupal/hacked": "^2.0@beta"
"drupal/hacked": "^2.0@beta",
"drupal/job_scheduler": "^4.0",
"drupal/monitoring": "^1.13",
"drupal/security_review": "^2.0"
}
}
form.drd-agent-auth .domain {
padding: 2em 0;
text-align: center;
font-weight: bold;
font-size: 2em;
font-weight: bold;
}
......@@ -48,10 +48,13 @@ class DomainsReceive extends Base {
try {
include DRUPAL_ROOT . '/sites/sites.php';
}
catch (\Exception $e) {
catch (\Exception) {
// Ignore.
}
}
// The $sites variable could be non-empty, if the included file above
// defined an array with site values.
// @phpstan-ignore-next-line
if (empty($sites)) {
foreach (scandir(DRUPAL_ROOT . '/sites') as $shortname) {
if (is_dir(DRUPAL_ROOT . '/sites/' . $shortname) &&
......@@ -126,6 +129,9 @@ class DomainsReceive extends Base {
], RfcLogLevel::ERROR);
return ['', ''];
}
// The $base_url variable could be non-empty, if the file content above
// defined the base url.
// @phpstan-ignore-next-line
if (empty($base_url)) {
if ($shortname === 'default') {
$base_url = $GLOBALS['base_url'];
......
......@@ -3,7 +3,7 @@
namespace Drupal\drd_agent\Agent\Action;
use Drupal\Core\Extension\Extension;
use Drupal\hacked\hackedProject;
use Drupal\hacked\HackedProject;
/**
* Provides a 'Projects' code.
......
......@@ -2,11 +2,40 @@
namespace Drupal\drd_agent\Agent\Action;
use Drupal\Core\Update\UpdateHookRegistry;
use Drupal\Core\Update\UpdateRegistry;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a 'Update' code.
*/
class Update extends Base {
/**
* The update hook registry.
*
* @var \Drupal\Core\Update\UpdateHookRegistry
*/
protected UpdateHookRegistry $updateHookRegistry;
/**
* The update registry.
*
* @var \Drupal\Core\Update\UpdateRegistry
*/
protected UpdateRegistry $postUpdateRegistry;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): Update {
/** @var \Drupal\drd_agent\Agent\Action\Update $instance */
$instance = parent::create($container);
$instance->updateHookRegistry = $container->get('update.update_hook_registry');
$instance->postUpdateRegistry = $container->get('update.post_update_registry');
return $instance;
}
/**
* {@inheritdoc}
*/
......@@ -19,7 +48,7 @@ class Update extends Base {
$pending = update_get_update_list();
// Pending hook_post_update_X() implementations.
$post_updates = $this->container->get('update.post_update_registry')->getPendingUpdateInformation();
$post_updates = $this->postUpdateRegistry->getPendingUpdateInformation();
$result = [];
$start = [];
......@@ -61,7 +90,7 @@ class Update extends Base {
// correct place. (The updates are already sorted, so we can simply base
// this on the first one we come across in the above foreach loop.)
if (isset($start[$update['module']])) {
drupal_set_installed_schema_version($update['module'], $update['number'] - 1);
$this->updateHookRegistry->setInstalledVersion($update['module'], $update['number'] - 1);
unset($start[$update['module']]);
}
// Add this update function to the batch.
......@@ -79,7 +108,7 @@ class Update extends Base {
}
// Apply post update hooks.
$post_updates = $this->container->get('update.post_update_registry')->getPendingUpdateFunctions();
$post_updates = $this->postUpdateRegistry->getPendingUpdateFunctions();
if ($post_updates) {
$operations[] = ['drupal_flush_all_caches', []];
foreach ($post_updates as $function) {
......@@ -119,7 +148,8 @@ class Update extends Base {
$finished = FALSE;
while (!$finished) {
call_user_func_array($operation[0], $operation[1]);
$finished = (!empty($context['finished']) || !empty($context['sandbox']['#finished']));
// @phpstan-ignore-next-line
$finished = $context['finished'] || $context['sandbox']['#finished'];
}
}
}
......@@ -133,7 +163,7 @@ class Update extends Base {
private function captureUpdateMessages(array $results): void {
foreach ($results as $module => $updates) {
if ($module !== '#abort') {
foreach ($updates as $number => $queries) {
foreach ($updates as $queries) {
foreach ($queries as $query) {
// If there is no message for this update, don't show anything.
if (empty($query['query'])) {
......
......@@ -24,7 +24,7 @@ class Base implements BaseInterface {
*/
public static function getMethods(ContainerInterface $container, bool $instances = FALSE): array {
$methods = [];
foreach (['MCrypt', 'OpenSSL', 'TLS'] as $item) {
foreach (['OpenSSL', 'TLS'] as $item) {
$classname = "\\Drupal\\drd_agent\\Crypt\\Method\\$item";
/** @var BaseMethodInterface $method */
$method = new $classname($container);
......
<?php
namespace Drupal\drd_agent\Crypt\Method;
use Drupal\drd_agent\Crypt\BaseMethod;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides MCrypt encryption functionality.
*
* @ingroup drd
*/
class MCrypt extends BaseMethod {
/**
* The cypher.
*
* @var mixed|string
*/
private mixed $cipher;
/**
* The mode.
*
* @var mixed|string
*/
private mixed $mode;
/**
* The iv.
*
* @var string
*/
private string $iv;
/**
* The password.
*
* @var string
*/
private string $password;
/**
* {@inheritdoc}
*/
public function __construct(ContainerInterface $container, array $settings = []) {
parent::__construct($container);
$this->cipher = $settings['cipher'] ?? 'rijndael-256';
$this->mode = $settings['mode'] ?? 'cbc';
$this->password = $settings['password'] ?? '';
}
/**
* {@inheritdoc}
*/
public function getLabel(): string {
return 'MCrypt';
}
/**
* {@inheritdoc}
*/
public function getCipher(): string {
return $this->cipher;
}
/**
* {@inheritdoc}
*/
public function getPassword(): string {
return base64_decode($this->password);
}
/**
* {@inheritdoc}
*/
public function isAvailable(): bool {
return function_exists('mcrypt_encrypt');
}
/**
* {@inheritdoc}
*/
public function getCipherMethods(): array {
return [
'rijndael-128',
'rijndael-192',
'rijndael-256',
];
}
/**
* {@inheritdoc}
*/
public function getIv(): string {
if (empty($this->iv)) {
$nonceSize = mcrypt_get_iv_size($this->cipher, $this->mode);
$this->iv = mcrypt_create_iv($nonceSize, MCRYPT_DEV_URANDOM);
}
return $this->iv;
}
/**
* {@inheritdoc}
*/
public function encrypt(array $args): string {
return mcrypt_encrypt(
$this->cipher,
$this->getPassword(),
serialize($args),
$this->mode,
$this->getIv()
);
}
/**
* {@inheritdoc}
*/
public function decrypt(string $body, string $iv): mixed {
$this->iv = $iv;
return unserialize(mcrypt_decrypt(
$this->cipher,
$this->getPassword(),
$body,
$this->mode,
$this->iv
));
}
}
if (!defined('MCRYPT_DEV_URANDOM')) {
define('MCRYPT_DEV_URANDOM', 1);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment