Commit 85bec4c2 authored by Yas Naoi's avatar Yas Naoi Committed by Yas Naoi
Browse files

Issue #3191587 by yas, Xiaohua Guan: Add function's return type declaration (Tools)

parent 8f26d33d
Loading
Loading
Loading
Loading
+15 −13
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ use Drupal\Core\Entity\EntityInterface;
/**
 * Implements hook_help().
 */
function k8s_to_s3_help($route_name, RouteMatchInterface $route_match) {
function k8s_to_s3_help($route_name, RouteMatchInterface $route_match): string {
  switch ($route_name) {
    case 'help.page.k8s_to_s3':
      $output = '<h3>' . t('About') . '</h3>';
@@ -39,7 +39,7 @@ function k8s_to_s3_help($route_name, RouteMatchInterface $route_match) {
/**
 * Implements hook_cron().
 */
function k8s_to_s3_cron() {
function k8s_to_s3_cron(): void {
  if (!k8s_to_s3_validate_config()) {
    return;
  }
@@ -67,7 +67,7 @@ function k8s_to_s3_cron() {
 * @return bool
 *   TRUE if valid, else FALSE.
 */
function k8s_to_s3_validate_config() {
function k8s_to_s3_validate_config(): bool {
  $logger = \Drupal::logger('k8s_to_s3');
  $config = \Drupal::config('k8s_to_s3.settings');
  $k8s_clusters = empty($config->get('k8s_clusters'))
@@ -95,7 +95,7 @@ function k8s_to_s3_validate_config() {
/**
 * Copy K8s yaml templates up to S3.
 */
function k8s_to_s3_export_entities() {
function k8s_to_s3_export_entities(): void {
  /** @var \Drupal\aws_cloud\Service\Ecr\EcrServiceInterface $ecr */
  $ecr = \Drupal::service('aws_cloud.ecr');

@@ -180,7 +180,7 @@ function k8s_to_s3_export_entities() {
/**
 * Export server template to s3.
 */
function k8s_to_s3_export_server_templates() {
function k8s_to_s3_export_server_templates(): void {
  $config = \Drupal::config('k8s_to_s3.settings');
  $s3_bucket = $config->get('s3_bucket');
  $aws_cloud_context = $config->get('aws_cloud');
@@ -252,7 +252,7 @@ function k8s_to_s3_export_server_templates() {
 * @param array $operations
 *   Array of operations for batch to perform.
 */
function k8s_to_s3_run_batch(array $operations) {
function k8s_to_s3_run_batch(array $operations): void {
  if (count($operations)) {
    $batch = [
      'title' => t('Transferring k8s cloud images to ECR and S3'),
@@ -363,7 +363,7 @@ function k8s_to_s3_transfer_image_batch(
 * @return array
 *   Auth array.
 */
function k8s_to_s3_get_auth_token(EcrServiceInterface $ecr, $cloud_context) {
function k8s_to_s3_get_auth_token(EcrServiceInterface $ecr, $cloud_context): array {
  $ecr->setCloudContext($cloud_context);
  $token = $ecr->getAuthorizationToken();
  $token = base64_decode($token);
@@ -391,7 +391,7 @@ function k8s_to_s3_get_auth_token(EcrServiceInterface $ecr, $cloud_context) {
 * @param string $cloud_context
 *   Cloud context for ECR.
 *
 * @return bool|string
 * @return string
 *   Target image uri or false if not transferred.
 */
function k8s_to_s3_transfer_image(
@@ -399,8 +399,10 @@ function k8s_to_s3_transfer_image(
  DockerServiceInterface $docker,
  $image,
  $cloud_context
) {
): string {

  $auth = k8s_to_s3_get_auth_token($ecr, $cloud_context);
  $target_tag = '';

  if (count($auth)) {
    $info = $docker->parseImage($image);
@@ -453,7 +455,7 @@ function k8s_to_s3_get_ecr_target(
  EcrServiceInterface $ecr,
  $image,
  $cloud_context
) {
): string {
  $ecr->setCloudContext($cloud_context);
  $endpoint = $ecr->getEcrEndpoint();
  $info = $docker->parseImage($image);
@@ -475,7 +477,7 @@ function k8s_to_s3_get_ecr_target(
 * @return string
 *   The built key.
 */
function k8s_to_s3_build_k8s_s3_key(CloudContentEntityBase $entity, $entity_type, $delete = FALSE) {
function k8s_to_s3_build_k8s_s3_key(CloudContentEntityBase $entity, $entity_type, $delete = FALSE): string {
  $delete_str = '';
  if ($delete) {
    $delete_str = '.delete';
@@ -586,7 +588,7 @@ function k8s_to_s3_entity_presave(EntityInterface $entity) {
 * @param string $body
 *   The body of S3 object.
 */
function k8s_to_s3_put_object(S3ServiceInterface $s3_service, $s3_bucket, $key, $body) {
function k8s_to_s3_put_object(S3ServiceInterface $s3_service, $s3_bucket, $key, $body): void {
  $result = $s3_service->putObject([
    'Bucket' => $s3_bucket,
    'Key' => $key,
@@ -629,7 +631,7 @@ function k8s_to_s3_add_transfer_image_operations(
  EcrServiceInterface $ecr,
  DockerServiceInterface $docker,
  $aws_cloud_context
) {
): void {
  $containers = [];

  // Extract the containers array.
+4 −4
Original line number Diff line number Diff line
@@ -50,21 +50,21 @@ class K8sToS3AdminSettings extends ConfigFormBase {
  /**
   * {@inheritdoc}
   */
  public function getFormId() {
  public function getFormId(): string {
    return 'k8s_to_s3_admin_settings';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
  protected function getEditableConfigNames(): array {
    return ['k8s_to_s3.settings'];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
  public function buildForm(array $form, FormStateInterface $form_state): array {
    $config = $this->config('k8s_to_s3.settings');

    $aws_cloud_configs = $this->cloudConfigPluginManager->loadConfigEntities('aws_cloud');
@@ -150,7 +150,7 @@ class K8sToS3AdminSettings extends ConfigFormBase {
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
  public function submitForm(array &$form, FormStateInterface $form_state): void {
    $config = $this->configFactory()->getEditable('k8s_to_s3.settings');

    $k8s_clusters = array_filter($form_state->getValue('k8s_clusters'));
+8 −8
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ use Drupal\Core\Routing\RouteMatchInterface;
/**
 * Implements hook_help().
 */
function s3_to_k8s_help($route_name, RouteMatchInterface $route_match) {
function s3_to_k8s_help($route_name, RouteMatchInterface $route_match): string {
  switch ($route_name) {
    case 'help.page.s3_to_k8s':
      $output = '<h3>' . t('About') . '</h3>';
@@ -34,7 +34,7 @@ function s3_to_k8s_help($route_name, RouteMatchInterface $route_match) {
/**
 * Implements hook_cron().
 */
function s3_to_k8s_cron() {
function s3_to_k8s_cron(): void {
  $logger = \Drupal::logger('s3_to_k8s');
  $config = \Drupal::config('s3_to_k8s.settings');

@@ -56,7 +56,7 @@ function s3_to_k8s_cron() {
    return;
  }

  $k8s_cloud_context = $k8s_cloud_context = $config->get('k8s_cluster') === 'Automatic'
  $k8s_cloud_context = $config->get('k8s_cluster') === 'Automatic'
    ? s3_to_k8s_select_minimum_resource_cluster()
    : $config->get('k8s_cluster');
  if (empty($k8s_cloud_context)) {
@@ -120,7 +120,7 @@ function s3_to_k8s_cron() {
 * @param array $objects
 *   The S3 objects.
 */
function s3_to_k8s_import_entities($entity_type, $aws_cloud_context, $s3_bucket, $s3_path, $k8s_cloud_context, array $objects) {
function s3_to_k8s_import_entities($entity_type, $aws_cloud_context, $s3_bucket, $s3_path, $k8s_cloud_context, array $objects): void {
  $entity_map = [];
  $entities = \Drupal::entityTypeManager()
    ->getStorage($entity_type)
@@ -218,7 +218,7 @@ function s3_to_k8s_import_entities($entity_type, $aws_cloud_context, $s3_bucket,
 * @param array $objects
 *   The S3 objects.
 */
function s3_to_k8s_delete_entities($entity_type, $aws_cloud_context, $s3_bucket, $s3_path, $k8s_cloud_context, array $objects) {
function s3_to_k8s_delete_entities($entity_type, $aws_cloud_context, $s3_bucket, $s3_path, $k8s_cloud_context, array $objects): void {
  $entity_map = [];
  $entities = \Drupal::entityTypeManager()
    ->getStorage($entity_type)
@@ -295,16 +295,16 @@ function s3_to_k8s_delete_entities($entity_type, $aws_cloud_context, $s3_bucket,
}

/**
 * Select a K8s cluser of the minium resource usage.
 * Select a K8s cluster of the minium resource usage.
 */
function s3_to_k8s_select_minimum_resource_cluster() {
function s3_to_k8s_select_minimum_resource_cluster(): mixed {
  $entities = \Drupal::service('plugin.manager.cloud_config_plugin')->loadConfigEntities('k8s');

  $cloud_contexts = array_map(static function ($entity) {
    return $entity->getCloudContext();
  }, $entities);
  if (empty($cloud_contexts)) {
    return;
    return NULL;
  }

  $weight_pods = 0.5;
+4 −4
Original line number Diff line number Diff line
@@ -76,21 +76,21 @@ class S3ToK8sAdminSettings extends ConfigFormBase {
  /**
   * {@inheritdoc}
   */
  public function getFormId() {
  public function getFormId(): string {
    return 's3_to_k8s_admin_settings';
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
  protected function getEditableConfigNames(): array {
    return ['s3_to_k8s.settings'];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
  public function buildForm(array $form, FormStateInterface $form_state): array {
    $config = $this->config('s3_to_k8s.settings');

    $aws_cloud_configs = $this->cloudConfigPluginManager->loadConfigEntities('aws_cloud');
@@ -162,7 +162,7 @@ class S3ToK8sAdminSettings extends ConfigFormBase {
  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
  public function submitForm(array &$form, FormStateInterface $form_state): void {
    $config = $this->configFactory()->getEditable('s3_to_k8s.settings');
    $config->set('aws_cloud', $form_state->getValue('aws_cloud'));
    $config->set('s3_bucket', $form_state->getValue('s3_bucket'));