Skip to content
Merged
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"extra": {
"drush": {
"services": {
"drush.11.6-12.5.yml": ">=11.6",
"drush.10.services.yml": "^10 || ^11"
}
}
Expand Down
1 change: 1 addition & 0 deletions drush.10.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ services:
arguments:
- '@account_switcher'
- '@entity_type.manager'
- '@logger.islandora_drush_utils'
tags:
- name: drush.command
islandora_drush_utils.command.user_wrapping_alterer:
Expand Down
6 changes: 6 additions & 0 deletions drush.11.6-12.5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
# XXX: Command files are expected to make use of newer methods of instantiation,
# such as:
# - create() method as of Drush 11.6; or,
# - autowiring as of Drush 12.5
services: {}
27 changes: 13 additions & 14 deletions islandora_drush_utils.module
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Implements hook_batch_alter().
*/
function islandora_drush_utils_batch_alter(&$batch) {
function islandora_drush_utils_batch_alter(array &$batch) : void {
// Better preservation messsaging.
foreach ($batch['sets'] as &$set) {
if (!isset($set['operations'])) {
Expand Down Expand Up @@ -59,24 +59,24 @@ function islandora_drush_utils_batch_alter(&$batch) {
if (is_string($callable)) {
return trim($callable);
}
elseif (is_array($callable)) {

if (is_array($callable)) {
if (is_object($callable[0])) {
return sprintf("(%s instance)::%s", get_class($callable[0]),
trim($callable[1]));
}
else {
return sprintf("%s::%s", trim($callable[0]), trim($callable[1]));
}

return sprintf("%s::%s", trim($callable[0]), trim($callable[1]));
}
elseif ($callable instanceof Closure) {

if ($callable instanceof Closure) {
return 'closure';
}
else {
return 'unknown';
}

return 'unknown';
};

$wrap_op = function ($op) use ($user, $logger, $namer) {
$wrap_op = static function ($op) use ($user, $logger, $namer) {
$func = reset($op);
if ($func !== '_islandora_drush_utils_user_wrapped_batch_op') {
$logger->debug('Wrapping @func with @wrapper to maintain the user (@uid).',
Expand All @@ -93,9 +93,8 @@ function islandora_drush_utils_batch_alter(&$batch) {
],
];
}
else {
return $op;
}

return $op;
};

foreach ($batch['sets'] as &$set) {
Expand All @@ -108,7 +107,7 @@ function islandora_drush_utils_batch_alter(&$batch) {
/**
* Wrap batch op with user.
*/
function _islandora_drush_utils_user_wrapped_batch_op($id, $info, &$context) {
function _islandora_drush_utils_user_wrapped_batch_op(int|string $id, array $info, array &$context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Verify PHP version supports union types.

The union type int|string requires PHP 8.0+. Please confirm the project's minimum PHP version meets this requirement.

Run the following script to check the PHP version constraint:


🏁 Script executed:

#!/bin/bash
# Description: Check minimum PHP version in composer.json

# Check for PHP version requirement
rg -n '"php":\s*"[^"]*"' composer.json

# Also check for any platform requirements
rg -n -A 5 '"platform"' composer.json

Length of output: 0


🏁 Script executed:

#!/bin/bash
# Locate composer.json files and check PHP version constraint
find . -type f -name 'composer.json' -print | while read file; do
  echo "File: $file"
  rg -n '"php":\s*"[^"]*"' "$file"
  rg -n -A 5 '"platform"' "$file"
done

Length of output: 21


🏁 Script executed:

#!/bin/bash
# Print the top of composer.json to locate PHP version requirement
head -n 200 composer.json

Length of output: 683


Declare PHP 8.0+ as a requirement
The int|string union type needs PHP 8.0 or newer—add "php": ">=8.0" to your composer.json (or confirm your Drupal core constraint already enforces ≥8.0).

🤖 Prompt for AI Agents
In islandora_drush_utils.module around line 110 the function uses the PHP 8.0+
union type "int|string", which requires your project to declare PHP >=8.0;
update composer.json to include "php": ">=8.0" in the "require" section (or
verify that your project's Drupal core or platform constraint already enforces
PHP >=8.0) and run composer update/composer validate to ensure constraints are
consistent; if you cannot raise the PHP requirement, replace the union type with
a compatible declaration (e.g., omit the typehint and validate inside the
function) instead.

$switcher = \Drupal::service('account_switcher');
try {
$user = \Drupal::service('entity_type.manager')
Expand Down
12 changes: 8 additions & 4 deletions src/Drush/Commands/UserWrapperCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\AccountSwitcherInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Drush\Commands\AutowireTrait;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
Expand All @@ -23,9 +24,9 @@
* "@islandora_drush_utils-user-wrap" annotation to use it where we want
* to.
*/
class UserWrapperCommands implements LoggerAwareInterface, ContainerInjectionInterface {
class UserWrapperCommands implements ContainerInjectionInterface {

use LoggerAwareTrait;
use AutowireTrait;

/**
* The user to which we will switch.
Expand All @@ -42,6 +43,8 @@ class UserWrapperCommands implements LoggerAwareInterface, ContainerInjectionInt
public function __construct(
protected AccountSwitcherInterface $switcher,
protected EntityTypeManagerInterface $entityTypeManager,
#[Autowire(service: 'logger.islandora_drush_utils')]
protected LoggerInterface $logger,
protected $debug = FALSE,
) {
}
Expand All @@ -53,6 +56,7 @@ public static function create(ContainerInterface $container) {
return new static(
$container->get('account_switcher'),
$container->get('entity_type.manager'),
$container->get('logger.islandora_drush_utils'),
FALSE,
);
}
Expand Down