From df745f12132ec2c4a8d0ff10cdccf67d9643ab51 Mon Sep 17 00:00:00 2001 From: yas <45549-yas@users.noreply.drupalcode.org> Date: Wed, 26 Apr 2023 02:09:09 -0700 Subject: [PATCH] Issue #3356158 by yas, sekinet, baldwinlouie, Xiaohua Guan, Masami: Refactor to use static closure (2) --- .../src/Service/CloudClusterWorkerService.php | 2 +- .../src/Controller/Ec2/ApiController.php | 8 +++---- .../src/Form/Ec2/ElasticIpAssociateForm.php | 4 ++-- .../src/Form/Ec2/InstanceEditForm.php | 2 +- .../Block/LowUtilizationInstancesBlock.php | 2 +- .../Plugin/Block/UnusedElasticIpsBlock.php | 2 +- .../AwsCloud/AwsCloudOperationsService.php | 4 ++-- .../aws_cloud/src/Service/Ec2/Ec2Service.php | 2 +- .../K8sCloudLaunchTemplatePlugin.php | 2 +- .../k8s/src/Service/K8sService.php | 2 +- .../src/Controller/ApiController.php | 4 ++-- .../src/Form/OpenStackInstanceEditForm.php | 2 +- .../FieldFormatter/UserRolesFormatter.php | 4 ++-- .../Field/FieldWidget/UserRolesItem.php | 2 +- .../src/Service/OpenStackBatchOperations.php | 8 +++---- .../Service/OpenStackOperationsService.php | 24 +++++++++---------- .../src/Service/Rest/OpenStackService.php | 4 ++-- 17 files changed, 39 insertions(+), 39 deletions(-) diff --git a/modules/cloud_cluster_worker/src/Service/CloudClusterWorkerService.php b/modules/cloud_cluster_worker/src/Service/CloudClusterWorkerService.php index 2412599898..d0c55ca654 100644 --- a/modules/cloud_cluster_worker/src/Service/CloudClusterWorkerService.php +++ b/modules/cloud_cluster_worker/src/Service/CloudClusterWorkerService.php @@ -352,7 +352,7 @@ class CloudClusterWorkerService extends CloudServiceBase implements CloudCluster } } - array_walk_recursive($params, function (&$value, $key) use ($param_refs, $refs) { + array_walk_recursive($params, static function (&$value, $key) use ($param_refs, $refs) { if (!empty($param_refs[$key]) && $value === $refs[$key]) { $value = $param_refs[$key]; } diff --git a/modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php b/modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php index a9611b6571..aee33f339c 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php +++ b/modules/cloud_service_providers/aws_cloud/src/Controller/Ec2/ApiController.php @@ -682,7 +682,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { if ($key === 'network_in' || $key === 'network_out') { // Convert Byte to MB. - $data[$key]['values'] = array_map(function ($value) { + $data[$key]['values'] = array_map(static function ($value) { return $value / 1024 / 1024; }, $data[$key]['values']); } @@ -1450,7 +1450,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { ]); $options = []; - array_walk($groups, function ($group) use (&$options) { + array_walk($groups, static function ($group) use (&$options) { $options[$group->getGroupName()] = $group->getGroupName(); }); @@ -1785,7 +1785,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { 'cloud_context' => $entity->getCloudContext(), 'network_border_group' => $network_border_group, ]); - $subnet_ids = array_map(function ($subnet) { + $subnet_ids = array_map(static function ($subnet) { return $subnet->getSubnetId(); }, $subnets); if (!empty($subnet_ids)) { @@ -1882,7 +1882,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { 'cloud_context' => $entity->getCloudContext(), 'network_border_group' => $network_border_group, ]); - $subnet_ids = array_map(function ($subnet) { + $subnet_ids = array_map(static function ($subnet) { return $subnet->getSubnetId(); }, $subnets); if (!empty($subnet_ids)) { diff --git a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/ElasticIpAssociateForm.php b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/ElasticIpAssociateForm.php index 701e9a32eb..6bee1163b5 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/ElasticIpAssociateForm.php +++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/ElasticIpAssociateForm.php @@ -489,7 +489,7 @@ class ElasticIpAssociateForm extends AwsDeleteForm { 'cloud_context' => $entity->getCloudContext(), 'network_border_group' => $network_border_group, ]); - $subnet_ids = array_map(function ($subnet) { + $subnet_ids = array_map(static function ($subnet) { return $subnet->getSubnetId(); }, $subnets); if (!empty($subnet_ids)) { @@ -585,7 +585,7 @@ class ElasticIpAssociateForm extends AwsDeleteForm { 'cloud_context' => $entity->getCloudContext(), 'network_border_group' => $network_border_group, ]); - $subnet_ids = array_map(function ($subnet) { + $subnet_ids = array_map(static function ($subnet) { return $subnet->getSubnetId(); }, $subnets); if (!empty($subnet_ids)) { diff --git a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceEditForm.php b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceEditForm.php index dc96745557..650da23100 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceEditForm.php +++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/InstanceEditForm.php @@ -689,7 +689,7 @@ class InstanceEditForm extends AwsCloudContentForm { 'vpc_id' => $entity->getVpcId(), ]); - array_walk($groups, function ($group) use (&$options) { + array_walk($groups, static function ($group) use (&$options) { $options[$group->getGroupName()] = $group->getGroupName(); }); diff --git a/modules/cloud_service_providers/aws_cloud/src/Plugin/Block/LowUtilizationInstancesBlock.php b/modules/cloud_service_providers/aws_cloud/src/Plugin/Block/LowUtilizationInstancesBlock.php index e3470b4df0..004b610a31 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Plugin/Block/LowUtilizationInstancesBlock.php +++ b/modules/cloud_service_providers/aws_cloud/src/Plugin/Block/LowUtilizationInstancesBlock.php @@ -213,7 +213,7 @@ class LowUtilizationInstancesBlock extends BlockBase implements ContainerFactory } else { - $urls = array_map(function ($instance) { + $urls = array_map(static function ($instance) { return $instance->toLink($this->t('@instance', [ '@instance' => $instance->getName(), ])); diff --git a/modules/cloud_service_providers/aws_cloud/src/Plugin/Block/UnusedElasticIpsBlock.php b/modules/cloud_service_providers/aws_cloud/src/Plugin/Block/UnusedElasticIpsBlock.php index dbfc60a640..872ec05805 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Plugin/Block/UnusedElasticIpsBlock.php +++ b/modules/cloud_service_providers/aws_cloud/src/Plugin/Block/UnusedElasticIpsBlock.php @@ -33,7 +33,7 @@ class UnusedElasticIpsBlock extends BlockBase { ]; } else { - $urls = array_map(function ($elastic_ip) { + $urls = array_map(static function ($elastic_ip) { if ($elastic_ip->getName() === $elastic_ip->getPublicIp()) { return $elastic_ip->toLink($elastic_ip->getPublicIp()); } diff --git a/modules/cloud_service_providers/aws_cloud/src/Service/AwsCloud/AwsCloudOperationsService.php b/modules/cloud_service_providers/aws_cloud/src/Service/AwsCloud/AwsCloudOperationsService.php index b47cda6b11..efb2edf269 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Service/AwsCloud/AwsCloudOperationsService.php +++ b/modules/cloud_service_providers/aws_cloud/src/Service/AwsCloud/AwsCloudOperationsService.php @@ -2650,7 +2650,7 @@ class AwsCloudOperationsService implements AwsCloudOperationsServiceInterface { $this->ec2Service->modifyImageAttribute([ 'ImageId' => $entity->getImageId(), 'LaunchPermission' => [ - 'Remove' => array_map(function ($item) { + 'Remove' => array_map(static function ($item) { return ['UserId' => $item]; }, $account_ids_to_remove), ], @@ -2661,7 +2661,7 @@ class AwsCloudOperationsService implements AwsCloudOperationsServiceInterface { $this->ec2Service->modifyImageAttribute([ 'ImageId' => $entity->getImageId(), 'LaunchPermission' => [ - 'Add' => array_map(function ($item) { + 'Add' => array_map(static function ($item) { return ['UserId' => $item]; }, $account_ids_to_add), ], diff --git a/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2Service.php b/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2Service.php index cadcd368df..3c456be3d4 100644 --- a/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2Service.php +++ b/modules/cloud_service_providers/aws_cloud/src/Service/Ec2/Ec2Service.php @@ -443,7 +443,7 @@ class Ec2Service extends CloudServiceBase implements Ec2ServiceInterface { ]); // Converts NULL in the array to an empty string value (''). - !is_array($params) ?: array_walk_recursive($params, function (&$value, $key) { + !is_array($params) ?: array_walk_recursive($params, static function (&$value, $key) { $value = $value ?? ''; }); $command = $ec2_client->getCommand($operation, $params); diff --git a/modules/cloud_service_providers/k8s/src/Plugin/cloud/launch_template/K8sCloudLaunchTemplatePlugin.php b/modules/cloud_service_providers/k8s/src/Plugin/cloud/launch_template/K8sCloudLaunchTemplatePlugin.php index b7ec143d42..7145b3ae18 100644 --- a/modules/cloud_service_providers/k8s/src/Plugin/cloud/launch_template/K8sCloudLaunchTemplatePlugin.php +++ b/modules/cloud_service_providers/k8s/src/Plugin/cloud/launch_template/K8sCloudLaunchTemplatePlugin.php @@ -1345,7 +1345,7 @@ class K8sCloudLaunchTemplatePlugin extends CloudPluginBase implements CloudLaunc $self = $this; - $promise = new Promise(function () use (&$promise, $self, $yaml_string, $namespace) { + $promise = new Promise(static function () use (&$promise, $self, $yaml_string, $namespace) { $object_types = $self->k8sService->supportedCloudLaunchTemplates(); $yamls = $self->k8sService->decodeMultipleDocYaml($yaml_string); diff --git a/modules/cloud_service_providers/k8s/src/Service/K8sService.php b/modules/cloud_service_providers/k8s/src/Service/K8sService.php index 1e7e4c31ad..0040bbe35d 100644 --- a/modules/cloud_service_providers/k8s/src/Service/K8sService.php +++ b/modules/cloud_service_providers/k8s/src/Service/K8sService.php @@ -3694,7 +3694,7 @@ class K8sService extends CloudServiceBase implements K8sServiceInterface { ]); // Sort pods by oldest first. - usort($pods, function ($a, $b) { + usort($pods, static function ($a, $b) { if ($a->created() === $b->created()) { return 0; } diff --git a/modules/cloud_service_providers/openstack/src/Controller/ApiController.php b/modules/cloud_service_providers/openstack/src/Controller/ApiController.php index 9cfd6b693d..fe675cfa61 100644 --- a/modules/cloud_service_providers/openstack/src/Controller/ApiController.php +++ b/modules/cloud_service_providers/openstack/src/Controller/ApiController.php @@ -1407,7 +1407,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { 'cloud_context' => $entity->getCloudContext(), 'network_border_group' => $network_border_group, ]); - $subnet_ids = array_map(function ($subnet) { + $subnet_ids = array_map(static function ($subnet) { return $subnet->getSubnetId(); }, $subnets); if (!empty($subnet_ids)) { @@ -1945,7 +1945,7 @@ class ApiController extends ControllerBase implements ApiControllerInterface { * The options converted. */ private function convertOptionsForJson(array $options): array { - return array_map(function ($key, $value) { + return array_map(static function ($key, $value) { return [ 'value' => $key, 'label' => $value, diff --git a/modules/cloud_service_providers/openstack/src/Form/OpenStackInstanceEditForm.php b/modules/cloud_service_providers/openstack/src/Form/OpenStackInstanceEditForm.php index 38b02af79a..6b9d10e7c6 100644 --- a/modules/cloud_service_providers/openstack/src/Form/OpenStackInstanceEditForm.php +++ b/modules/cloud_service_providers/openstack/src/Form/OpenStackInstanceEditForm.php @@ -400,7 +400,7 @@ class OpenStackInstanceEditForm extends InstanceEditForm { 'cloud_context' => $entity->getCloudContext(), ]); - array_walk($groups, function ($group) use (&$options) { + array_walk($groups, static function ($group) use (&$options) { $options[$group->getGroupName()] = $group->getGroupName(); }); diff --git a/modules/cloud_service_providers/openstack/src/Plugin/Field/FieldFormatter/UserRolesFormatter.php b/modules/cloud_service_providers/openstack/src/Plugin/Field/FieldFormatter/UserRolesFormatter.php index 3e8a4f65b5..fcc5bce85f 100644 --- a/modules/cloud_service_providers/openstack/src/Plugin/Field/FieldFormatter/UserRolesFormatter.php +++ b/modules/cloud_service_providers/openstack/src/Plugin/Field/FieldFormatter/UserRolesFormatter.php @@ -66,7 +66,7 @@ class UserRolesFormatter extends FormatterBase implements ContainerFactoryPlugin } // Sort $roles by the label of role. - usort($roles, function ($a, $b) { + usort($roles, static function ($a, $b) { return ($a->label() < $b->label()) ? -1 : 1; }); @@ -77,7 +77,7 @@ class UserRolesFormatter extends FormatterBase implements ContainerFactoryPlugin } // Sort $user_roles by the label of user. - usort($user_roles_list, function ($a, $b) { + usort($user_roles_list, static function ($a, $b) { return ($a[0]->label() < $b[0]->label()) ? -1 : 1; }); diff --git a/modules/cloud_service_providers/openstack/src/Plugin/Field/FieldWidget/UserRolesItem.php b/modules/cloud_service_providers/openstack/src/Plugin/Field/FieldWidget/UserRolesItem.php index bd86f1d46c..2313fd593b 100644 --- a/modules/cloud_service_providers/openstack/src/Plugin/Field/FieldWidget/UserRolesItem.php +++ b/modules/cloud_service_providers/openstack/src/Plugin/Field/FieldWidget/UserRolesItem.php @@ -146,7 +146,7 @@ class UserRolesItem extends WidgetBase implements ContainerFactoryPluginInterfac ->loadByProperties($properties); // Sort by name. - usort($entities, function ($a, $b) { + usort($entities, static function ($a, $b) { return $a->getName() < $b->getName() ? -1 : 1; }); diff --git a/modules/cloud_service_providers/openstack/src/Service/OpenStackBatchOperations.php b/modules/cloud_service_providers/openstack/src/Service/OpenStackBatchOperations.php index 0b765f1211..5d78224edb 100644 --- a/modules/cloud_service_providers/openstack/src/Service/OpenStackBatchOperations.php +++ b/modules/cloud_service_providers/openstack/src/Service/OpenStackBatchOperations.php @@ -1302,11 +1302,11 @@ class OpenStackBatchOperations { } // Sort by role name. - usort($roles, function ($a, $b) { + usort($roles, static function ($a, $b) { return $a->getName() < $b->getName() ? -1 : 1; }); - $role_ids = array_map(function ($role) { + $role_ids = array_map(static function ($role) { return $role->id(); }, $roles); @@ -1317,12 +1317,12 @@ class OpenStackBatchOperations { } // Sort by user name. - usort($user_roles, function ($a, $b) { + usort($user_roles, static function ($a, $b) { return $a['user']->getName() < $b['user']->getName() ? -1 : 1; }); // Update property user to id. - $user_roles = array_map(function ($item) { + $user_roles = array_map(static function ($item) { return [ 'user' => $item['user']->id(), 'roles' => $item['roles'], diff --git a/modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsService.php b/modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsService.php index f1000169e8..e8f54901cb 100644 --- a/modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsService.php +++ b/modules/cloud_service_providers/openstack/src/Service/OpenStackOperationsService.php @@ -652,7 +652,7 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface $this->ec2Service->modifyImageAttribute([ 'ImageId' => $entity->getImageId(), 'LaunchPermission' => [ - 'Remove' => array_map(function ($item) { + 'Remove' => array_map(static function ($item) { return ['UserId' => $item]; }, $account_ids_to_remove), ], @@ -663,7 +663,7 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface $this->ec2Service->modifyImageAttribute([ 'ImageId' => $entity->getImageId(), 'LaunchPermission' => [ - 'Add' => array_map(function ($item) { + 'Add' => array_map(static function ($item) { return ['UserId' => $item]; }, $account_ids_to_add), ], @@ -752,7 +752,7 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface } $shared_projects = $form_state->getValue('shared_projects'); - if (empty($shared_projects) || count(array_filter($shared_projects, function ($project) { + if (empty($shared_projects) || count(array_filter($shared_projects, static function ($project) { return is_array($project) && !empty($project['project_id']); })) === 0) { $form_state->setErrorByName('shared_projects', $this->t("At least one valid project ID is required when you select the 'Shared' option as 'Visibility'.")); @@ -760,7 +760,7 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface } // Validate each project in $shared_projects array. - $invalid_project_id_found = in_array(TRUE, array_map(function ($project) { + $invalid_project_id_found = in_array(TRUE, array_map(static function ($project) { // Ensure each project_id is a non-empty alphanumeric string. return is_array($project) && !empty($project['project_id']) && !preg_match('/^[a-zA-Z0-9]+$/', $project['project_id']); }, $shared_projects ?? [])); @@ -963,7 +963,7 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface $entity->set('termination_timestamp', NULL); } - $port_ids = array_filter(array_map(function ($port_id_with_value) { + $port_ids = array_filter(array_map(static function ($port_id_with_value) { if (!empty($port_id_with_value['value'])) { return $port_id_with_value['value']; } @@ -4568,7 +4568,7 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface } // Sort by value. - uasort($options, function ($a, $b) { + uasort($options, static function ($a, $b) { return $a < $b ? -1 : 1; }); @@ -4594,11 +4594,11 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface 'external' => TRUE, ]); - $ext_network_ids = array_map(function ($item) { + $ext_network_ids = array_map(static function ($item) { return $item->getNetworkId(); }, $ext_networks); - $router_ports = array_filter($ports, function ($port) { + $router_ports = array_filter($ports, static function ($port) { return in_array($port->getDeviceOwner(), OpenStackServiceInterface::ROUTER_INTERFACE_OWNERS); }); @@ -4608,7 +4608,7 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface 'cloud_context' => $cloud_context, 'external_gateway_network_id' => $ext_network_ids, ]); - $gw_router_ids = array_map(function ($item) { + $gw_router_ids = array_map(static function ($item) { return $item->getRouterId(); }, $gw_routers); @@ -4629,7 +4629,7 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface 'shared' => TRUE, ]); - $shared_network_ids = array_map(function ($item) { + $shared_network_ids = array_map(static function ($item) { return $item->getNetworkId(); }, $shared_networks); @@ -4640,7 +4640,7 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface 'network_id' => $shared_network_ids, ]); - $shared_subnet_ids = array_map(function ($item) { + $shared_subnet_ids = array_map(static function ($item) { return $item->getSubnetId(); }, $shared_subnets); @@ -4715,7 +4715,7 @@ class OpenStackOperationsService implements OpenStackOperationsServiceInterface $this->getSubnet($network->getNetworkId(), 'IPv6', $cloud_context) ); - $cidrs = array_map(function ($subnet) { + $cidrs = array_map(static function ($subnet) { return $subnet->getCidr(); }, $subnets); diff --git a/modules/cloud_service_providers/openstack/src/Service/Rest/OpenStackService.php b/modules/cloud_service_providers/openstack/src/Service/Rest/OpenStackService.php index 83a0d23ca4..68259bfa0f 100644 --- a/modules/cloud_service_providers/openstack/src/Service/Rest/OpenStackService.php +++ b/modules/cloud_service_providers/openstack/src/Service/Rest/OpenStackService.php @@ -4009,7 +4009,7 @@ class OpenStackService extends CloudServiceBase implements OpenStackServiceInter ->loadByProperties([ 'cloud_context' => $this->cloudContext, ]); - $network_ids = array_map(function ($item) { + $network_ids = array_map(static function ($item) { return !empty($item) ? $item->getNetworkId() : ''; }, $networks ?: []); @@ -4315,7 +4315,7 @@ class OpenStackService extends CloudServiceBase implements OpenStackServiceInter ->loadByProperties([ 'cloud_context' => $this->cloudContext, ]); - $network_ids = array_map(function ($item) { + $network_ids = array_map(static function ($item) { return !empty($item) ? $item->getNetworkId() : ''; }, $networks ?: []); -- GitLab