From 8fc070159804bedd73421b999b2b0303ffdb0d53 Mon Sep 17 00:00:00 2001
From: "das.gautam27" <das.gautam27@yahoo.com>
Date: Fri, 14 Mar 2025 16:31:32 +0530
Subject: [PATCH 1/5] DRAFT by damienmckenna: Add a migration example.

---
 migrate_source_ical.info.yml                  |   2 +-
 src/Plugin/migrate/source/Ical.php            |  23 ++--
 .../Plugin/migrate/source/IcalKernelTest.php  | 107 +++++++++++++++++-
 3 files changed, 114 insertions(+), 18 deletions(-)

diff --git a/migrate_source_ical.info.yml b/migrate_source_ical.info.yml
index 3f7d261..267e167 100644
--- a/migrate_source_ical.info.yml
+++ b/migrate_source_ical.info.yml
@@ -1,6 +1,6 @@
 name: Migrate Source iCal
 description: Migrate data from calendars like google calendar or .ical files.
-core_version_requirement: ^8 || ^9
+core_version_requirement: ^8 || ^9 || ^10 || ^11
 type: module
 package: migrate
 dependencies:
diff --git a/src/Plugin/migrate/source/Ical.php b/src/Plugin/migrate/source/Ical.php
index 261fc58..a257904 100644
--- a/src/Plugin/migrate/source/Ical.php
+++ b/src/Plugin/migrate/source/Ical.php
@@ -1,8 +1,4 @@
 <?php
-/**
- * @file
- * Contains \Drupal\migrate_source_ical\Plugin\migrate\source\ical.
- */
 
 namespace Drupal\migrate_source_ical\Plugin\migrate\source;
 
@@ -70,15 +66,15 @@ class Ical extends SourcePluginBase {
   /**
    * {@inheritdoc}
    */
-  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, array $namespaces = array()) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, array $namespaces = []) {
     parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
 
-    $config_fields = array(
+    $config_fields = [
       'path',
       'fields',
       'identifier',
-      'keys'
-    );
+      'ids',
+    ];
 
     // Store the configuration data.
     foreach ($config_fields as $config_field) {
@@ -91,7 +87,7 @@ class Ical extends SourcePluginBase {
       }
     }
 
-    // TODO:
+    // @todo
     $this->readerClass = !isset($configuration['readerClass']) ? '\Drupal\migrate_source_ical\Plugin\migrate\IcalReader' : $configuration['readerClass'];
 
     // Create the ICAL reader that will process the request, and pass it configuration.
@@ -105,14 +101,14 @@ class Ical extends SourcePluginBase {
    * @return int
    *   The number of available source records.
    */
-  public function _count($url) {
+  public function _count($url): int {
     return count($this->reader->getSourceFields($url));
   }
 
   /**
    * {@inheritdoc}
    */
-  public function count($refresh = false) {
+  public function count($refresh = FALSE): int {
     return $this->_count($this->path);
   }
 
@@ -120,8 +116,8 @@ class Ical extends SourcePluginBase {
    * {@inheritdoc}
    */
   public function getIds() {
-    $ids = array();
-    foreach ($this->configuration['keys'] as $key) {
+    $ids = [];
+    foreach ($this->configuration['ids'] as $key) {
       $ids[$key]['type'] = 'string';
     }
     return $ids;
@@ -155,4 +151,5 @@ class Ical extends SourcePluginBase {
     $iterator = $this->reader->getSourceFieldsIterator($this->path);
     return $iterator;
   }
+
 }
diff --git a/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php b/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php
index 3f71c98..52456e2 100644
--- a/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php
+++ b/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php
@@ -1,9 +1,14 @@
 <?php
 
-namespace Drupal\Tests\migrate_source_ical\Unit\Plugin\migrate\source;
+namespace Drupal\Tests\migrate_source_ical\Kernel\Plugin\migrate\source;
 
+use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
+use Drupal\field\Entity\FieldConfig;
+use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\KernelTests\KernelTestBase;
-use Drupal\migrate\Plugin\MigratePluginManagerInterface;
+use Drupal\migrate\MigrateExecutable;
+use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
 
 /**
  * @coversDefaultClass \Drupal\migrate_source_ical\Plugin\migrate\source\Ical
@@ -12,10 +17,56 @@ use Drupal\migrate\Plugin\MigratePluginManagerInterface;
  */
 class IcalKernelTest extends KernelTestBase {
 
+  use ContentTypeCreationTrait;
+
+  protected $bundle;
+
+  protected $entityTypeId;
+
   /**
    * {@inheritdoc}
    */
-  public static $modules = ['migrate', 'migrate_source_ical'];
+  public static $modules = [
+    'migrate',
+    'migrate_source_ical',
+    'node',
+    'user',
+    'system',
+    'field',
+    'text',
+    'datetime',
+  ];
+
+  public function setUp(): void {
+    parent::setUp(); // TODO: Change the autogenerated stub
+    $this->installSchema('node',[]);
+    $this->installSchema('user',[]);
+    $this->installSchema('system',[]);
+    $this->installSchema('field',[]);
+    $this->installSchema('user',[]);
+    $this->installConfig(['node', 'user']);
+    $this->entityTypeId = 'node';
+    $this->bundle = $this->createContentType(['type' => 'event']);
+
+    // Create a field with settings to validate.
+    $this->fieldStorage = FieldStorageConfig::create([
+      'field_name' => 'field_event_date',
+      'type' => 'datetime',
+      'entity_type' => $this->entityTypeId,
+      'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME],
+    ]);
+    $this->fieldStorage->save();
+    $this->field = FieldConfig::create([
+      'field_storage' => $this->fieldStorage,
+      'bundle' => $this->bundle->id(),
+      'settings' => [
+        'default_value' => 'blank',
+      ],
+    ]);
+    $this->field->save();
+
+
+  }
 
   /**
    * Tests the construction of Ical.
@@ -23,9 +74,57 @@ class IcalKernelTest extends KernelTestBase {
    * @covers ::__construct
    */
   public function testCreate() {
-    /** @var MigratePluginManagerInterface $migrationSourceManager */
+    /** @var \Drupal\migrate\Plugin\MigratePluginManagerInterface $migrationSourceManager */
     $migrationSourceManager = $this->container->get('plugin.manager.migrate.source');
     $this->assertTrue($migrationSourceManager->hasDefinition('ical'));
   }
 
+  /**
+   *
+   */
+  public function testSourcePlugin() {
+    // @todo Create a test json input.
+    $definition = [
+      'source' => [
+        'plugin' => 'ical',
+        'path' => 'http://l.d11/sites/default/files/calendar.ics',
+        'identifier' => 'upc',
+        'identifierDepth' => 1,
+        'ids' => [
+          'uid',
+        ],
+        'fields' => [
+          'uid' => 'UID',
+          'dtstart' => 'Date Start',
+        ],
+      ],
+      'process' => [
+        'title' => 'title',
+        'field_event_date/value' => [
+          'plugin' => 'format_date',
+          'from_format' => 'YmdTHisZ',
+          'to_format' => 'Y-m-d',
+          'source' => 'dtstart',
+        ]
+      ],
+      'destination' => [
+        'plugin' => 'entity:node',
+        'default_bundle' => 'article',
+      ],
+    ];
+
+    $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
+
+    $executable = new MigrateExecutable($migration);
+    $result = $executable->import();
+    // Check that the migration has completed.
+    $this->assertEquals(MigrationInterface::RESULT_COMPLETED, $result);
+
+    /** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map_plugin */
+    $id_map_plugin = $migration->getIdMap();
+    $map_row = $id_map_plugin->getRowBySource(['title' => 'about-us']);
+//    $this->assertEquals(MigrateIdMapInterface::STATUS_FAILED, $map_row['source_row_status']);
+    $this->assertNotNull($map_row['destid1']);
+  }
+
 }
-- 
GitLab


From 8480f529320dbd6ae0cb859f8132bfe150bb1fb1 Mon Sep 17 00:00:00 2001
From: hs-gautam <gautam@genero.jp>
Date: Fri, 14 Mar 2025 19:38:39 +0530
Subject: [PATCH 2/5] #Issue 3297668: Improved tests and fixed warnings.

---
 migrate_source_ical.info.yml                  |  2 +-
 src/Plugin/migrate/IcalReader.php             |  7 ---
 src/Plugin/migrate/process/IcalFormatDate.php |  8 ++--
 src/Plugin/migrate/source/Ical.php            |  9 +---
 tests/calendar.ics                            | 23 +++++++++
 .../Plugin/migrate/source/IcalKernelTest.php  | 47 +++++++++++--------
 6 files changed, 56 insertions(+), 40 deletions(-)
 create mode 100644 tests/calendar.ics

diff --git a/migrate_source_ical.info.yml b/migrate_source_ical.info.yml
index 267e167..7b9a9f2 100644
--- a/migrate_source_ical.info.yml
+++ b/migrate_source_ical.info.yml
@@ -1,6 +1,6 @@
 name: Migrate Source iCal
 description: Migrate data from calendars like google calendar or .ical files.
-core_version_requirement: ^8 || ^9 || ^10 || ^11
+core_version_requirement: ^10 || ^11
 type: module
 package: migrate
 dependencies:
diff --git a/src/Plugin/migrate/IcalReader.php b/src/Plugin/migrate/IcalReader.php
index c2997a4..64bc070 100644
--- a/src/Plugin/migrate/IcalReader.php
+++ b/src/Plugin/migrate/IcalReader.php
@@ -94,13 +94,6 @@ use ICal\ICal;
  */
 class IcalReader {
 
-  /**
-   * The client class to create the HttpClient.
-   *
-   * @var string
-   */
-  protected $clientClass = '';
-
   /**
    * The HTTP Client
    *
diff --git a/src/Plugin/migrate/process/IcalFormatDate.php b/src/Plugin/migrate/process/IcalFormatDate.php
index 88a2b7b..cc38d33 100644
--- a/src/Plugin/migrate/process/IcalFormatDate.php
+++ b/src/Plugin/migrate/process/IcalFormatDate.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Drupal\migrate_source_ical\Plugin\migrate\Process;
+namespace Drupal\migrate_source_ical\Plugin\migrate\process;
 
 use Drupal\migrate\Plugin\migrate\process\FormatDate;
 use Drupal\Component\Datetime\DateTimePlus;
@@ -49,13 +49,13 @@ use Drupal\migrate\Row;
  *     to_format: Y-m-d\TH:i:s
  *     source: event_date
  * @endcode
- * 
+ *
  * @see \DateTime::createFromFormat()
  * @see \Drupal\Component\Datetime\DateTimePlus::__construct()
  * @see \Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface
  * @see \Drupal\migrate\Plugin\MigrateProcessInterface
  * @see \Drupal\migrate\Plugin\migrate\process\FormatDate
- * 
+ *
  * @MigrateProcessPlugin(
  *   id = "ical_format_date"
  * )
@@ -86,7 +86,7 @@ class IcalFormatDate extends FormatDate {
   * @return string
   *  The date format to use, using standard PHP notation; defaults to 'Ymd'.
   */
-  private function determineFromFormat() {
+  private function determineFromFormat($value) {
     $length = strlen($value);
 
     // Date strings which include the full date, time and "Z".
diff --git a/src/Plugin/migrate/source/Ical.php b/src/Plugin/migrate/source/Ical.php
index a257904..16fe700 100644
--- a/src/Plugin/migrate/source/Ical.php
+++ b/src/Plugin/migrate/source/Ical.php
@@ -56,12 +56,6 @@ class Ical extends SourcePluginBase {
    */
   protected $reader;
 
-  /**
-   * The client class to create the HttpClient.
-   *
-   * @var string
-   */
-  protected $clientClass = '';
 
   /**
    * {@inheritdoc}
@@ -148,8 +142,7 @@ class Ical extends SourcePluginBase {
    * {@inheritdoc}
    */
   protected function initializeIterator() {
-    $iterator = $this->reader->getSourceFieldsIterator($this->path);
-    return $iterator;
+    return $this->reader->getSourceFieldsIterator($this->path);
   }
 
 }
diff --git a/tests/calendar.ics b/tests/calendar.ics
new file mode 100644
index 0000000..674c1e8
--- /dev/null
+++ b/tests/calendar.ics
@@ -0,0 +1,23 @@
+BEGIN:VCALENDAR
+PRODID:-//Google Inc//Google Calendar 70.9054//EN
+VERSION:2.0
+CALSCALE:GREGORIAN
+METHOD:PUBLISH
+X-WR-CALNAME:DrupalCon Events
+X-WR-TIMEZONE:Asia/Kolkata
+
+BEGIN:VEVENT
+DTSTART;VALUE=DATE:20241209
+DTEND;VALUE=DATE:20241211
+UID:ical_event01
+SUMMARY:DrupalCon Singapore
+END:VEVENT
+
+BEGIN:VEVENT
+DTSTART;VALUE=DATE:20250324
+DTEND;VALUE=DATE:20250327
+UID:ical_event02
+SUMMARY:DrupalCon Atlanta
+END:VEVENT
+
+END:VALENDAR
diff --git a/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php b/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php
index 52456e2..4377fab 100644
--- a/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php
+++ b/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php
@@ -38,13 +38,16 @@ class IcalKernelTest extends KernelTestBase {
   ];
 
   public function setUp(): void {
-    parent::setUp(); // TODO: Change the autogenerated stub
+    parent::setUp();
     $this->installSchema('node',[]);
     $this->installSchema('user',[]);
     $this->installSchema('system',[]);
     $this->installSchema('field',[]);
     $this->installSchema('user',[]);
+    $this->installEntitySchema('node');
+    $this->installEntitySchema('user');
     $this->installConfig(['node', 'user']);
+
     $this->entityTypeId = 'node';
     $this->bundle = $this->createContentType(['type' => 'event']);
 
@@ -53,7 +56,7 @@ class IcalKernelTest extends KernelTestBase {
       'field_name' => 'field_event_date',
       'type' => 'datetime',
       'entity_type' => $this->entityTypeId,
-      'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME],
+      'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATE],
     ]);
     $this->fieldStorage->save();
     $this->field = FieldConfig::create([
@@ -64,15 +67,8 @@ class IcalKernelTest extends KernelTestBase {
       ],
     ]);
     $this->field->save();
-
-
   }
 
-  /**
-   * Tests the construction of Ical.
-   *
-   * @covers ::__construct
-   */
   public function testCreate() {
     /** @var \Drupal\migrate\Plugin\MigratePluginManagerInterface $migrationSourceManager */
     $migrationSourceManager = $this->container->get('plugin.manager.migrate.source');
@@ -83,11 +79,11 @@ class IcalKernelTest extends KernelTestBase {
    *
    */
   public function testSourcePlugin() {
-    // @todo Create a test json input.
+    $calendar = $this->getModulePath('migrate_source_ical') . '/tests/calendar.ics';
     $definition = [
       'source' => [
         'plugin' => 'ical',
-        'path' => 'http://l.d11/sites/default/files/calendar.ics',
+        'path' => $calendar,
         'identifier' => 'upc',
         'identifierDepth' => 1,
         'ids' => [
@@ -96,20 +92,22 @@ class IcalKernelTest extends KernelTestBase {
         'fields' => [
           'uid' => 'UID',
           'dtstart' => 'Date Start',
+          'summary' => 'Summary',
         ],
       ],
       'process' => [
-        'title' => 'title',
-        'field_event_date/value' => [
-          'plugin' => 'format_date',
-          'from_format' => 'YmdTHisZ',
-          'to_format' => 'Y-m-d',
-          'source' => 'dtstart',
+        'title' => 'summary',
+        'field_event_date' => [
+          'value' => [
+            'plugin' => 'ical_format_date',
+            'to_format' => 'Y-m-d',
+            'source' => 'dtstart',
+          ]
         ]
       ],
       'destination' => [
         'plugin' => 'entity:node',
-        'default_bundle' => 'article',
+        'default_bundle' => 'event',
       ],
     ];
 
@@ -122,9 +120,18 @@ class IcalKernelTest extends KernelTestBase {
 
     /** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map_plugin */
     $id_map_plugin = $migration->getIdMap();
-    $map_row = $id_map_plugin->getRowBySource(['title' => 'about-us']);
-//    $this->assertEquals(MigrateIdMapInterface::STATUS_FAILED, $map_row['source_row_status']);
+    // Check if date is properly stored in the event field.
+    $map_row = $id_map_plugin->getRowBySource(['uid' => 'ical_event01']);
+    $this->assertNotNull($map_row['destid1']);
+    $node1 = $this->container->get('entity_type.manager')->getStorage('node')
+      ->load($map_row['destid1']);
+    $this->assertEquals('2024-12-09', $node1->field_event_date->value);
+
+    $map_row = $id_map_plugin->getRowBySource(['uid' => 'ical_event02']);
     $this->assertNotNull($map_row['destid1']);
+    $node2 = $this->container->get('entity_type.manager')->getStorage('node')
+      ->load($map_row['destid1']);
+    $this->assertEquals('2025-03-24', $node2->field_event_date->value);
   }
 
 }
-- 
GitLab


From 271a06d0911be72337c53b971f706bd4de4a204c Mon Sep 17 00:00:00 2001
From: Gautam Das <9498-das.gautam27@users.noreply.drupalcode.org>
Date: Fri, 14 Mar 2025 14:19:57 +0000
Subject: [PATCH 3/5] Add gitlab ci file

---
 .gitlab-ci.yml | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 .gitlab-ci.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..c6cd69a
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,29 @@
+################
+# GitLabCI template for Drupal projects.
+#
+# This template is designed to give any Contrib maintainer everything they need to test, without requiring modification.
+# It is also designed to keep up to date with Core Development automatically through the use of include files that can be centrally maintained.
+# As long as you include the project, ref and three files below, any future updates added by the Drupal Association will be used in your
+# pipelines automatically. However, you can modify this template if you have additional needs for your project.
+# The full documentation is on https://project.pages.drupalcode.org/gitlab_templates/
+################
+
+# For information on alternative values for 'ref' see https://project.pages.drupalcode.org/gitlab_templates/info/templates-version/
+# To test a Drupal 7 project, change the first include filename from .main.yml to .main-d7.yml
+include:
+  - project: $_GITLAB_TEMPLATES_REPO
+    ref: $_GITLAB_TEMPLATES_REF
+    file:
+      - '/includes/include.drupalci.main.yml'
+      - '/includes/include.drupalci.variables.yml'
+      - '/includes/include.drupalci.workflows.yml'
+#
+################
+# Pipeline configuration variables are defined with default values and descriptions in the file
+# https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml
+# Uncomment the lines below if you want to override any of the variables. The following is just an example.
+################
+# variables:
+#   SKIP_ESLINT: '1'
+#   OPT_IN_TEST_NEXT_MAJOR: '1'
+#   _CURL_TEMPLATES_REF: 'main'
-- 
GitLab


From 0bceb7c7c30c74aadb36b3e0977486bc5bf3c9aa Mon Sep 17 00:00:00 2001
From: hs-gautam <gautam@genero.jp>
Date: Fri, 14 Mar 2025 20:10:14 +0530
Subject: [PATCH 4/5] #Issue 3297668: Fix phpcs errors.

---
 src/Plugin/migrate/IcalReader.php             | 104 ++----------------
 src/Plugin/migrate/process/IcalFormatDate.php |  19 ++--
 src/Plugin/migrate/source/Ical.php            |  22 ++--
 .../Plugin/migrate/source/IcalKernelTest.php  |  55 +++++++--
 4 files changed, 71 insertions(+), 129 deletions(-)

diff --git a/src/Plugin/migrate/IcalReader.php b/src/Plugin/migrate/IcalReader.php
index 64bc070..0201bd2 100644
--- a/src/Plugin/migrate/IcalReader.php
+++ b/src/Plugin/migrate/IcalReader.php
@@ -1,88 +1,5 @@
 <?php
 
-/**
- * @file
- * Contains Drupal\migrate_source_json\Plugin\migrate\JSONReader.
- *
- * This reader can traverse multidimensional arrays and retrieve results
- * by locating subarrays that contain a known identifier field at a known depth.
- * It can locate id fields that are nested in the results and pull out all other
- * content that is at the same level. If that content contains additional nested
- * arrays or needs other manipulation, extend this class and massage the data further
- * in the getSourceFields() method.
- *
- * For example, a file that adheres to the JSON API might look like this:
- *
- Array
-(
-    [DTSTART] => DateTime Object
-        (
-            [date] => 2015-10-13 10:30:00.000000
-            [timezone_type] => 3
-            [timezone] => Asia/Calcutta
-        )
-
-    [DTEND] => DateTime Object
-        (
-            [date] => 2015-10-13 11:00:00.000000
-            [timezone_type] => 3
-            [timezone] => Asia/Calcutta
-        )
-
-    [RRULE] => Array
-        (
-            [FREQ] => WEEKLY
-            [UNTIL] => DateTime Object
-                (
-                    [date] => 2015-11-13 05:00:00.000000
-                    [timezone_type] => 2
-                    [timezone] => Z
-                )
-
-            [BYDAY] => MO,TU,WE,TH,FR
-        )
-
-    [DTSTAMP] => DateTime Object
-        (
-            [date] => 2017-09-22 12:02:14.000000
-            [timezone_type] => 2
-            [timezone] => Z
-        )
-
-    [ORGANIZER] => mailto:nvhsa43nhis4uqjiec7u9ceqa0@group.calendar.google.com
-    [UID] => 59m3jpl5vasf9q7ao22m3frc9o@google.com
-    [ATTENDEE] => mailto:gdgautamd5@gmail.com
-    [CREATED] => DateTime Object
-        (
-            [date] => 2015-10-08 02:26:35.000000
-            [timezone_type] => 2
-            [timezone] => Z
-        )
-
-    [DESCRIPTION] =>
-    [LAST-MODIFIED] => DateTime Object
-        (
-            [date] => 2015-11-20 07:51:34.000000
-            [timezone_type] => 2
-            [timezone] => Z
-        )
-
-    [LOCATION] =>
-    [SEQUENCE] => 1
-    [STATUS] => CONFIRMED
-    [SUMMARY] => Scrum Meeting
-    [TRANSP] => OPAQUE
-    [0] =>
-    [RECURRING] => 1
-)
- *
- * In the above example, the id field and the value1 field would be transformed
- * to top-level key/value pairs, as required by Migrate. The value2 field,
- * if needed, might require further manipulation by extending this class.
- *
- * @see http://php.net/manual/en/class.recursiveiteratoriterator.php
- */
-
 namespace Drupal\migrate_source_ical\Plugin\migrate;
 
 use Drupal\migrate\MigrateException;
@@ -95,7 +12,7 @@ use ICal\ICal;
 class IcalReader {
 
   /**
-   * The HTTP Client
+   * The HTTP Client.
    *
    * @var JSONClientInterface resource
    */
@@ -109,7 +26,7 @@ class IcalReader {
   protected $headers = [];
 
   /**
-   * Source configuration
+   * Source configuration.
    *
    * @var array
    */
@@ -164,30 +81,29 @@ class IcalReader {
    * Return the identifier for this JSON source.
    */
   public function getIdentifier() {
-    return isset($this->identifier) ? $this->identifier : '';
+    return $this->identifier ?? '';
   }
 
   /**
    * Return the identifier depth for this JSON source.
    */
   public function getIdentifierDepth() {
-    return isset($this->identifierDepth) ? $this->identifierDepth : NULL;
+    return $this->identifierDepth ?? NULL;
   }
 
   /**
    * {@inheritdoc}
-   * Fetch all fields.
    */
   public function getSourceFields($url) {
 
     $iterator = $this->getSourceData($url);
 
     // Recurse through the result array. When there is an array of items at the
-    // expected depth that has the expected identifier as one of the keys, pull that
-    // array out as a distinct item.
+    // expected depth that has the expected identifier as one of the keys,
+    // pull that array out as a distinct item.
     // $identifier = $this->getIdentifier();
     // $identifierDepth = $this->getIdentifierDepth();
-    $items = array();
+    $items = [];
     while ($iterator->valid()) {
       $iterator->next();
       $item = $iterator->current();
@@ -201,7 +117,6 @@ class IcalReader {
 
   /**
    * {@inheritdoc}
-   * Process the fields
    */
   public function getSourceFieldsIterator($url) {
     return $this->getSourceFields($url);
@@ -214,6 +129,7 @@ class IcalReader {
    *   The URL to read the source data from.
    *
    * @return \RecursiveIteratorIterator|resource
+   *   Returns a resource.
    *
    * @throws \Drupal\migrate\MigrateException
    */
@@ -227,8 +143,10 @@ class IcalReader {
       // Each object returns and event array.
       $obj = new \ArrayIterator($response);
       return $obj;
-    } catch (RequestException $e) {
+    }
+    catch (RequestException $e) {
       throw new MigrateException($e->getMessage(), $e->getCode(), $e);
     }
   }
+
 }
diff --git a/src/Plugin/migrate/process/IcalFormatDate.php b/src/Plugin/migrate/process/IcalFormatDate.php
index cc38d33..5564ab8 100644
--- a/src/Plugin/migrate/process/IcalFormatDate.php
+++ b/src/Plugin/migrate/process/IcalFormatDate.php
@@ -3,10 +3,7 @@
 namespace Drupal\migrate_source_ical\Plugin\migrate\process;
 
 use Drupal\migrate\Plugin\migrate\process\FormatDate;
-use Drupal\Component\Datetime\DateTimePlus;
-use Drupal\migrate\MigrateException;
 use Drupal\migrate\MigrateExecutableInterface;
-use Drupal\migrate\ProcessPluginBase;
 use Drupal\migrate\Row;
 
 /**
@@ -78,14 +75,14 @@ class IcalFormatDate extends FormatDate {
   }
 
   /**
-  * Determine the date format to use for the input string.
-  *
-  * @param string $value
-  *  The source string that is being imported.
-  *
-  * @return string
-  *  The date format to use, using standard PHP notation; defaults to 'Ymd'.
-  */
+   * Determine the date format to use for the input string.
+   *
+   * @param string $value
+   *   The source string that is being imported.
+   *
+   * @return string
+   *   The date format to use, using standard PHP notation; defaults to 'Ymd'.
+   */
   private function determineFromFormat($value) {
     $length = strlen($value);
 
diff --git a/src/Plugin/migrate/source/Ical.php b/src/Plugin/migrate/source/Ical.php
index 16fe700..c69db5e 100644
--- a/src/Plugin/migrate/source/Ical.php
+++ b/src/Plugin/migrate/source/Ical.php
@@ -56,6 +56,12 @@ class Ical extends SourcePluginBase {
    */
   protected $reader;
 
+  /**
+   * List of ids in source settings.
+   *
+   * @var array
+   */
+  protected $ids = [];
 
   /**
    * {@inheritdoc}
@@ -81,29 +87,19 @@ class Ical extends SourcePluginBase {
       }
     }
 
-    // @todo
     $this->readerClass = !isset($configuration['readerClass']) ? '\Drupal\migrate_source_ical\Plugin\migrate\IcalReader' : $configuration['readerClass'];
 
-    // Create the ICAL reader that will process the request, and pass it configuration.
+    // Create the ICAL reader that will process the request,
+    // and pass it configuration.
     $this->reader = new $this->readerClass($configuration);
 
   }
 
-  /**
-   * Return a count of all available source records.
-   *
-   * @return int
-   *   The number of available source records.
-   */
-  public function _count($url): int {
-    return count($this->reader->getSourceFields($url));
-  }
-
   /**
    * {@inheritdoc}
    */
   public function count($refresh = FALSE): int {
-    return $this->_count($this->path);
+    return count($this->reader->getSourceFields($this->path));
   }
 
   /**
diff --git a/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php b/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php
index 4377fab..685c5ed 100644
--- a/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php
+++ b/tests/src/Kernel/Plugin/migrate/source/IcalKernelTest.php
@@ -8,6 +8,7 @@ use Drupal\field\Entity\FieldStorageConfig;
 use Drupal\KernelTests\KernelTestBase;
 use Drupal\migrate\MigrateExecutable;
 use Drupal\migrate\Plugin\MigrationInterface;
+use Drupal\node\Entity\NodeType;
 use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
 
 /**
@@ -19,14 +20,38 @@ class IcalKernelTest extends KernelTestBase {
 
   use ContentTypeCreationTrait;
 
-  protected $bundle;
+  /**
+   * Node type i.e event.
+   *
+   * @var \Drupal\node\Entity\NodeType
+   */
+  protected NodeType $bundle;
 
-  protected $entityTypeId;
+  /**
+   * Node entity type.
+   *
+   * @var string
+   */
+  protected string $entityTypeId;
+
+  /**
+   * A field storage to use in this test class.
+   *
+   * @var \Drupal\field\Entity\FieldStorageConfig
+   */
+  protected $fieldStorage;
+
+  /**
+   * The field used in this test class.
+   *
+   * @var \Drupal\field\Entity\FieldConfig
+   */
+  protected $field;
 
   /**
    * {@inheritdoc}
    */
-  public static $modules = [
+  protected static $modules = [
     'migrate',
     'migrate_source_ical',
     'node',
@@ -37,13 +62,16 @@ class IcalKernelTest extends KernelTestBase {
     'datetime',
   ];
 
+  /**
+   * {@inheritdoc}
+   */
   public function setUp(): void {
     parent::setUp();
-    $this->installSchema('node',[]);
-    $this->installSchema('user',[]);
-    $this->installSchema('system',[]);
-    $this->installSchema('field',[]);
-    $this->installSchema('user',[]);
+    $this->installSchema('node', []);
+    $this->installSchema('user', []);
+    $this->installSchema('system', []);
+    $this->installSchema('field', []);
+    $this->installSchema('user', []);
     $this->installEntitySchema('node');
     $this->installEntitySchema('user');
     $this->installConfig(['node', 'user']);
@@ -69,14 +97,17 @@ class IcalKernelTest extends KernelTestBase {
     $this->field->save();
   }
 
-  public function testCreate() {
+  /**
+   * Tests if source plugin exists.
+   */
+  public function testSourcePluginExists() {
     /** @var \Drupal\migrate\Plugin\MigratePluginManagerInterface $migrationSourceManager */
     $migrationSourceManager = $this->container->get('plugin.manager.migrate.source');
     $this->assertTrue($migrationSourceManager->hasDefinition('ical'));
   }
 
   /**
-   *
+   * Tests if source data is converted into entities.
    */
   public function testSourcePlugin() {
     $calendar = $this->getModulePath('migrate_source_ical') . '/tests/calendar.ics';
@@ -102,8 +133,8 @@ class IcalKernelTest extends KernelTestBase {
             'plugin' => 'ical_format_date',
             'to_format' => 'Y-m-d',
             'source' => 'dtstart',
-          ]
-        ]
+          ],
+        ],
       ],
       'destination' => [
         'plugin' => 'entity:node',
-- 
GitLab


From b35fdc3c3dab1d2fd33283059f3059e8eae00f5e Mon Sep 17 00:00:00 2001
From: hs-gautam <gautam@genero.jp>
Date: Fri, 14 Mar 2025 20:27:16 +0530
Subject: [PATCH 5/5] #Issue 3297668: Fix phpcs and cspell errors.

---
 .gitlab-ci.yml             | 3 ++-
 migrate_source_ical.module | 1 -
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c6cd69a..edb6f20 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -23,7 +23,8 @@ include:
 # https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.variables.yml
 # Uncomment the lines below if you want to override any of the variables. The following is just an example.
 ################
-# variables:
+variables:
+  _CSPELL_IGNORE_PATHS: 'tests/*, README.md'
 #   SKIP_ESLINT: '1'
 #   OPT_IN_TEST_NEXT_MAJOR: '1'
 #   _CURL_TEMPLATES_REF: 'main'
diff --git a/migrate_source_ical.module b/migrate_source_ical.module
index 6f4ce7d..8a4c455 100644
--- a/migrate_source_ical.module
+++ b/migrate_source_ical.module
@@ -6,7 +6,6 @@
  */
 
 use Drupal\Core\Routing\RouteMatchInterface;
-use Drupal\node\Entity\Node;
 
 /**
  * Implements hook_help().
-- 
GitLab