diff --git a/composer.json b/composer.json index c66ec428ac35087cc9932887185ee651084fe68d..ab6f58eab75b66c28353826651ec3b27589b6e24 100644 --- a/composer.json +++ b/composer.json @@ -30,14 +30,8 @@ "config": { "preferred-install": "dist" }, - "require-dev": { - "drush/drush": "^10" - }, - "extra": { - "drush": { - "services": { - "drush.services.yml": "^9 || ^10" - } - } + "require": { + "php": ">=7.4", + "drupal/core": ">=9.1" } } diff --git a/migrate_example/migrate_example.info.yml b/migrate_example/migrate_example.info.yml index 55dd3f9d3a565a09874e36586ddcbf121231ac2b..44abfc03107e103cb03c875bed90c2bfc3d6bc61 100644 --- a/migrate_example/migrate_example.info.yml +++ b/migrate_example/migrate_example.info.yml @@ -2,7 +2,7 @@ type: module name: Migrate Example description: 'Examples of how Drupal 8+ migration compares to previous versions.' package: Examples -core_version_requirement: ^8.8 || ^9 +core_version_requirement: '>=9.1' dependencies: - drupal:migrate - migrate_plus:migrate_example_setup diff --git a/migrate_example/migrate_example_setup/migrate_example_setup.info.yml b/migrate_example/migrate_example_setup/migrate_example_setup.info.yml index 9734cd2d4dd293a160ac4b8b1c491fbbbd791ecf..29e47829783d62636a184c9341721bf80162b6ee 100644 --- a/migrate_example/migrate_example_setup/migrate_example_setup.info.yml +++ b/migrate_example/migrate_example_setup/migrate_example_setup.info.yml @@ -2,7 +2,7 @@ type: module name: Migrate Example Setup description: 'Separate site configuration for the example from the actual migration.' package: Migration -core_version_requirement: ^8.8 || ^9 +core_version_requirement: '>=9.1' hidden: true dependencies: - drupal:comment diff --git a/migrate_example/migrate_example_setup/migrate_example_setup.install b/migrate_example/migrate_example_setup/migrate_example_setup.install index 58b9c63853c89d6f27c0240511cda80dc436217a..89ea528726b2ad1986c2ad2df9d798d7b9e95ecf 100644 --- a/migrate_example/migrate_example_setup/migrate_example_setup.install +++ b/migrate_example/migrate_example_setup/migrate_example_setup.install @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + /** * @file * Install file for migrate example module. @@ -12,7 +14,8 @@ /** * Implements hook_schema(). */ -function migrate_example_setup_schema() { +function migrate_example_setup_schema(): array { + $schema = []; $schema['migrate_example_beer_account'] = migrate_example_beer_schema_account(); $schema['migrate_example_beer_node'] = migrate_example_beer_schema_node(); $schema['migrate_example_beer_comment'] = migrate_example_beer_schema_comment(); @@ -25,7 +28,7 @@ function migrate_example_setup_schema() { /** * Implements hook_install(). */ -function migrate_example_setup_install() { +function migrate_example_setup_install(): void { // Populate our tables. migrate_example_beer_data_account(); migrate_example_beer_data_node(); @@ -37,10 +40,9 @@ function migrate_example_setup_install() { /** * The hook_schema definition for node. * - * @return array * The schema definition. */ -function migrate_example_beer_schema_node() { +function migrate_example_beer_schema_node(): array { return [ 'description' => 'Beers of the world.', 'fields' => [ @@ -109,10 +111,9 @@ function migrate_example_beer_schema_node() { /** * The hook_schema definition for topic. * - * @return array * The schema definition. */ -function migrate_example_beer_schema_topic() { +function migrate_example_beer_schema_topic(): array { return [ 'description' => 'Categories', 'fields' => [ @@ -152,10 +153,9 @@ function migrate_example_beer_schema_topic() { /** * The hook_schema definition for topic node. * - * @return array * The schema definition. */ -function migrate_example_beer_schema_topic_node() { +function migrate_example_beer_schema_topic_node(): array { return [ 'description' => 'Beers topic pairs.', 'fields' => [ @@ -178,10 +178,9 @@ function migrate_example_beer_schema_topic_node() { /** * The hook_schema definition for comment. * - * @return array * The schema definition. */ -function migrate_example_beer_schema_comment() { +function migrate_example_beer_schema_comment(): array { return [ 'description' => 'Beers comments.', 'fields' => [ @@ -237,10 +236,9 @@ function migrate_example_beer_schema_comment() { /** * The hook_schema definition for account. * - * @return array * The schema definition. */ -function migrate_example_beer_schema_account() { +function migrate_example_beer_schema_account(): array { return [ 'description' => 'Beers accounts.', 'fields' => [ @@ -303,7 +301,7 @@ function migrate_example_beer_schema_account() { /** * Populate node table. */ -function migrate_example_beer_data_node() { +function migrate_example_beer_data_node(): void { $fields = [ 'bid', 'name', @@ -372,7 +370,7 @@ function migrate_example_beer_data_node() { * * @todo Duplicate email also. */ -function migrate_example_beer_data_account() { +function migrate_example_beer_data_account(): void { $fields = [ 'status', 'registered', @@ -436,7 +434,7 @@ function migrate_example_beer_data_account() { /** * Populate comment table. */ -function migrate_example_beer_data_comment() { +function migrate_example_beer_data_comment(): void { $fields = ['bid', 'cid_parent', 'subject', 'body', 'name', 'mail', 'aid']; $query = \Drupal::database()->insert('migrate_example_beer_comment') ->fields($fields); @@ -464,7 +462,7 @@ function migrate_example_beer_data_comment() { /** * Populate topic table. */ -function migrate_example_beer_data_topic() { +function migrate_example_beer_data_topic(): void { $fields = ['style', 'details', 'style_parent', 'region', 'hoppiness']; $query = \Drupal::database()->insert('migrate_example_beer_topic') ->fields($fields); @@ -488,7 +486,7 @@ function migrate_example_beer_data_topic() { /** * Populate topic node table. */ -function migrate_example_beer_data_topic_node() { +function migrate_example_beer_data_topic_node(): void { $fields = ['bid', 'style']; $query = \Drupal::database()->insert('migrate_example_beer_topic_node') ->fields($fields); diff --git a/migrate_example/src/Plugin/migrate/source/BeerComment.php b/migrate_example/src/Plugin/migrate/source/BeerComment.php index b5d446a3ffccb3180da51aef75e6c9c4ff071ca8..91b55d5df21edffe11ba13b016f3f3df92aace06 100644 --- a/migrate_example/src/Plugin/migrate/source/BeerComment.php +++ b/migrate_example/src/Plugin/migrate/source/BeerComment.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_example\Plugin\migrate\source; +use Drupal\Core\Database\Query\SelectInterface; use Drupal\migrate\Plugin\migrate\source\SqlBase; /** @@ -11,12 +14,12 @@ use Drupal\migrate\Plugin\migrate\source\SqlBase; * id = "beer_comment" * ) */ -class BeerComment extends SqlBase { +final class BeerComment extends SqlBase { /** * {@inheritdoc} */ - public function query() { + public function query(): SelectInterface { $fields = [ 'cid', 'cid_parent', @@ -27,17 +30,16 @@ class BeerComment extends SqlBase { 'bid', 'subject', ]; - $query = $this->select('migrate_example_beer_comment', 'mec') + return $this->select('migrate_example_beer_comment', 'mec') ->fields('mec', $fields) ->orderBy('cid_parent', 'ASC'); - return $query; } /** * {@inheritdoc} */ - public function fields() { - $fields = [ + public function fields(): array { + return [ 'cid' => $this->t('Comment ID'), 'cid_parent' => $this->t('Parent comment ID in case of comment replies'), 'name' => $this->t('Comment name (if anon)'), @@ -46,14 +48,12 @@ class BeerComment extends SqlBase { 'bid' => $this->t('Beer ID that is being commented upon'), 'subject' => $this->t('Comment subject'), ]; - - return $fields; } /** * {@inheritdoc} */ - public function getIds() { + public function getIds(): array { return [ 'cid' => [ 'type' => 'integer', diff --git a/migrate_example/src/Plugin/migrate/source/BeerNode.php b/migrate_example/src/Plugin/migrate/source/BeerNode.php index 40ac4df29d36bca6950880ce39437fce0891ad1a..07a4a975e80c49b09c11180f6c6a880ffaeee255 100644 --- a/migrate_example/src/Plugin/migrate/source/BeerNode.php +++ b/migrate_example/src/Plugin/migrate/source/BeerNode.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_example\Plugin\migrate\source; +use Drupal\Core\Database\Query\SelectInterface; use Drupal\migrate\Plugin\migrate\source\SqlBase; use Drupal\migrate\Row; @@ -12,12 +15,12 @@ use Drupal\migrate\Row; * id = "beer_node" * ) */ -class BeerNode extends SqlBase { +final class BeerNode extends SqlBase { /** * {@inheritdoc} */ - public function query() { + public function query(): SelectInterface { // An important point to note is that your query *must* return a single row // for each item to be imported. Here we might be tempted to add a join to // migrate_example_beer_topic_node in our query, to pull in the @@ -39,16 +42,15 @@ class BeerNode extends SqlBase { 'image_title', 'image_description', ]; - $query = $this->select('migrate_example_beer_node', 'b') + return $this->select('migrate_example_beer_node', 'b') ->fields('b', $fields); - return $query; } /** * {@inheritdoc} */ - public function fields() { - $fields = [ + public function fields(): array { + return [ 'bid' => $this->t('Beer ID'), 'name' => $this->t('Name of beer'), 'body' => $this->t('Full description of the beer'), @@ -64,14 +66,12 @@ class BeerNode extends SqlBase { // are available for mapping after prepareRow() is called. 'terms' => $this->t('Applicable styles'), ]; - - return $fields; } /** * {@inheritdoc} */ - public function getIds() { + public function getIds(): array { return [ 'bid' => [ 'type' => 'integer', @@ -83,7 +83,7 @@ class BeerNode extends SqlBase { /** * {@inheritdoc} */ - public function prepareRow(Row $row) { + public function prepareRow(Row $row): bool { // As explained above, we need to pull the style relationships into our // source row here, as an array of 'style' values (the unique ID for // the beer_term migration). diff --git a/migrate_example/src/Plugin/migrate/source/BeerTerm.php b/migrate_example/src/Plugin/migrate/source/BeerTerm.php index 5eb3e70f30abf158b38f5f844653b04ef107bb16..7c9269683f0196d87a5a3c413d747f88847c4afe 100644 --- a/migrate_example/src/Plugin/migrate/source/BeerTerm.php +++ b/migrate_example/src/Plugin/migrate/source/BeerTerm.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_example\Plugin\migrate\source; +use Drupal\Core\Database\Query\SelectInterface; use Drupal\migrate\Plugin\migrate\source\SqlBase; /** @@ -20,12 +23,12 @@ use Drupal\migrate\Plugin\migrate\source\SqlBase; * id = "beer_term" * ) */ -class BeerTerm extends SqlBase { +final class BeerTerm extends SqlBase { /** * {@inheritdoc} */ - public function query() { + public function query(): SelectInterface { // The most important part of a SQL source plugin is the SQL query to // retrieve the data to be imported. Note that the query is not executed // here - the migration process will control execution of the query. Also @@ -42,12 +45,12 @@ class BeerTerm extends SqlBase { /** * {@inheritdoc} */ - public function fields() { + public function fields(): array { // This method simply documents the available source fields provided by the // source plugin, for use by front-end tools. It returns an array keyed by // field/column name, with the value being a translated string explaining // to humans what the field represents. - $fields = [ + return [ 'style' => $this->t('Beer style'), 'details' => $this->t('Style details'), 'style_parent' => $this->t('Parent style'), @@ -56,14 +59,12 @@ class BeerTerm extends SqlBase { 'region' => $this->t('Region the style is associated with'), 'hoppiness' => $this->t('Hoppiness of the style'), ]; - - return $fields; } /** * {@inheritdoc} */ - public function getIds() { + public function getIds(): array { // This method indicates what field(s) from the source row uniquely identify // that source row, and what their types are. This is critical information // for managing the migration. The keys of the returned array are the field diff --git a/migrate_example/src/Plugin/migrate/source/BeerUser.php b/migrate_example/src/Plugin/migrate/source/BeerUser.php index 398f87c6963fcfe8220b7cd2e09d24aa73c823e4..0992034e504f5e758d4b781b7ed4ef158216bf3c 100644 --- a/migrate_example/src/Plugin/migrate/source/BeerUser.php +++ b/migrate_example/src/Plugin/migrate/source/BeerUser.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_example\Plugin\migrate\source; +use Drupal\Core\Database\Query\SelectInterface; use Drupal\migrate\Plugin\migrate\source\SqlBase; use Drupal\migrate\Row; @@ -12,12 +15,12 @@ use Drupal\migrate\Row; * id = "beer_user" * ) */ -class BeerUser extends SqlBase { +final class BeerUser extends SqlBase { /** * {@inheritdoc} */ - public function query() { + public function query(): SelectInterface { $fields = [ 'aid', 'status', @@ -36,8 +39,8 @@ class BeerUser extends SqlBase { /** * {@inheritdoc} */ - public function fields() { - $fields = [ + public function fields(): array { + return [ 'aid' => $this->t('Account ID'), 'status' => $this->t('Blocked/Allowed'), 'registered' => $this->t('Registered date'), @@ -48,14 +51,12 @@ class BeerUser extends SqlBase { 'sex' => $this->t('Gender'), 'beers' => $this->t('Favorite beers, pipe-separated'), ]; - - return $fields; } /** * {@inheritdoc} */ - public function getIds() { + public function getIds(): array { return [ 'aid' => [ 'type' => 'integer', @@ -67,7 +68,7 @@ class BeerUser extends SqlBase { /** * {@inheritdoc} */ - public function prepareRow(Row $row) { + public function prepareRow(Row $row): bool { // A prepareRow() is the most common place to perform custom run-time // processing that isn't handled by an existing process plugin. It is called // when the raw data has been pulled from the source, and provides the diff --git a/migrate_example/tests/src/Kernel/MigrateExampleTest.php b/migrate_example/tests/src/Kernel/MigrateExampleTest.php index 677d6d52b56f637fc626b482d80d8f7c2a1460f0..c9b6a143683c1f3f5b6edfe1417ed073df76f126 100755 --- a/migrate_example/tests/src/Kernel/MigrateExampleTest.php +++ b/migrate_example/tests/src/Kernel/MigrateExampleTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_example\Kernel; use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase; @@ -9,7 +11,7 @@ use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase; * * @group migrate_plus */ -class MigrateExampleTest extends MigrateDrupalTestBase { +final class MigrateExampleTest extends MigrateDrupalTestBase { /** * {@inheritdoc} @@ -55,7 +57,7 @@ class MigrateExampleTest extends MigrateDrupalTestBase { /** * Tests the results of "Beer" example migration. */ - public function testBeerMigration() { + public function testBeerMigration(): void { $users = \Drupal::entityTypeManager()->getStorage('user')->loadMultiple(); // There are 4 users created in beer_user migration and 1 stub entity // created during beer_node migration. diff --git a/migrate_example_advanced/migrate_example_advanced.info.yml b/migrate_example_advanced/migrate_example_advanced.info.yml index e170b33bbe3c43bd24d1c22d4b498e7037417a89..d607a0c166feb9c0e4320f9b4b8ad2eb63577c51 100644 --- a/migrate_example_advanced/migrate_example_advanced.info.yml +++ b/migrate_example_advanced/migrate_example_advanced.info.yml @@ -2,7 +2,7 @@ type: module name: Migrate Example (Advanced) description: 'Specialized examples of Drupal 8+ migration.' package: Examples -core_version_requirement: ^8.8 || ^9 +core_version_requirement: '>=9.1' dependencies: - drupal:migrate - migrate_plus:migrate_example_advanced_setup diff --git a/migrate_example_advanced/migrate_example_advanced.install b/migrate_example_advanced/migrate_example_advanced.install index 2023bdee16be8ba07e0d9e21610eff8261773dea..a772817f50ad62961aadb90414663fda10e87d2c 100644 --- a/migrate_example_advanced/migrate_example_advanced.install +++ b/migrate_example_advanced/migrate_example_advanced.install @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + /** * @file * Install, update and uninstall functions for migrate_example_advanced module. @@ -15,7 +17,7 @@ use Drupal\migrate_plus\Entity\Migration; * use. So, in the .yml files we provide the REST resources relative to the * site root and here rewrite them to fully-qualified paths. */ -function migrate_example_advanced_install() { +function migrate_example_advanced_install(): void { /** @var \Drupal\migrate_plus\Entity\MigrationInterface $wine_role_xml_migration */ $wine_role_xml_migration = Migration::load('wine_role_xml'); if ($wine_role_xml_migration) { diff --git a/migrate_example_advanced/migrate_example_advanced_setup/migrate_example_advanced_setup.info.yml b/migrate_example_advanced/migrate_example_advanced_setup/migrate_example_advanced_setup.info.yml index acf626e923afc89cf5a2bf97009092e91cb9ce9b..ace30441228a540f01e9bf16e22d100222c365dd 100644 --- a/migrate_example_advanced/migrate_example_advanced_setup/migrate_example_advanced_setup.info.yml +++ b/migrate_example_advanced/migrate_example_advanced_setup/migrate_example_advanced_setup.info.yml @@ -2,7 +2,7 @@ type: module name: Migrate Advanced Example Setup description: 'Separate site configuration for the example from the actual migration.' package: Migration -core_version_requirement: ^8.8 || ^9 +core_version_requirement: '>=9.1' hidden: true dependencies: - drupal:comment diff --git a/migrate_example_advanced/migrate_example_advanced_setup/migrate_example_advanced_setup.install b/migrate_example_advanced/migrate_example_advanced_setup/migrate_example_advanced_setup.install index 6fd5f7926c46cff2ede66e687dd4f1532cd1b62b..d1bebb9eabc6adb05982f8ab3681c017dd4e5dab 100644 --- a/migrate_example_advanced/migrate_example_advanced_setup/migrate_example_advanced_setup.install +++ b/migrate_example_advanced/migrate_example_advanced_setup/migrate_example_advanced_setup.install @@ -12,7 +12,8 @@ /** * Implements hook_schema(). */ -function migrate_example_advanced_setup_schema() { +function migrate_example_advanced_setup_schema(): array { + $schema = []; $schema['migrate_example_advanced_account'] = migrate_example_advanced_schema_account(); $schema['migrate_example_advanced_account_updates'] = migrate_example_advanced_schema_account_updates(); $schema['migrate_example_advanced_categories'] = migrate_example_advanced_schema_categories(); @@ -36,7 +37,7 @@ function migrate_example_advanced_setup_schema() { /** * Implements hook_install(). */ -function migrate_example_advanced_setup_install() { +function migrate_example_advanced_setup_install(): void { // Populate our tables. migrate_example_advanced_data_account(); migrate_example_advanced_data_account_updates(); @@ -61,7 +62,7 @@ function migrate_example_advanced_setup_install() { * @return array * The schema definition. */ -function migrate_example_advanced_schema_wine() { +function migrate_example_advanced_schema_wine(): array { return [ 'description' => 'Wines of the world', 'fields' => [ @@ -135,7 +136,7 @@ function migrate_example_advanced_schema_wine() { * @return array * The schema definition. */ -function migrate_example_advanced_schema_updates() { +function migrate_example_advanced_schema_updates(): array { return [ 'description' => 'Updated wine ratings', 'fields' => [ @@ -162,7 +163,7 @@ function migrate_example_advanced_schema_updates() { * @return array * The schema definition. */ -function migrate_example_advanced_schema_producer() { +function migrate_example_advanced_schema_producer(): array { return [ 'description' => 'Wine producers of the world', 'fields' => [ @@ -203,10 +204,9 @@ function migrate_example_advanced_schema_producer() { /** * The hook_schema definition for categories. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_categories() { +function migrate_example_advanced_schema_categories(): array { return [ 'description' => 'Categories', 'fields' => [ @@ -252,10 +252,9 @@ function migrate_example_advanced_schema_categories() { /** * The hook_schema definition for vintages. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_vintages() { +function migrate_example_advanced_schema_vintages(): array { return [ 'description' => 'Wine vintages', 'fields' => [ @@ -278,10 +277,9 @@ function migrate_example_advanced_schema_vintages() { /** * The hook_schema definition for variety updates. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_variety_updates() { +function migrate_example_advanced_schema_variety_updates(): array { return [ 'description' => 'Variety updates', 'fields' => [ @@ -304,10 +302,9 @@ function migrate_example_advanced_schema_variety_updates() { /** * The hook_schema definition for category wine. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_category_wine() { +function migrate_example_advanced_schema_category_wine(): array { return [ 'description' => 'Wine category assignments', 'fields' => [ @@ -330,10 +327,9 @@ function migrate_example_advanced_schema_category_wine() { /** * The hook_schema definition for category producer. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_category_producer() { +function migrate_example_advanced_schema_category_producer(): array { return [ 'description' => 'Producer category assignments', 'fields' => [ @@ -356,10 +352,9 @@ function migrate_example_advanced_schema_category_producer() { /** * The hook_schema definition for comment. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_comment() { +function migrate_example_advanced_schema_comment(): array { return [ 'description' => 'Wine comments', 'fields' => [ @@ -443,10 +438,9 @@ function migrate_example_advanced_schema_comment() { /** * The hook_schema definition for comment updates. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_comment_updates() { +function migrate_example_advanced_schema_comment_updates(): array { return [ 'description' => 'Wine comment updates', 'fields' => [ @@ -470,10 +464,9 @@ function migrate_example_advanced_schema_comment_updates() { /** * The hook_schema definition for account. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_account() { +function migrate_example_advanced_schema_account(): array { return [ 'description' => 'Wine accounts.', 'fields' => [ @@ -561,10 +554,9 @@ function migrate_example_advanced_schema_account() { /** * The hook_schema definition for account updates. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_account_updates() { +function migrate_example_advanced_schema_account_updates(): array { return [ 'description' => 'Wine account updates', 'fields' => [ @@ -587,10 +579,9 @@ function migrate_example_advanced_schema_account_updates() { /** * The hook_schema definition for blobs. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_blobs() { +function migrate_example_advanced_schema_blobs(): array { return [ 'description' => 'Wine blobs to be migrated to file entities', 'fields' => [ @@ -613,10 +604,9 @@ function migrate_example_advanced_schema_blobs() { /** * The hook_schema definition for files. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_files() { +function migrate_example_advanced_schema_files(): array { return [ 'description' => 'Wine and account files', 'fields' => [ @@ -658,10 +648,9 @@ function migrate_example_advanced_schema_files() { /** * The hook_schema definition for table source. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_table_source() { +function migrate_example_advanced_schema_table_source(): array { return [ 'description' => 'Source data to go into a custom Drupal table', 'fields' => [ @@ -691,10 +680,9 @@ function migrate_example_advanced_schema_table_source() { /** * The hook_schema definition for table destination. * - * @return array * The schema definition. */ -function migrate_example_advanced_schema_table_dest() { +function migrate_example_advanced_schema_table_dest(): array { return [ 'description' => 'Custom Drupal table to receive source data directly', 'fields' => [ diff --git a/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/PositionResource.php b/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/PositionResource.php index 20fe34aaddb65b59fbad06d7c34d54a523472e19..cb3a9026428754b4ddb110a24724c213b85820a3 100644 --- a/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/PositionResource.php +++ b/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/PositionResource.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_example_advanced_setup\Plugin\rest\resource; use Drupal\rest\Plugin\ResourceBase; @@ -16,27 +18,25 @@ use Drupal\rest\ResourceResponse; * } * ) */ -class PositionResource extends ResourceBase { +final class PositionResource extends ResourceBase { /** * Responds to GET requests. * - * @return \Drupal\rest\ResourceResponse * The response containing the position data. */ - public function get() { + public function get(): ResourceResponse { $position1 = ['sourceid' => 'wine_taster', 'name' => 'Wine Taster']; $position2 = ['sourceid' => 'vintner', 'name' => 'Vintner']; $data = ['position' => [$position1, $position2]]; - $response = new ResourceResponse($data, 200); - return $response; + return new ResourceResponse($data, 200); } /** * {@inheritdoc} */ - public function permissions() { + public function permissions(): array { // Remove permissions so the resource is available to all. return []; } diff --git a/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyItems.php b/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyItems.php index 670134c3455ad09f897aec759b198581fd0c1ffa..34e4de35dd1ffbd47c44dd4d5d2f5e3d5aa62fdb 100644 --- a/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyItems.php +++ b/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyItems.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_example_advanced_setup\Plugin\rest\resource; use Drupal\rest\Plugin\ResourceBase; @@ -16,18 +18,17 @@ use Drupal\rest\ResourceResponse; * } * ) */ -class VarietyItems extends ResourceBase { +final class VarietyItems extends ResourceBase { /** * Responds to GET requests. * - * @param string $variety + * @param string|null $variety * Machine name of the variety to retrieve. * - * @return \Drupal\rest\ResourceResponse * The response containing the requested variety data. */ - public function get($variety = NULL) { + public function get(?string $variety = NULL): ResourceResponse { $varieties = [ 'retsina' => [ 'name' => 'Retsina', @@ -61,14 +62,13 @@ class VarietyItems extends ResourceBase { $data = []; } - $response = new ResourceResponse($data, 200); - return $response; + return new ResourceResponse($data, 200); } /** * {@inheritdoc} */ - public function permissions() { + public function permissions(): array { // Remove permissions so the resource is available to all. return []; } diff --git a/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyList.php b/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyList.php index bb4bb60cbcc9abf46ef3ac0cca6f9b983576af6f..dbf38fe49c6d564c43729d6aa3af2a1ccb0cf5b6 100644 --- a/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyList.php +++ b/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyList.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_example_advanced_setup\Plugin\rest\resource; use Drupal\rest\Plugin\ResourceBase; @@ -16,25 +18,24 @@ use Drupal\rest\ResourceResponse; * } * ) */ -class VarietyList extends ResourceBase { +final class VarietyList extends ResourceBase { /** * Responds to GET requests. * - * @return \Drupal\rest\ResourceResponse * The response containing the requested variety data. */ - public function get() { + public function get(): ResourceResponse { + $data = []; $data['items'] = ['retsina', 'trebbiano', 'valpolicella', 'bardolino']; - $response = new ResourceResponse($data, 200); - return $response; + return new ResourceResponse($data, 200); } /** * {@inheritdoc} */ - public function permissions() { + public function permissions(): array { // Remove permissions so the resource is available to all. return []; } diff --git a/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyMultiFiles.php b/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyMultiFiles.php index 5db35b5ce848955054a5e2cba7e91d6dec5dbe1d..0020340c13ebb9d2461b6c0b5c845678444d3e60 100644 --- a/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyMultiFiles.php +++ b/migrate_example_advanced/migrate_example_advanced_setup/src/Plugin/rest/resource/VarietyMultiFiles.php @@ -21,13 +21,12 @@ class VarietyMultiFiles extends ResourceBase { /** * Responds to GET requests. * - * @param string $type + * @param string|null $type * 'red', 'white', or NULL to return all varieties. * - * @return \Drupal\rest\ResourceResponse * The response containing the requested variety data. */ - public function get($type = NULL) { + public function get(?string $type = NULL): ResourceResponse { $data = []; if (strtolower($type) != 'white') { $data['variety'][] = [ @@ -72,14 +71,13 @@ class VarietyMultiFiles extends ResourceBase { ]; } - $response = new ResourceResponse($data, 200); - return $response; + return new ResourceResponse($data, 200); } /** * {@inheritdoc} */ - public function permissions() { + public function permissions(): array { // Remove permissions so the resource is available to all. return []; } diff --git a/migrate_example_advanced/src/Plugin/migrate/source/WineTerm.php b/migrate_example_advanced/src/Plugin/migrate/source/WineTerm.php index 3d3d235dd229930ce7b97a355ddb9cc21550e421..b2d37fad4666afc80b6d4fac6b070f47d7cc4079 100644 --- a/migrate_example_advanced/src/Plugin/migrate/source/WineTerm.php +++ b/migrate_example_advanced/src/Plugin/migrate/source/WineTerm.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_example_advanced\Plugin\migrate\source; +use Drupal\Core\Database\Query\SelectInterface; use Drupal\migrate\Plugin\migrate\source\SqlBase; /** @@ -11,12 +14,12 @@ use Drupal\migrate\Plugin\migrate\source\SqlBase; * id = "wine_term" * ) */ -class WineTerm extends SqlBase { +final class WineTerm extends SqlBase { /** * {@inheritdoc} */ - public function query() { + public function query(): SelectInterface { $fields = [ 'categoryid', 'type', @@ -34,8 +37,8 @@ class WineTerm extends SqlBase { /** * {@inheritdoc} */ - public function fields() { - $fields = [ + public function fields(): array { + return [ 'categoryid' => $this->t('Unique ID of the category'), 'type' => $this->t('Category type corresponding to Drupal vocabularies'), 'name' => $this->t('Category name'), @@ -43,14 +46,12 @@ class WineTerm extends SqlBase { 'category_parent' => $this->t('ID of the parent category'), 'ordering' => $this->t('Order in which to display this category'), ]; - - return $fields; } /** * {@inheritdoc} */ - public function getIds() { + public function getIds(): array { return ['categoryid' => ['type' => 'integer']]; } diff --git a/migrate_json_example/migrate_json_example.info.yml b/migrate_json_example/migrate_json_example.info.yml index 00e554d3826cff886cc499cf0719a7a3a7e846a6..f0fdb7087de21331f984ec649ae84dabcbc326b0 100644 --- a/migrate_json_example/migrate_json_example.info.yml +++ b/migrate_json_example/migrate_json_example.info.yml @@ -2,7 +2,7 @@ type: module name: Migrate JSON Example description: 'Simple JSON Migration example' package: Examples -core_version_requirement: ^8.8 || ^9 +core_version_requirement: '>=9.1' dependencies: - drupal:migrate - migrate_plus:migrate_plus diff --git a/migrate_json_example/migrate_json_example.install b/migrate_json_example/migrate_json_example.install index a038a19113e56688d188020dd24b2854b1f24606..b881aaa6b3655ef5b43a2b6f7d6662a4c6570038 100644 --- a/migrate_json_example/migrate_json_example.install +++ b/migrate_json_example/migrate_json_example.install @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + /** * @file * Install, update, and uninstall functions for migrate_json_example. @@ -10,13 +12,13 @@ use Drupal\Core\File\FileSystemInterface; /** * Copies the example file to the sites/default/files folder. */ -function migrate_json_example_install() { +function migrate_json_example_install(): void { // Create the example file directory and ensure it's writable. $directory = \Drupal::config('system.file')->get('default_scheme') . '://migrate_json_example'; \Drupal::service('file_system')->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS); // Copy the example file to example directory. - $module_path = drupal_get_path('module', 'migrate_json_example'); + $module_path = \Drupal::service('extension.list.module')->getPath('migrate_json_example'); $file_source = $module_path . '/artifacts/products.json'; \Drupal::service('file_system')->copy($file_source, $directory . '/products.json', FileSystemInterface::EXISTS_REPLACE); } diff --git a/migrate_json_example/tests/src/Kernel/MigrateJsonExampleTest.php b/migrate_json_example/tests/src/Kernel/MigrateJsonExampleTest.php index 27b89a2a16d9f1a17c51f84b76363c41f4b0d262..d6d3232d8d30e3d33668cdfb760ad18c66d2444f 100755 --- a/migrate_json_example/tests/src/Kernel/MigrateJsonExampleTest.php +++ b/migrate_json_example/tests/src/Kernel/MigrateJsonExampleTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_json_example\Kernel; use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase; @@ -9,7 +11,7 @@ use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase; * * @group migrate_plus */ -class MigrateJsonExampleTest extends MigrateDrupalTestBase { +final class MigrateJsonExampleTest extends MigrateDrupalTestBase { /** * {@inheritdoc} @@ -39,7 +41,7 @@ class MigrateJsonExampleTest extends MigrateDrupalTestBase { /** * Tests the results of "migrate_json_example" migrations. */ - public function testMigrations() { + public function testMigrations(): void { $node_storage = \Drupal::entityTypeManager()->getStorage('node'); $this->assertCount(0, $node_storage->loadMultiple()); // Execute "product" migration from 'migrate_json_example' module. diff --git a/migrate_plus.info.yml b/migrate_plus.info.yml index b447119d9e9b99d4bad683639a4013c60a5ede59..4760fc3b983e9d408aa93233f1c5780ee144d273 100644 --- a/migrate_plus.info.yml +++ b/migrate_plus.info.yml @@ -2,6 +2,7 @@ type: module name: Migrate Plus description: 'Enhancements to core migration support' package: Migration -core_version_requirement: ^9.1 +core_version_requirement: '>=9.1' +php: 7.4 dependencies: - drupal:migrate diff --git a/migrate_plus.install b/migrate_plus.install index 815b9876ea22667176147eb5b2b359d2a05ca377..70b31a7f65ad8a1412f98a8eb60a1f6155e3f6b1 100644 --- a/migrate_plus.install +++ b/migrate_plus.install @@ -8,7 +8,7 @@ /** * Converts 8.0.x core migration entities to 8.1.x migrate_plus entities. */ -function migrate_plus_update_8100() { +function migrate_plus_update_8100(): void { // We cannot use the configration entity system directly, because the entity // type migrate.migration.* no longer exists - we must directly manipulate // the config table. diff --git a/migrate_plus.module b/migrate_plus.module index fdb00df9c8c8d2daa6c97879039820f028f4dd9f..73c86c44a991dafa48b63d0bf0d95b21b4d980ca 100644 --- a/migrate_plus.module +++ b/migrate_plus.module @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + /** * @file * Provides enhancements for implementing and managing migrations. @@ -16,7 +18,7 @@ use Drupal\migrate_plus\Event\MigratePrepareRowEvent; /** * Implements hook_migration_plugins_alter(). */ -function migrate_plus_migration_plugins_alter(array &$migrations) { +function migrate_plus_migration_plugins_alter(array &$migrations): void { foreach (array_keys($migrations) as $id) { // Add the default class where empty. if (empty($migrations[$id]['class'])) { @@ -82,6 +84,6 @@ function migrate_plus_migration_plugins_alter(array &$migrations) { /** * Implements hook_migrate_prepare_row(). */ -function migrate_plus_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) { +function migrate_plus_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration): void { \Drupal::service('event_dispatcher')->dispatch(new MigratePrepareRowEvent($row, $source, $migration), MigrateEvents::PREPARE_ROW); } diff --git a/src/Annotation/Authentication.php b/src/Annotation/Authentication.php index 5b63e1af840c14182b023a2eb44c3388493801ed..fd54a1f0017820a59e28624b92b1fb1665261ca5 100644 --- a/src/Annotation/Authentication.php +++ b/src/Annotation/Authentication.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Annotation; use Drupal\Component\Annotation\Plugin; @@ -20,18 +22,12 @@ class Authentication extends Plugin { /** * The plugin ID. - * - * @var string */ - public $id; + public string $id; /** * The title of the plugin. - * - * @var \Drupal\Core\Annotation\Translation - * - * @ingroup plugin_translatable */ - public $title; + public string $title; } diff --git a/src/Annotation/DataFetcher.php b/src/Annotation/DataFetcher.php index 5c6e24ccb9fb85792ee66d50956d6ff775632cfd..8484fae6b3d4f77a8f81c81fe586dba12d15e7ce 100644 --- a/src/Annotation/DataFetcher.php +++ b/src/Annotation/DataFetcher.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Annotation; use Drupal\Component\Annotation\Plugin; @@ -20,18 +22,12 @@ class DataFetcher extends Plugin { /** * The plugin ID. - * - * @var string */ - public $id; + public string $id; /** * The title of the plugin. - * - * @var \Drupal\Core\Annotation\Translation - * - * @ingroup plugin_translatable */ - public $title; + public string $title; } diff --git a/src/Annotation/DataParser.php b/src/Annotation/DataParser.php index 6bc01e24aab88deacc53599af847d7e01f2f557e..c2fc184e106a20adbe1ca31daa1b7faf5718b1e6 100644 --- a/src/Annotation/DataParser.php +++ b/src/Annotation/DataParser.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Annotation; use Drupal\Component\Annotation\Plugin; @@ -23,15 +25,11 @@ class DataParser extends Plugin { * * @var string */ - public $id; + public string $id; /** * The title of the plugin. - * - * @var \Drupal\Core\Annotation\Translation - * - * @ingroup plugin_translatable */ - public $title; + public string $title; } diff --git a/src/AuthenticationPluginBase.php b/src/AuthenticationPluginBase.php index 8833512acd0042d92751e938cdef328c185f114b..cdbf0cb0f2e1ccf719a50226e4424acf3cdce4cc 100644 --- a/src/AuthenticationPluginBase.php +++ b/src/AuthenticationPluginBase.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus; use Drupal\Core\Plugin\PluginBase; @@ -18,7 +20,7 @@ abstract class AuthenticationPluginBase extends PluginBase implements Authentica /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self { return new static($configuration, $plugin_id, $plugin_definition); } diff --git a/src/AuthenticationPluginInterface.php b/src/AuthenticationPluginInterface.php index 5bdc60309fea04999c2a760eab80c1006e7378a8..f2200357aa51603f97f26ef47c8174e9cb37db5b 100644 --- a/src/AuthenticationPluginInterface.php +++ b/src/AuthenticationPluginInterface.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus; /** @@ -20,6 +22,6 @@ interface AuthenticationPluginInterface { * * @link http://docs.guzzlephp.org/en/latest/request-options.html */ - public function getAuthenticationOptions(); + public function getAuthenticationOptions(): array; } diff --git a/src/AuthenticationPluginManager.php b/src/AuthenticationPluginManager.php index 041094e4d7c4e7c327f22b2eec8ceab006b9f8e4..f18563d7047262ed0128e5e7ae883f02832c380c 100644 --- a/src/AuthenticationPluginManager.php +++ b/src/AuthenticationPluginManager.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus; +use Drupal\migrate_plus\Annotation\Authentication; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; @@ -28,7 +31,7 @@ class AuthenticationPluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/migrate_plus/authentication', $namespaces, $module_handler, 'Drupal\migrate_plus\AuthenticationPluginInterface', 'Drupal\migrate_plus\Annotation\Authentication'); + parent::__construct('Plugin/migrate_plus/authentication', $namespaces, $module_handler, AuthenticationPluginInterface::class, Authentication::class); $this->alterInfo('authentication_info'); $this->setCacheBackend($cache_backend, 'migrate_plus_plugins_authentication'); diff --git a/src/DataFetcherPluginBase.php b/src/DataFetcherPluginBase.php index eb21f301da43f74e05bf93dc8b00ca41627caad8..00850fcee7f12775f042d40e3cf92f3366566393 100644 --- a/src/DataFetcherPluginBase.php +++ b/src/DataFetcherPluginBase.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus; use Drupal\Core\Plugin\PluginBase; @@ -18,7 +20,7 @@ abstract class DataFetcherPluginBase extends PluginBase implements DataFetcherPl /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self { return new static($configuration, $plugin_id, $plugin_definition); } diff --git a/src/DataFetcherPluginInterface.php b/src/DataFetcherPluginInterface.php index f35042fcff88d13476bd96fa2f94b65213ca39d1..b405fd7f42a2c457c10d0e938deb44fa0e4285b5 100644 --- a/src/DataFetcherPluginInterface.php +++ b/src/DataFetcherPluginInterface.php @@ -1,7 +1,11 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus; +use Psr\Http\Message\ResponseInterface; + /** * Defines an interface for data fetchers. * @@ -18,12 +22,12 @@ interface DataFetcherPluginInterface { * @param array $headers * An array of the headers to set on the HTTP request. */ - public function setRequestHeaders(array $headers); + public function setRequestHeaders(array $headers): void; /** * Get the currently set request headers. */ - public function getRequestHeaders(); + public function getRequestHeaders(): array; /** * Return content. @@ -34,7 +38,7 @@ interface DataFetcherPluginInterface { * @return string * Content at the given url. */ - public function getResponseContent($url); + public function getResponseContent(string $url): string; /** * Return Http Response object for a given url. @@ -45,6 +49,6 @@ interface DataFetcherPluginInterface { * @return \Psr\Http\Message\ResponseInterface * The HTTP response message. */ - public function getResponse($url); + public function getResponse(string $url): ResponseInterface; } diff --git a/src/DataFetcherPluginManager.php b/src/DataFetcherPluginManager.php index 941252ed71c824e7c8ddda7ebaec24485cc87291..84f2e703549ba44cfab001a146bf0d17ec7d73bf 100644 --- a/src/DataFetcherPluginManager.php +++ b/src/DataFetcherPluginManager.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus; +use Drupal\migrate_plus\Annotation\DataFetcher; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; @@ -28,7 +31,7 @@ class DataFetcherPluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/migrate_plus/data_fetcher', $namespaces, $module_handler, 'Drupal\migrate_plus\DataFetcherPluginInterface', 'Drupal\migrate_plus\Annotation\DataFetcher'); + parent::__construct('Plugin/migrate_plus/data_fetcher', $namespaces, $module_handler, DataFetcherPluginInterface::class, DataFetcher::class); $this->alterInfo('data_fetcher_info'); $this->setCacheBackend($cache_backend, 'migrate_plus_plugins_data_fetcher'); diff --git a/src/DataParserPluginBase.php b/src/DataParserPluginBase.php index 7d187f31ddc662c203e5307225edd23da0dc0c82..c94e20d3c22519d0a255b50ad51b6af16b1474cc 100644 --- a/src/DataParserPluginBase.php +++ b/src/DataParserPluginBase.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus; use Drupal\Core\Plugin\PluginBase; @@ -20,19 +22,17 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug * * @var string[] */ - protected $urls; + protected ?array $urls; /** * Index of the currently-open url. - * - * @var int */ - protected $activeUrl; + protected ?int $activeUrl = NULL; /** * String indicating how to select an item's data from the source. * - * @var string + * @var string|int */ protected $itemSelector; @@ -45,17 +45,13 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug /** * Value of the ID for the current item when iterating. - * - * @var string */ - protected $currentId = NULL; + protected ?array $currentId = NULL; /** * The data retrieval client. - * - * @var \Drupal\migrate_plus\DataFetcherPluginInterface */ - protected $dataFetcher; + protected DataFetcherPluginInterface $dataFetcher; /** * {@inheritdoc} @@ -69,17 +65,14 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self { return new static($configuration, $plugin_id, $plugin_definition); } /** * Returns the initialized data fetcher plugin. - * - * @return \Drupal\migrate_plus\DataFetcherPluginInterface - * The data fetcher plugin. */ - public function getDataFetcherPlugin() { + public function getDataFetcherPlugin(): DataFetcherPluginInterface { if (!isset($this->dataFetcher)) { $this->dataFetcher = \Drupal::service('plugin.manager.migrate_plus.data_fetcher')->createInstance($this->configuration['data_fetcher_plugin'], $this->configuration); } @@ -89,15 +82,15 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug /** * {@inheritdoc} */ - public function rewind() { + public function rewind(): void { $this->activeUrl = NULL; $this->next(); } /** - * Implementation of Iterator::next(). + * {@inheritdoc} */ - public function next() { + public function next(): void { $this->currentItem = $this->currentId = NULL; if (is_null($this->activeUrl)) { if (!$this->nextSource()) { @@ -129,26 +122,18 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug * * @param string $url * URL to open. - * - * @return bool - * TRUE if the URL was successfully opened, FALSE otherwise. */ - abstract protected function openSourceUrl($url); + abstract protected function openSourceUrl(string $url): bool; /** * Retrieves the next row of data. populating currentItem. - * - * Retrieves from the open source URL. */ - abstract protected function fetchNextRow(); + abstract protected function fetchNextRow(): void; /** * Advances the data parser to the next source url. - * - * @return bool - * TRUE if a valid source URL was opened */ - protected function nextSource() { + protected function nextSource(): bool { if (empty($this->urls)) { return FALSE; } @@ -177,6 +162,7 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug /** * {@inheritdoc} */ + #[\ReturnTypeWillChange] public function current() { return $this->currentItem; } @@ -193,26 +179,22 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug /** * {@inheritdoc} */ - public function key() { + public function key(): ?array { return $this->currentId; } /** * {@inheritdoc} */ - public function valid() { + public function valid(): bool { return !empty($this->currentItem); } /** * {@inheritdoc} */ - public function count() { - $count = 0; - foreach ($this as $item) { - $count++; - } - return $count; + public function count(): int { + return iterator_count($this); } /** @@ -221,7 +203,7 @@ abstract class DataParserPluginBase extends PluginBase implements DataParserPlug * @return string[] * Array of selectors, keyed by field name. */ - protected function fieldSelectors() { + protected function fieldSelectors(): array { $fields = []; foreach ($this->configuration['fields'] as $field_info) { if (isset($field_info['selector'])) { diff --git a/src/DataParserPluginInterface.php b/src/DataParserPluginInterface.php index fb6ed69ba31312a162e3816651473c3b16563b4b..b99861273d9c119a139552f77304a8c427e3d935 100644 --- a/src/DataParserPluginInterface.php +++ b/src/DataParserPluginInterface.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus; /** diff --git a/src/DataParserPluginManager.php b/src/DataParserPluginManager.php index 65d92b1b71eb388712041236471fe30021cfa134..564dcdd9a3f843c0f495c60487b9d1c47422b412 100644 --- a/src/DataParserPluginManager.php +++ b/src/DataParserPluginManager.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus; +use Drupal\migrate_plus\Annotation\DataParser; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; @@ -28,7 +31,7 @@ class DataParserPluginManager extends DefaultPluginManager { * The module handler to invoke the alter hook with. */ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { - parent::__construct('Plugin/migrate_plus/data_parser', $namespaces, $module_handler, 'Drupal\migrate_plus\DataParserPluginInterface', 'Drupal\migrate_plus\Annotation\DataParser'); + parent::__construct('Plugin/migrate_plus/data_parser', $namespaces, $module_handler, DataParserPluginInterface::class, DataParser::class); $this->alterInfo('data_parser_info'); $this->setCacheBackend($cache_backend, 'migrate_plus_plugins_data_parser'); diff --git a/src/Entity/Migration.php b/src/Entity/Migration.php index c5a04d2ac80c388787b7c612efd43fd05837289f..f4e7416727839a072bb99745bc729b66d6145a2d 100644 --- a/src/Entity/Migration.php +++ b/src/Entity/Migration.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Entity; use Drupal\Core\Cache\Cache; @@ -41,22 +43,18 @@ class Migration extends ConfigEntityBase implements MigrationInterface { /** * The migration ID (machine name). - * - * @var string */ - protected $id; + protected ?string $id; /** * The human-readable label for the migration. - * - * @var string */ - protected $label; + protected ?string $label; /** * {@inheritdoc} */ - protected function invalidateTagsOnSave($update) { + protected function invalidateTagsOnSave($update): void { parent::invalidateTagsOnSave($update); Cache::invalidateTags(['migration_plugins']); } @@ -64,7 +62,7 @@ class Migration extends ConfigEntityBase implements MigrationInterface { /** * {@inheritdoc} */ - protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities) { + protected static function invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities): void { parent::invalidateTagsOnDelete($entity_type, $entities); Cache::invalidateTags(['migration_plugins']); } @@ -81,10 +79,11 @@ class Migration extends ConfigEntityBase implements MigrationInterface { * @param string $new_plugin_id * ID to use for the new configuration entity. * - * @return \Drupal\migrate_plus\Entity\MigrationInterface * A Migration configuration entity (not saved to persistent storage). */ - public static function createEntityFromPlugin($plugin_id, $new_plugin_id) { + public static function createEntityFromPlugin($plugin_id, $new_plugin_id): self { + $entity_array = []; + $migration_details = []; /** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager */ $plugin_manager = \Drupal::service('plugin.manager.migration'); /** @var \Drupal\migrate\Plugin\Migration $migration_plugin */ diff --git a/src/Entity/MigrationGroup.php b/src/Entity/MigrationGroup.php index ac936d7a643d8b3df4137179be3a1818816466ff..62e6eb98f283d1d5e146ab7fa73e4bedc308f9e1 100644 --- a/src/Entity/MigrationGroup.php +++ b/src/Entity/MigrationGroup.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Entity; use Drupal\Core\Cache\Cache; @@ -35,22 +37,18 @@ class MigrationGroup extends ConfigEntityBase implements MigrationGroupInterface /** * The migration group ID (machine name). - * - * @var string */ - protected $id; + protected ?string $id; /** * The human-readable label for the migration group. - * - * @var string */ - protected $label; + protected ?string $label; /** * {@inheritdoc} */ - public function delete() { + public function delete(): void { // Delete all migrations contained in this group. $query = \Drupal::entityQuery('migration') // Access check false because if the user has access to deleting @@ -77,7 +75,7 @@ class MigrationGroup extends ConfigEntityBase implements MigrationGroupInterface /** * {@inheritdoc} */ - public function calculateDependencies() { + public function calculateDependencies(): array { parent::calculateDependencies(); // Make sure we save any explicit module dependencies. if ($provider = $this->get('module')) { @@ -86,10 +84,10 @@ class MigrationGroup extends ConfigEntityBase implements MigrationGroupInterface return $this->dependencies; } - /** + /** * {@inheritdoc} */ - protected function invalidateTagsOnSave($update) { + protected function invalidateTagsOnSave($update): void { parent::invalidateTagsOnSave($update); Cache::invalidateTags(['migration_plugins']); } diff --git a/src/Entity/MigrationGroupInterface.php b/src/Entity/MigrationGroupInterface.php index 9dde2f2e4aca6cd357eaf632ec25c9af6b7c747b..7cf559f01d32f125c0bca59f527c34568171fb51 100644 --- a/src/Entity/MigrationGroupInterface.php +++ b/src/Entity/MigrationGroupInterface.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Entity; use Drupal\Core\Config\Entity\ConfigEntityInterface; @@ -7,6 +9,4 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; /** * Interface for migration groups. */ -interface MigrationGroupInterface extends ConfigEntityInterface { - -} +interface MigrationGroupInterface extends ConfigEntityInterface {} diff --git a/src/Entity/MigrationInterface.php b/src/Entity/MigrationInterface.php index e70b7e244f59ca9587e86775a0cdc02098e9e6f4..1ecfc69bc6ccbef1bff2717433d104df5fea9734 100644 --- a/src/Entity/MigrationInterface.php +++ b/src/Entity/MigrationInterface.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Entity; use Drupal\Core\Config\Entity\ConfigEntityInterface; @@ -7,6 +9,4 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; /** * Interface for migrations. */ -interface MigrationInterface extends ConfigEntityInterface { - -} +interface MigrationInterface extends ConfigEntityInterface {} diff --git a/src/Event/MigrateEvents.php b/src/Event/MigrateEvents.php index 4d9904bb6eb0ae0b875fa450a845fa00a43d54a8..115ff840fa99e3efcc366a9c0d16b58f1a7d36cf 100644 --- a/src/Event/MigrateEvents.php +++ b/src/Event/MigrateEvents.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Event; /** @@ -25,7 +27,7 @@ final class MigrateEvents { * * @var string */ - const PREPARE_ROW = 'migrate_plus.prepare_row'; + public const PREPARE_ROW = 'migrate_plus.prepare_row'; /** * Name of the event fired when a source item is missing. @@ -38,6 +40,6 @@ final class MigrateEvents { * * @see \Drupal\migrate\Event\MigrateRowDeleteEvent */ - const MISSING_SOURCE_ITEM = 'migrate_plus.missing_source_item'; + public const MISSING_SOURCE_ITEM = 'migrate_plus.missing_source_item'; } diff --git a/src/Event/MigratePrepareRowEvent.php b/src/Event/MigratePrepareRowEvent.php index 7972cb7a3c7f8f56b445fa9749b0078bab2db130..f55f79b02a11d2527f9c52bd17892593588e1d66 100644 --- a/src/Event/MigratePrepareRowEvent.php +++ b/src/Event/MigratePrepareRowEvent.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Event; use Drupal\migrate\Plugin\MigrateSourceInterface; @@ -12,26 +14,9 @@ use Symfony\Contracts\EventDispatcher\Event; */ class MigratePrepareRowEvent extends Event { - /** - * Row object. - * - * @var \Drupal\migrate\Row - */ - protected $row; - - /** - * Migration source plugin. - * - * @var \Drupal\migrate\Plugin\MigrateSourceInterface - */ - protected $source; - - /** - * Migration plugin. - * - * @var \Drupal\migrate\Plugin\MigrationInterface - */ - protected $migration; + protected Row $row; + protected MigrateSourceInterface $source; + protected MigrationInterface $migration; /** * Constructs a prepare-row event object. @@ -51,31 +36,22 @@ class MigratePrepareRowEvent extends Event { /** * Gets the row object. - * - * @return \Drupal\migrate\Row - * The row object about to be imported. */ - public function getRow() { + public function getRow(): Row { return $this->row; } /** * Gets the source plugin. - * - * @return \Drupal\migrate\Plugin\MigrateSourceInterface - * The source plugin firing the event. */ - public function getSource() { + public function getSource(): MigrateSourceInterface { return $this->source; } /** * Gets the migration plugin. - * - * @return \Drupal\migrate\Plugin\MigrationInterface - * The migration entity being imported. */ - public function getMigration() { + public function getMigration(): MigrationInterface { return $this->migration; } diff --git a/src/Plugin/MigrationConfigDeriver.php b/src/Plugin/MigrationConfigDeriver.php index d66892128881e6b5db6124e22f2192938ce12185..b8d5f8595dc80a6e4b7cccc58672d4cda7888912 100644 --- a/src/Plugin/MigrationConfigDeriver.php +++ b/src/Plugin/MigrationConfigDeriver.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin; use Drupal\Component\Plugin\Derivative\DeriverBase; @@ -13,7 +15,7 @@ class MigrationConfigDeriver extends DeriverBase { /** * {@inheritdoc} */ - public function getDerivativeDefinitions($base_plugin_definition) { + public function getDerivativeDefinitions($base_plugin_definition): array { // Always rederive from scratch, because changes may have been made without // clearing our internal cache. $this->derivatives = []; diff --git a/src/Plugin/migrate/destination/Table.php b/src/Plugin/migrate/destination/Table.php index 00d24159e8f2a0379ef943aa465a48c693fafa85..87424b4b75ef261fd490228f2bfca794eb27982b 100755 --- a/src/Plugin/migrate/destination/Table.php +++ b/src/Plugin/migrate/destination/Table.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\destination; use Drupal\Core\Database\Connection; @@ -74,52 +76,39 @@ class Table extends DestinationBase implements ContainerFactoryPluginInterface, /** * The name of the destination table. - * - * @var string */ - protected $tableName; + protected string $tableName; /** * IDMap compatible array of id fields. - * - * @var array */ - protected $idFields; + protected array $idFields; /** * Array of fields present on the destination table. - * - * @var array */ - protected $fields; + protected array $fields; - /** - * The database connection. - * - * @var \Drupal\Core\Database\Connection - */ - protected $dbConnection; + protected Connection $dbConnection; /** * Maximum number of rows to insert in one query. - * - * @var int */ - protected $batchSize; + protected int $batchSize = 1; /** * The query object being built row-by-row. * * @var array */ - protected $rowsToInsert = []; + protected array $rowsToInsert = []; /** * The highest ID seen or created so far on this table. * * @var int */ - protected $lastId = 0; + protected int $lastId = 0; /** * Constructs a new Table. @@ -140,15 +129,15 @@ class Table extends DestinationBase implements ContainerFactoryPluginInterface, $this->dbConnection = $connection; $this->tableName = $configuration['table_name']; $this->idFields = $configuration['id_fields']; - $this->fields = isset($configuration['fields']) ? $configuration['fields'] : []; - $this->batchSize = isset($configuration['batch_size']) ? $configuration['batch_size'] : 1; + $this->fields = $configuration['fields'] ?? []; + $this->batchSize = $configuration['batch_size'] ?? 1; $this->supportsRollback = TRUE; } /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL): self { $db_key = !empty($configuration['database_key']) ? $configuration['database_key'] : NULL; return new static( $configuration, @@ -162,7 +151,7 @@ class Table extends DestinationBase implements ContainerFactoryPluginInterface, /** * {@inheritdoc} */ - public function getIds() { + public function getIds(): array { if (empty($this->idFields)) { throw new MigrateException('Id fields are required for a table destination'); } @@ -172,7 +161,7 @@ class Table extends DestinationBase implements ContainerFactoryPluginInterface, /** * {@inheritdoc} */ - public function fields(MigrationInterface $migration = NULL) { + public function fields(MigrationInterface $migration = NULL): array { return $this->fields; } @@ -211,8 +200,10 @@ class Table extends DestinationBase implements ContainerFactoryPluginInterface, $values = []; if ($batch_inserts) { $destination_properties = array_keys($this->migration->getProcess()); - $destination_properties = array_merge($destination_properties, - array_keys($this->idFields)); + $destination_properties = [ + ...$destination_properties, + ...array_keys($this->idFields), + ]; sort($destination_properties); $destination_values = $row->getDestination(); foreach ($destination_properties as $property_name) { @@ -252,13 +243,13 @@ class Table extends DestinationBase implements ContainerFactoryPluginInterface, ->fields($values) ->execute(); } - return $status ? $ids : NULL; + return $status ? $ids : FALSE; } /** * {@inheritdoc} */ - public function rollback(array $destination_identifier) { + public function rollback(array $destination_identifier): void { $delete = $this->dbConnection->delete($this->tableName); foreach ($destination_identifier as $field => $value) { $delete->condition($field, $value); @@ -269,7 +260,7 @@ class Table extends DestinationBase implements ContainerFactoryPluginInterface, /** * Execute the insert query and reset everything. */ - public function flushInserts() { + public function flushInserts(): void { if (count($this->rowsToInsert) > 0) { $batch_query = $this->dbConnection->insert($this->tableName) ->fields(array_keys($this->rowsToInsert[0])); @@ -286,13 +277,13 @@ class Table extends DestinationBase implements ContainerFactoryPluginInterface, /** * {@inheritDoc} */ - public function preImport(MigrateImportEvent $event) { + public function preImport(MigrateImportEvent $event): void { } /** * {@inheritDoc} */ - public function postImport(MigrateImportEvent $event) { + public function postImport(MigrateImportEvent $event): void { // At the conclusion of a given migration, make sure batched inserts go in. $this->flushInserts(); } diff --git a/src/Plugin/migrate/process/ArrayPop.php b/src/Plugin/migrate/process/ArrayPop.php index d4749caff3e006962d4c9770dd5a89507baeff61..e5af28d1aa34cbbcaf0a921a61efd60a62f040e9 100644 --- a/src/Plugin/migrate/process/ArrayPop.php +++ b/src/Plugin/migrate/process/ArrayPop.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\migrate\MigrateException; diff --git a/src/Plugin/migrate/process/ArrayShift.php b/src/Plugin/migrate/process/ArrayShift.php index 02ef190b56f8bff914f05260f5ca0e4beb6f9b0b..af80c4b4b379411f79fa154be5c45ecc0f6e8f92 100644 --- a/src/Plugin/migrate/process/ArrayShift.php +++ b/src/Plugin/migrate/process/ArrayShift.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\migrate\MigrateException; diff --git a/src/Plugin/migrate/process/DefaultEntityValue.php b/src/Plugin/migrate/process/DefaultEntityValue.php index 78ef4cadd4682870074038db276e237c1b305392..d7a584b914b4477b88fe93d33b4f8f7122999203 100644 --- a/src/Plugin/migrate/process/DefaultEntityValue.php +++ b/src/Plugin/migrate/process/DefaultEntityValue.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\migrate\MigrateExecutableInterface; diff --git a/src/Plugin/migrate/process/Dom.php b/src/Plugin/migrate/process/Dom.php index 1d1c50fbb766d0b4e5e9cbae88b2bddb307eb7d1..ca538a61b11f64f87cc901a5b956fad71aa3fee4 100644 --- a/src/Plugin/migrate/process/Dom.php +++ b/src/Plugin/migrate/process/Dom.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\Component\Utility\Html; @@ -75,17 +77,13 @@ class Dom extends ProcessPluginBase { /** * If parsing warnings should be logged as migrate messages. - * - * @var bool */ - protected $logMessages = TRUE; + protected bool $logMessages = TRUE; /** * The HTML contains only the piece inside the body element. - * - * @var bool */ - protected $nonRoot = TRUE; + protected bool $nonRoot = TRUE; /** * {@inheritdoc} @@ -106,11 +104,10 @@ class Dom extends ProcessPluginBase { /** * Supply default values of all optional parameters. * - * @return array * An array with keys the optional parameters and values the corresponding * defaults. */ - protected function defaultValues() { + protected function defaultValues(): array { return [ 'non_root' => TRUE, 'log_messages' => TRUE, @@ -138,19 +135,18 @@ class Dom extends ProcessPluginBase { * The destination property currently worked on. This is only used together * with the $row above. * - * @return \DOMDocument * The document object based on the provided string. * * @throws \Drupal\migrate\MigrateException * When the received $value is not a string. */ - public function import($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + public function import($value, MigrateExecutableInterface $migrate_executable, Row $row, string $destination_property): \DOMDocument { if (!is_string($value)) { throw new MigrateException('Cannot import a non-string value.'); } if ($this->logMessages) { - set_error_handler(static function ($errno, $errstr) use ($migrate_executable) { + set_error_handler(static function ($errno, $errstr) use ($migrate_executable): void { $migrate_executable->saveMessage($errstr, MigrationInterface::MESSAGE_WARNING); }); } @@ -193,7 +189,7 @@ class Dom extends ProcessPluginBase { * @throws \Drupal\migrate\MigrateException * When the received $value is not a \DOMDocument. */ - public function export($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + public function export($value, MigrateExecutableInterface $migrate_executable, Row $row, string $destination_property) { if (!$value instanceof \DOMDocument) { $value_description = (gettype($value) == 'object') ? get_class($value) : gettype($value); throw new MigrateException(sprintf('Cannot export a "%s".', $value_description)); @@ -212,7 +208,7 @@ class Dom extends ProcessPluginBase { * A subset of a full html string. For instance the contents of the body * element. */ - protected function getNonRootHtml($partial) { + protected function getNonRootHtml(string $partial): string { $replacements = [ "\n" => '', '!encoding' => strtolower($this->configuration['encoding']), diff --git a/src/Plugin/migrate/process/DomApplyStyles.php b/src/Plugin/migrate/process/DomApplyStyles.php index 995085c4427cf0ffe5face7ddb5e255de7d9c2ab..990caabead8dffbc1646b7d514eb9efb7acc0dff 100644 --- a/src/Plugin/migrate/process/DomApplyStyles.php +++ b/src/Plugin/migrate/process/DomApplyStyles.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; @@ -63,19 +65,12 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class DomApplyStyles extends DomProcessBase implements ContainerFactoryPluginInterface { - /** - * The config factory. - * - * @var \Drupal\Core\Config\ConfigFactory - */ - protected $configFactory; + protected ConfigFactory $configFactory; /** - * Array of styles from the WYSIWYG editor. - * - * @var array + * Styles from the WYSIWYG editor. */ - protected $styles = []; + protected array $styles = []; /** * {@inheritdoc} @@ -91,7 +86,7 @@ class DomApplyStyles extends DomProcessBase implements ContainerFactoryPluginInt /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL): self { return new static( $configuration, $plugin_id, @@ -103,7 +98,7 @@ class DomApplyStyles extends DomProcessBase implements ContainerFactoryPluginInt /** * {@inheritdoc} */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property): \DOMDocument { $this->init($value, $destination_property); foreach ($this->configuration['rules'] as $rule) { @@ -126,7 +121,7 @@ class DomApplyStyles extends DomProcessBase implements ContainerFactoryPluginInt * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ - protected function setStyles($format) { + protected function setStyles($format): void { if (empty($format) || !is_string($format)) { $message = 'The "format" option must be a non-empty string.'; throw new InvalidPluginDefinitionException($this->getPluginId(), $message); @@ -146,7 +141,7 @@ class DomApplyStyles extends DomProcessBase implements ContainerFactoryPluginInt * * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException */ - protected function validateRules() { + protected function validateRules(): void { if (!array_key_exists('rules', $this->configuration) || !is_array($this->configuration['rules'])) { $message = 'The "rules" option must be an array.'; throw new InvalidPluginDefinitionException($this->getPluginId(), $message); @@ -173,7 +168,7 @@ class DomApplyStyles extends DomProcessBase implements ContainerFactoryPluginInt * @param string[] $rule * An array with keys 'xpath', 'style', and (optional) 'depth'. */ - protected function apply(array $rule) { + protected function apply(array $rule): void { // An entry in $this->styles has the format element(\.class)*: for example, // 'p' or 'a.button' or 'div.col-xs-6.col-md-4'. // @see setStyles() diff --git a/src/Plugin/migrate/process/DomMigrationLookup.php b/src/Plugin/migrate/process/DomMigrationLookup.php index fa68d175f6e43da7fc4f5f46bdec267106f82e16..e9ceda10328e637d8d8cb2294da02eab6a3afad6 100644 --- a/src/Plugin/migrate/process/DomMigrationLookup.php +++ b/src/Plugin/migrate/process/DomMigrationLookup.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; @@ -67,28 +69,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class DomMigrationLookup extends DomStrReplace implements ContainerFactoryPluginInterface { - /** - * The migration to be executed. - * - * @var \Drupal\migrate\Plugin\MigrationInterface - */ - protected $migration; - - /** - * The process plugin manager. - * - * @var \Drupal\migrate\Plugin\MigratePluginManagerInterface - */ - protected $processPluginManager; + protected MigrationInterface $migration; + protected MigratePluginManagerInterface $processPluginManager; /** * Parameters passed to transform method, except the first, value. * * This helps to pass values to another process plugin. - * - * @var array */ - protected $transformParameters; + protected array $transformParameters = []; /** * {@inheritdoc} @@ -118,7 +107,7 @@ class DomMigrationLookup extends DomStrReplace implements ContainerFactoryPlugin ); } // Add missing values if possible. - $default_replace = isset($this->configuration['replace']) ? $this->configuration['replace'] : NULL; + $default_replace = $this->configuration['replace'] ?? NULL; foreach ($this->configuration['migrations'] as $migration_name => $configuration_item) { if (!empty($configuration_item['replace'])) { continue; @@ -136,7 +125,7 @@ class DomMigrationLookup extends DomStrReplace implements ContainerFactoryPlugin /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL): self { return new static( $configuration, $plugin_id, @@ -149,7 +138,7 @@ class DomMigrationLookup extends DomStrReplace implements ContainerFactoryPlugin /** * {@inheritdoc} */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property): \DOMDocument { $this->init($value, $destination_property); $this->transformParameters = [ 'migrate_executable' => $migrate_executable, @@ -188,7 +177,7 @@ class DomMigrationLookup extends DomStrReplace implements ContainerFactoryPlugin /** * {@inheritdoc} */ - protected function doReplace(\DOMElement $html_node, $search, $replace, $subject) { + protected function doReplace(\DOMElement $html_node, $search, $replace, $subject): void { $new_subject = preg_replace($search, $replace, $subject); $this->postReplace($html_node, $new_subject); } @@ -204,7 +193,7 @@ class DomMigrationLookup extends DomStrReplace implements ContainerFactoryPlugin * @return string|null * The found mapped ID, or NULL if not found on the provided migration. */ - protected function migrationLookup($id, $migration_name) { + protected function migrationLookup($id, $migration_name): ?string { $mapped_id = NULL; $parameters = [ $id, diff --git a/src/Plugin/migrate/process/DomProcessBase.php b/src/Plugin/migrate/process/DomProcessBase.php index 05981ba54a44e12a43a9ea2474bfa6332ddfa6df..8ebb4931a51191885397e9a4c584b9b62a2cdb61 100644 --- a/src/Plugin/migrate/process/DomProcessBase.php +++ b/src/Plugin/migrate/process/DomProcessBase.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\migrate\MigrateSkipRowException; @@ -14,19 +16,8 @@ use Drupal\migrate\ProcessPluginBase; */ abstract class DomProcessBase extends ProcessPluginBase { - /** - * Document to use. - * - * @var \DOMDocument - */ - protected $document; - - /** - * Xpath query object. - * - * @var \DOMXPath - */ - protected $xpath; + protected ?\DOMDocument $document = NULL; + protected ?\DOMXPath $xpath = NULL; /** * Initialize the class properties. @@ -40,7 +31,7 @@ abstract class DomProcessBase extends ProcessPluginBase { * @throws \Drupal\migrate\MigrateSkipRowException * If $value is not a \DOMDocument object. */ - protected function init($value, $destination_property) { + protected function init($value, string $destination_property) { if (!($value instanceof \DOMDocument)) { $message = sprintf( 'The %s plugin in the %s process pipeline requires a \DOMDocument object. You can use the dom plugin to convert a string to \DOMDocument.', diff --git a/src/Plugin/migrate/process/DomRemove.php b/src/Plugin/migrate/process/DomRemove.php index 63191e5553cc4c36740402a2fc5a1fbbe6b6a4f5..42085998f2e93b2ff5efd638f096c0e240766d84 100644 --- a/src/Plugin/migrate/process/DomRemove.php +++ b/src/Plugin/migrate/process/DomRemove.php @@ -1,10 +1,11 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; -use Drupal\migrate_plus\Plugin\migrate\process\DomProcessBase; /** * Remove nodes from a DOMDocument object. @@ -43,7 +44,7 @@ class DomRemove extends DomProcessBase { /** * {@inheritdoc} */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property): \DOMDocument { $this->init($value, $destination_property); $walking_dead = []; // The PHP docs for removeChild() explain that you need to do this in two diff --git a/src/Plugin/migrate/process/DomSelect.php b/src/Plugin/migrate/process/DomSelect.php index 0df41687377ece063aab6d212fd34f1637c984d6..7c2b80e3a72e1fc5f5ce890e33e6d2d70929d9ce 100644 --- a/src/Plugin/migrate/process/DomSelect.php +++ b/src/Plugin/migrate/process/DomSelect.php @@ -1,10 +1,11 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; -use Drupal\migrate_plus\Plugin\migrate\process\DomProcessBase; /** * Select strings from a DOMDocument object. @@ -39,7 +40,7 @@ class DomSelect extends DomProcessBase { /** * {@inheritdoc} */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property): array { $this->init($value, $destination_property); $values = []; foreach ($this->xpath->query($this->configuration['selector']) as $node) { diff --git a/src/Plugin/migrate/process/DomStrReplace.php b/src/Plugin/migrate/process/DomStrReplace.php index 80c5f8587b065a93e43a2602f8aaf31c3bd25636..c522a5cf0e0e669a6b854c11e36ef7ab17ff8c37 100644 --- a/src/Plugin/migrate/process/DomStrReplace.php +++ b/src/Plugin/migrate/process/DomStrReplace.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; @@ -84,7 +86,7 @@ class DomStrReplace extends DomProcessBase { 'attribute' => [ 'attribute_options' => NULL, ], - 'element' => [] + 'element' => [], ], 'search' => NULL, 'replace' => NULL, @@ -196,10 +198,11 @@ class DomStrReplace extends DomProcessBase { * @return string * The string to use a subject on search. */ - protected function getSubject(\DOMElement $node) { + protected function getSubject(\DOMElement $node): string { switch ($this->configuration['mode']) { case 'attribute': return $node->getAttribute($this->configuration['attribute_options']['name']); + case 'element': return $node->nodeName; } @@ -211,7 +214,7 @@ class DomStrReplace extends DomProcessBase { * @return string * The value to be searched. */ - protected function getSearch() { + protected function getSearch(): string { switch ($this->configuration['mode']) { case 'attribute': case 'element': @@ -225,7 +228,7 @@ class DomStrReplace extends DomProcessBase { * @return string * The value to use for replacement. */ - protected function getReplace() { + protected function getReplace(): string { switch ($this->configuration['mode']) { case 'attribute': case 'element': @@ -245,7 +248,7 @@ class DomStrReplace extends DomProcessBase { * @param string $subject * The string on which to perform the substitution. */ - protected function doReplace(\DOMElement $html_node, $search, $replace, $subject) { + protected function doReplace(\DOMElement $html_node, string $search, string $replace, string $subject): void { if ($this->configuration['regex']) { $function = 'preg_replace'; } @@ -267,11 +270,12 @@ class DomStrReplace extends DomProcessBase { * @param string $new_subject * The new value to use. */ - protected function postReplace(\DOMElement $html_node, $new_subject) { + protected function postReplace(\DOMElement $html_node, string $new_subject): void { switch ($this->configuration['mode']) { case 'attribute': $html_node->setAttribute($this->configuration['attribute_options']['name'], $new_subject); break; + case 'element': $new_node = $this->document->createElement($new_subject); foreach ($html_node->childNodes as $child) { diff --git a/src/Plugin/migrate/process/EntityGenerate.php b/src/Plugin/migrate/process/EntityGenerate.php index ab94bb475d8e0d4618b9df8992331296a7d25880..907007152046d2e7dc4999820276c298dbb5dcc7 100644 --- a/src/Plugin/migrate/process/EntityGenerate.php +++ b/src/Plugin/migrate/process/EntityGenerate.php @@ -1,9 +1,13 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\Component\Utility\NestedArray; use Drupal\migrate\MigrateExecutableInterface; +use Drupal\migrate\Plugin\migrate\process\Get; +use Drupal\migrate\Plugin\MigratePluginManagerInterface; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Row; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -47,38 +51,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class EntityGenerate extends EntityLookup { - /** - * The row from the source to process. - * - * @var \Drupal\migrate\Row - */ - protected $row; - - /** - * The migrate executable. - * - * @var \Drupal\migrate\MigrateExecutableInterface - */ - protected $migrateExecutable; - - /** - * The MigratePluginManager instance. - * - * @var \Drupal\migrate\Plugin\MigratePluginManagerInterface - */ - protected $processPluginManager; - - /** - * The get process plugin instance. - * - * @var \Drupal\migrate\Plugin\migrate\process\Get - */ - protected $getProcessPlugin; + protected ?Row $row = NULL; + protected ?MigrateExecutableInterface $migrateExecutable = NULL; + protected ?MigratePluginManagerInterface $processPluginManager = NULL; + protected ?Get $getProcessPlugin = NULL; /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition, MigrationInterface $migration = NULL) { + public static function create(ContainerInterface $container, array $configuration, $pluginId, $pluginDefinition, MigrationInterface $migration = NULL): self { $instance = parent::create($container, $configuration, $pluginId, $pluginDefinition, $migration); $instance->processPluginManager = $container->get('plugin.manager.migrate.process'); return $instance; @@ -87,11 +68,11 @@ class EntityGenerate extends EntityLookup { /** * {@inheritdoc} */ - public function transform($value, MigrateExecutableInterface $migrateExecutable, Row $row, $destinationProperty) { + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $this->row = $row; - $this->migrateExecutable = $migrateExecutable; + $this->migrateExecutable = $migrate_executable; // Creates an entity if the lookup determines it doesn't exist. - if (!($result = parent::transform($value, $migrateExecutable, $row, $destinationProperty))) { + if (!($result = parent::transform($value, $migrate_executable, $row, $destination_property))) { $result = $this->generateEntity($value); } @@ -127,10 +108,9 @@ class EntityGenerate extends EntityLookup { * @param mixed $value * Primary value to use in creation of the entity. * - * @return array * Entity value array. */ - protected function entity($value) { + protected function entity($value): array { $entity_values = [$this->lookupValueKey => $value]; if ($this->lookupBundleKey) { @@ -139,8 +119,8 @@ class EntityGenerate extends EntityLookup { // Gather any static default values for properties/fields. if (isset($this->configuration['default_values']) && is_array($this->configuration['default_values'])) { - foreach ($this->configuration['default_values'] as $key => $value) { - $entity_values[$key] = $value; + foreach ($this->configuration['default_values'] as $key => $default_value) { + $entity_values[$key] = $default_value; } } // Gather any additional properties/fields. diff --git a/src/Plugin/migrate/process/EntityLookup.php b/src/Plugin/migrate/process/EntityLookup.php index 6b8327cde0fdf50f1fc16dc8344fab886d61070e..f79e9400b1623a4b2d5a00fa8042479aafc39073 100644 --- a/src/Plugin/migrate/process/EntityLookup.php +++ b/src/Plugin/migrate/process/EntityLookup.php @@ -1,8 +1,13 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\Core\Config\Entity\ConfigEntityInterface; +use Drupal\Core\Entity\EntityFieldManagerInterface; +use Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; @@ -76,89 +81,18 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginInterface { - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * The field manager. - * - * @var \Drupal\Core\Entity\EntityFieldManagerInterface - */ - protected $entityFieldManager; - - /** - * The migration. - * - * @var \Drupal\migrate\Plugin\MigrationInterface - */ - protected $migration; - - /** - * The selection plugin. - * - * @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface - */ - protected $selectionPluginManager; - - /** - * The destination type. - * - * @var string - */ - protected $destinationEntityType; - - /** - * The destination bundle. - * - * @var string|bool - */ - protected $destinationBundleKey; - - /** - * The lookup value's key. - * - * @var string - */ - protected $lookupValueKey; - - /** - * The lookup bundle's key. - * - * @var string - */ - protected $lookupBundleKey; - - /** - * The lookup bundle. - * - * @var string - */ - protected $lookupBundle; - - /** - * The lookup entity type. - * - * @var string - */ - protected $lookupEntityType; - - /** - * The destination property or field. - * - * @var string - */ - protected $destinationProperty; - - /** - * The access check flag. - * - * @var string - */ - protected $accessCheck = TRUE; + protected ?EntityTypeManagerInterface $entityTypeManager; + protected EntityFieldManagerInterface $entityFieldManager; + protected MigrationInterface $migration; + protected SelectionPluginManagerInterface $selectionPluginManager; + protected ?string $destinationEntityType; + protected ?string $destinationBundleKey = NULL; + protected ?string $lookupValueKey = NULL; + protected ?string $lookupBundleKey = NULL; + protected ?string $lookupBundle = NULL; + protected ?string $lookupEntityType = NULL; + protected ?string $destinationProperty; + protected bool $accessCheck = TRUE; /** * {@inheritdoc} @@ -182,7 +116,7 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn /** * {@inheritdoc} */ - public function transform($value, MigrateExecutableInterface $migrateExecutable, Row $row, $destinationProperty) { + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { // If the source data is an empty array, return the same. if (gettype($value) === 'array' && count($value) === 0) { return []; @@ -190,11 +124,11 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn // In case of subfields ('field_reference/target_id'), extract the field // name only. - $parts = explode('/', $destinationProperty); - $destinationProperty = reset($parts); - $this->determineLookupProperties($destinationProperty); + $parts = explode('/', $destination_property); + $destination_property = reset($parts); + $this->determineLookupProperties($destination_property); - $this->destinationProperty = isset($this->configuration['destination_field']) ? $this->configuration['destination_field'] : NULL; + $this->destinationProperty = $this->configuration['destination_field'] ?? NULL; return $this->query($value); } @@ -206,9 +140,9 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn * The destination property currently worked on. This is only used together * with the $row above. */ - protected function determineLookupProperties($destinationProperty) { + protected function determineLookupProperties(string $destinationProperty): void { if (isset($this->configuration['access_check'])) { - $this->accessCheck = $this->configuration['access_check']; + $this->accessCheck = (bool) $this->configuration['access_check']; } if (!empty($this->configuration['value_key'])) { $this->lookupValueKey = $this->configuration['value_key']; @@ -325,7 +259,7 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn } if ($multiple && !empty($this->destinationProperty)) { - array_walk($results, function (&$value) { + array_walk($results, function (&$value): void { $value = [$this->destinationProperty => $value]; }); } diff --git a/src/Plugin/migrate/process/EntityValue.php b/src/Plugin/migrate/process/EntityValue.php index 75891b1aa837b86b9afc204f874a70532850bd7f..6bb6cd5974c7051f2a7adead36835bb43a54df03 100644 --- a/src/Plugin/migrate/process/EntityValue.php +++ b/src/Plugin/migrate/process/EntityValue.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; +use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -39,40 +42,15 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class EntityValue extends ProcessPluginBase implements ContainerFactoryPluginInterface { - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * The Field Name. - * - * @var string - */ - protected $fieldName; - - /** - * The langcode reference. False if not configured. - * - * @var string - */ - protected $langCodeRef; - - /** - * The storage for the configured entity type. - * - * @var \Drupal\Core\Entity\EntityStorageInterface|\Drupal\Core\Entity\RevisionableStorageInterface - */ - protected $entityStorage; + protected EntityTypeManagerInterface $entityTypeManager; + protected string $fieldName; + protected ?string $langCodeRef; + protected EntityStorageInterface $entityStorage; /** * Flag indicating whether there are multiple values. - * - * @var bool */ - protected $multiple; + protected ?bool $multiple = NULL; /** * Creates a EntityValue instance. @@ -107,7 +85,7 @@ class EntityValue extends ProcessPluginBase implements ContainerFactoryPluginInt $entity_type = $this->configuration['entity_type']; $this->entityStorage = $this->entityTypeManager->getStorage($entity_type); - $this->langCodeRef = isset($this->configuration['langcode']) ? $this->configuration['langcode'] : NULL; + $this->langCodeRef = $this->configuration['langcode'] ?? NULL; if (empty($this->configuration['field_name'])) { throw new \InvalidArgumentException("'field_name' configuration must be specified for migrate_plus_entity_value process plugin."); @@ -119,7 +97,7 @@ class EntityValue extends ProcessPluginBase implements ContainerFactoryPluginInt /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self { return new static( $configuration, $plugin_id, @@ -131,7 +109,7 @@ class EntityValue extends ProcessPluginBase implements ContainerFactoryPluginInt /** * {@inheritdoc} */ - public function transform($value, MigrateExecutableInterface $migrateExecutable, Row $row, $destinationProperty) { + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { $this->multiple = is_array($value); if (!isset($value)) { return []; @@ -149,10 +127,8 @@ class EntityValue extends ProcessPluginBase implements ContainerFactoryPluginInt $entity = $entity->getUntranslated(); } } - else { - if ($langcode) { - throw new MigrateException('Langcode can only be used with content entities currently.'); - } + elseif ($langcode) { + throw new MigrateException('Langcode can only be used with content entities currently.'); } try { return $entity->get($this->fieldName)->getValue(); @@ -163,15 +139,13 @@ class EntityValue extends ProcessPluginBase implements ContainerFactoryPluginInt } }, $entities); - $return = $this->multiple ? array_values($arrays) : ($arrays ? reset($arrays) : []); - - return $return; + return $this->multiple ? array_values($arrays) : ($arrays ? reset($arrays) : []); } /** * {@inheritdoc} */ - public function multiple() { + public function multiple(): bool { return $this->multiple; } @@ -184,7 +158,7 @@ class EntityValue extends ProcessPluginBase implements ContainerFactoryPluginInt * @return \Drupal\Core\Entity\EntityInterface[] * The entities. */ - protected function loadEntities(array $ids) { + protected function loadEntities(array $ids): array { $entities = $this->entityStorage->loadMultiple($ids); return $entities; } diff --git a/src/Plugin/migrate/process/FileBlob.php b/src/Plugin/migrate/process/FileBlob.php index ed581682008f9104dad4cfce0b5903663f83dc4c..60239df3accfce29f5d06c1f7b2358e06de510a3 100644 --- a/src/Plugin/migrate/process/FileBlob.php +++ b/src/Plugin/migrate/process/FileBlob.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\Core\File\FileSystemInterface; @@ -74,12 +76,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class FileBlob extends ProcessPluginBase implements ContainerFactoryPluginInterface { - /** - * The file system service. - * - * @var \Drupal\Core\File\FileSystemInterface - */ - protected $fileSystem; + protected FileSystemInterface $fileSystem; /** * Constructs a file_blob process plugin. @@ -104,7 +101,7 @@ class FileBlob extends ProcessPluginBase implements ContainerFactoryPluginInterf /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self { return new static( $configuration, $plugin_id, @@ -124,7 +121,7 @@ class FileBlob extends ProcessPluginBase implements ContainerFactoryPluginInterf } [$destination, $blob] = $value; - // Determine if we going to overwrite existing files or not touch them. + // Determine if we are going to overwrite existing files or not touch them. $replace = $this->getOverwriteMode(); // Attempt to save the file to avoid calling file_prepare_directory() any @@ -158,7 +155,7 @@ class FileBlob extends ProcessPluginBase implements ContainerFactoryPluginInterf * @return bool|string * File path on success, FALSE on failure. */ - protected function putFile($destination, $blob, $replace = FileSystemInterface::EXISTS_REPLACE) { + protected function putFile(string $destination, string $blob, int $replace = FileSystemInterface::EXISTS_REPLACE) { $path = $this->fileSystem->getDestinationFilename($destination, $replace); if ($path) { if (file_put_contents($path, $blob)) { @@ -176,11 +173,10 @@ class FileBlob extends ProcessPluginBase implements ContainerFactoryPluginInterf /** * Determines how to handle file conflicts. * - * @return int * Either FileSystemInterface::EXISTS_REPLACE; (default) or * FileSystemInterface::EXISTS_ERROR, depending on the configuration. */ - protected function getOverwriteMode() { + protected function getOverwriteMode(): int { if (isset($this->configuration['reuse']) && !empty($this->configuration['reuse'])) { return FileSystemInterface::EXISTS_ERROR; } @@ -201,9 +197,9 @@ class FileBlob extends ProcessPluginBase implements ContainerFactoryPluginInterf * The directory component of the path or URI, or FALSE if it could not * be determined. */ - protected function getDirectory($uri) { + protected function getDirectory(string $uri) { $dir = $this->fileSystem->dirname($uri); - if (substr($dir, -3) == '://') { + if (substr($dir, -3) === '://') { return $this->fileSystem->realpath($dir); } return $dir; diff --git a/src/Plugin/migrate/process/Gate.php b/src/Plugin/migrate/process/Gate.php index 3a8bdf3a78226ad823569b707352925ec6ff9664..68878518696821303526c1c3f601371a536d51be 100644 --- a/src/Plugin/migrate/process/Gate.php +++ b/src/Plugin/migrate/process/Gate.php @@ -1,8 +1,9 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; -use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\MigrateSkipProcessException; use Drupal\migrate\ProcessPluginBase; diff --git a/src/Plugin/migrate/process/Merge.php b/src/Plugin/migrate/process/Merge.php index e2934925fe083a3736772172aa3b88f84833cea6..1ccd6d28a88ef80cb5a3fb154cf2045019d42f34 100644 --- a/src/Plugin/migrate/process/Merge.php +++ b/src/Plugin/migrate/process/Merge.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\migrate\MigrateException; @@ -51,7 +53,7 @@ class Merge extends ProcessPluginBase { /** * {@inheritdoc} */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property): array { if (!is_array($value)) { throw new MigrateException(sprintf('Merge process failed for destination property (%s): input is not an array.', $destination_property)); } diff --git a/src/Plugin/migrate/process/MultipleValues.php b/src/Plugin/migrate/process/MultipleValues.php index be6779a124fcf78a5bfe2684b81b1c152f3d8f9a..8e782b67a7afa4cb5b7e500fbc6bf129d6bff047 100644 --- a/src/Plugin/migrate/process/MultipleValues.php +++ b/src/Plugin/migrate/process/MultipleValues.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\migrate\MigrateExecutableInterface; @@ -51,7 +53,7 @@ class MultipleValues extends ProcessPluginBase { /** * {@inheritdoc} */ - public function multiple() { + public function multiple(): bool { return TRUE; } diff --git a/src/Plugin/migrate/process/Service.php b/src/Plugin/migrate/process/Service.php index 51fec0ff0b3bf553d887e38af0dacf9dc80be7ce..009d4258c30d4c20020949e7438ac9a5aa4c8473 100644 --- a/src/Plugin/migrate/process/Service.php +++ b/src/Plugin/migrate/process/Service.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -55,7 +57,7 @@ class Service extends Callback implements ContainerFactoryPluginInterface { /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self { if (!isset($configuration['service'])) { throw new \InvalidArgumentException('The "service" must be set.'); } diff --git a/src/Plugin/migrate/process/SingleValue.php b/src/Plugin/migrate/process/SingleValue.php index 2583a9026cb709ab0078c6d48a722cb1d8c79b8e..e24954995f1638e1a1b42a6841d93d269ca1605c 100644 --- a/src/Plugin/migrate/process/SingleValue.php +++ b/src/Plugin/migrate/process/SingleValue.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\migrate\MigrateExecutableInterface; diff --git a/src/Plugin/migrate/process/SkipOnValue.php b/src/Plugin/migrate/process/SkipOnValue.php index d05cdafab1fd5c8ce6ade81fd78c85b6d987ac9e..2550ea654045dd534c442e021f2108d5e31d13ad 100644 --- a/src/Plugin/migrate/process/SkipOnValue.php +++ b/src/Plugin/migrate/process/SkipOnValue.php @@ -1,8 +1,9 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; -use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\MigrateSkipProcessException; use Drupal\migrate\MigrateSkipRowException; @@ -93,7 +94,7 @@ class SkipOnValue extends ProcessPluginBase { * Thrown if the source property evaluates to a configured value and the * row should be skipped, records with STATUS_IGNORED status in the map. */ - public function row($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + public function row($value, MigrateExecutableInterface $migrate_executable, Row $row, string $destination_property) { $message = !empty($this->configuration['message']) ? $this->configuration['message'] : ''; if (is_array($this->configuration['value'])) { @@ -116,8 +117,9 @@ class SkipOnValue extends ProcessPluginBase { } /** - * Stops processing the current property when input value evaluates to a - * configured value. + * Stops processing the current property. + * + * Stop when input value evaluates to a configured value. * * @param mixed $value * The input value. @@ -136,7 +138,7 @@ class SkipOnValue extends ProcessPluginBase { * Thrown if the source property evaluates to a configured value and rest * of the process should be skipped. */ - public function process($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + public function process($value, MigrateExecutableInterface $migrate_executable, Row $row, string $destination_property) { if (is_array($this->configuration['value'])) { $value_in_array = FALSE; $not_equals = isset($this->configuration['not_equals']); @@ -166,10 +168,9 @@ class SkipOnValue extends ProcessPluginBase { * @param bool $equal * Compare as equal or not equal. * - * @return bool * True if the compare successfully, FALSE otherwise. */ - protected function compareValue($value, $skipValue, $equal = TRUE) { + protected function compareValue($value, $skipValue, bool $equal = TRUE): bool { if ($equal) { return (string) $value == (string) $skipValue; } diff --git a/src/Plugin/migrate/process/StrReplace.php b/src/Plugin/migrate/process/StrReplace.php index 2377d83305d33a5a3cef5c63de197366e4a69c3a..cddd2c7d28769cedab3055124e1f2d318c2fbbd2 100644 --- a/src/Plugin/migrate/process/StrReplace.php +++ b/src/Plugin/migrate/process/StrReplace.php @@ -1,8 +1,9 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; -use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; @@ -89,10 +90,8 @@ class StrReplace extends ProcessPluginBase { /** * Flag indicating whether there are multiple values. - * - * @var bool */ - protected $multiple; + protected ?bool $multiple = NULL; /** * {@inheritdoc} @@ -130,7 +129,7 @@ class StrReplace extends ProcessPluginBase { /** * {@inheritdoc} */ - public function multiple() { + public function multiple(): bool { return $this->multiple; } diff --git a/src/Plugin/migrate/process/Transliteration.php b/src/Plugin/migrate/process/Transliteration.php deleted file mode 100644 index 1ee48da58a84a5d86b8deced5bb692c74cf23923..0000000000000000000000000000000000000000 --- a/src/Plugin/migrate/process/Transliteration.php +++ /dev/null @@ -1,89 +0,0 @@ -<?php - -namespace Drupal\migrate_plus\Plugin\migrate\process; - -use Drupal\Component\Transliteration\TransliterationInterface; -use Drupal\Core\Language\LanguageInterface; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\migrate\MigrateExecutableInterface; -use Drupal\migrate\ProcessPluginBase; -use Drupal\migrate\Row; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Transliterates text from Unicode to US-ASCII. - * - * The transliteration process plugin takes the source value and runs it through - * the transliteration service. Letters will have language decorations and - * accents removed. - * - * Example: - * - * @code - * process: - * bar: - * plugin: transliteration - * source: foo - * @endcode - * - * If the value of foo in the source is 'áéÃ!' then the destination value of - * bar will be 'aei!'. - * - * @see \Drupal\migrate\Plugin\MigrateProcessInterface - * - * @MigrateProcessPlugin( - * id = "transliteration" - * ) - * - * @deprecated in migrate_plus:8.x-5.3 and is removed from migrate_plus:6.0.0. - * Use 'service' process plugin instead. See https://www.drupal.org/node/3255994 - * - * @see https://www.drupal.org/node/3255994 - */ -class Transliteration extends ProcessPluginBase implements ContainerFactoryPluginInterface { - - /** - * The transliteration service. - * - * @var \Drupal\Component\Transliteration\TransliterationInterface - */ - protected $transliteration; - - /** - * Constructs a Transliteration plugin. - * - * @param array $configuration - * The plugin configuration. - * @param string $plugin_id - * The plugin ID. - * @param mixed $plugin_definition - * The plugin definition. - * @param \Drupal\Component\Transliteration\TransliterationInterface $transliteration - * The transliteration service. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, TransliterationInterface $transliteration) { - @trigger_error(__CLASS__ . ' is deprecated in migrate_plus:8.x-5.3 and is removed from migrate_plus:6.0.0. Use Drupal\migrate_plus\Plugin\migrate\process\Service process plugin instead. See https://www.drupal.org/node/3255994', E_USER_DEPRECATED); - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->transliteration = $transliteration; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('transliteration') - ); - } - - /** - * {@inheritdoc} - */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - return $this->transliteration->transliterate($value, LanguageInterface::LANGCODE_DEFAULT, '_'); - } - -} diff --git a/src/Plugin/migrate/process/Transpose.php b/src/Plugin/migrate/process/Transpose.php index 445bb7c515519a5ea638cf12aaf0fb1f04d81c4b..72c294eda92aeccef1a3456b3eaff0a06c9db506 100644 --- a/src/Plugin/migrate/process/Transpose.php +++ b/src/Plugin/migrate/process/Transpose.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\process; use Drupal\migrate\MigrateExecutableInterface; diff --git a/src/Plugin/migrate/source/SourcePluginExtension.php b/src/Plugin/migrate/source/SourcePluginExtension.php index 5d5f5cb512c9f4bed0b8dd1f093291300faab222..38bfed0eebad2de66b330962a5e47e2153e4878c 100644 --- a/src/Plugin/migrate/source/SourcePluginExtension.php +++ b/src/Plugin/migrate/source/SourcePluginExtension.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\source; use Drupal\migrate\Plugin\migrate\source\SourcePluginBase; @@ -42,10 +44,10 @@ abstract class SourcePluginExtension extends SourcePluginBase { /** * {@inheritdoc} */ - public function fields() { + public function fields(): array { $fields = []; foreach ($this->fields as $field_info) { - $fields[$field_info['name']] = isset($field_info['label']) ? $field_info['label'] : $field_info['name']; + $fields[$field_info['name']] = $field_info['label'] ?? $field_info['name']; } return $fields; } @@ -53,7 +55,7 @@ abstract class SourcePluginExtension extends SourcePluginBase { /** * {@inheritdoc} */ - public function getIds() { + public function getIds(): array { return $this->ids; } diff --git a/src/Plugin/migrate/source/Table.php b/src/Plugin/migrate/source/Table.php index 3a7de424ff93a2b52afe0ccc1ede3286fdb7e1bb..c56b234114c36bfe687d6645b768cbc2ca6270a1 100644 --- a/src/Plugin/migrate/source/Table.php +++ b/src/Plugin/migrate/source/Table.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\source; +use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\State\StateInterface; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Plugin\migrate\source\SqlBase; @@ -78,28 +81,28 @@ class Table extends SqlBase { * * @var string */ - const TABLE_ALIAS = 't'; + public const TABLE_ALIAS = 't'; /** * The name of the destination table. * * @var string */ - protected $tableName; + protected string $tableName; /** * IDMap compatible array of id fields. * * @var array */ - protected $idFields; + protected array $idFields; /** * Array of fields present on the destination table. * * @var array */ - protected $fields; + protected array $fields; /** * {@inheritdoc} @@ -124,34 +127,34 @@ class Table extends SqlBase { $field['alias'] = static::TABLE_ALIAS; } $this->idFields = $configuration['id_fields']; - $this->fields = isset($configuration['fields']) ? $configuration['fields'] : []; + $this->fields = $configuration['fields'] ?? []; } /** * {@inheritdoc} */ - public function query() { + public function query(): SelectInterface { return $this->select($this->tableName, static::TABLE_ALIAS)->fields(static::TABLE_ALIAS, $this->fields); } /** * {@inheritdoc} */ - public function fields() { + public function fields(): array { return $this->fields; } /** * {@inheritdoc} */ - public function getIds() { + public function getIds(): array { return $this->idFields; } /** * {@inheritdoc} */ - public function checkRequirements() { + public function checkRequirements(): void { if (!$this->getDatabase()->schema()->tableExists($this->tableName)) { throw new RequirementsException("Source database table '{$this->tableName}' does not exist", ['source_table' => $this->tableName]); } diff --git a/src/Plugin/migrate/source/Url.php b/src/Plugin/migrate/source/Url.php index 242223b61889060e1780fa003ec18817ad3a78cb..c4bba417c70829c603d3b396cad9b8dd5501a7d4 100644 --- a/src/Plugin/migrate/source/Url.php +++ b/src/Plugin/migrate/source/Url.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate\source; +use Drupal\migrate_plus\DataParserPluginInterface; use Drupal\migrate\Plugin\MigrationInterface; /** @@ -18,14 +21,14 @@ class Url extends SourcePluginExtension { * * @var array */ - protected $sourceUrls = []; + protected array $sourceUrls = []; /** * The data parser plugin. * * @var \Drupal\migrate_plus\DataParserPluginInterface */ - protected $dataParserPlugin; + protected DataParserPluginInterface $dataParserPlugin; /** * {@inheritdoc} @@ -45,7 +48,7 @@ class Url extends SourcePluginExtension { * @return string * Comma-separated list of URLs being imported. */ - public function __toString() { + public function __toString(): string { // This could cause a problem when using a lot of urls, may need to hash. $urls = implode(', ', $this->sourceUrls); return $urls; @@ -54,10 +57,9 @@ class Url extends SourcePluginExtension { /** * Returns the initialized data parser plugin. * - * @return \Drupal\migrate_plus\DataParserPluginInterface * The data parser plugin. */ - public function getDataParserPlugin() { + public function getDataParserPlugin(): DataParserPluginInterface { if (!isset($this->dataParserPlugin)) { $this->dataParserPlugin = \Drupal::service('plugin.manager.migrate_plus.data_parser')->createInstance($this->configuration['data_parser_plugin'], $this->configuration); } @@ -67,11 +69,10 @@ class Url extends SourcePluginExtension { /** * Creates and returns a filtered Iterator over the documents. * - * @return \Iterator * An iterator over the documents providing source rows that match the * configured item_selector. */ - protected function initializeIterator() { + protected function initializeIterator(): DataParserPluginInterface { return $this->getDataParserPlugin(); } diff --git a/src/Plugin/migrate_plus/authentication/Basic.php b/src/Plugin/migrate_plus/authentication/Basic.php index f1ca69ab6ca0ab3eccc748daf557db4093cc22a0..9e6288c7e4b0cfe9e8ce227dfcbbee446f916f58 100755 --- a/src/Plugin/migrate_plus/authentication/Basic.php +++ b/src/Plugin/migrate_plus/authentication/Basic.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate_plus\authentication; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -18,7 +20,7 @@ class Basic extends AuthenticationPluginBase implements ContainerFactoryPluginIn /** * {@inheritdoc} */ - public function getAuthenticationOptions() { + public function getAuthenticationOptions(): array { return [ 'auth' => [ $this->configuration['username'], diff --git a/src/Plugin/migrate_plus/authentication/Digest.php b/src/Plugin/migrate_plus/authentication/Digest.php index 2466534306966daae5068a035256e5ffe5feb9c7..9b2f57f573ac642d127b46bc01c9211bf280a473 100755 --- a/src/Plugin/migrate_plus/authentication/Digest.php +++ b/src/Plugin/migrate_plus/authentication/Digest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate_plus\authentication; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -18,7 +20,7 @@ class Digest extends AuthenticationPluginBase implements ContainerFactoryPluginI /** * {@inheritdoc} */ - public function getAuthenticationOptions() { + public function getAuthenticationOptions(): array { return [ 'auth' => [ $this->configuration['username'], diff --git a/src/Plugin/migrate_plus/authentication/Ntlm.php b/src/Plugin/migrate_plus/authentication/Ntlm.php index 3e526881ebd3969711822847f7254b39a239c653..54d4a7e335b843c655045089329b2e2f076ed0c6 100644 --- a/src/Plugin/migrate_plus/authentication/Ntlm.php +++ b/src/Plugin/migrate_plus/authentication/Ntlm.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate_plus\authentication; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -18,7 +20,7 @@ class Ntlm extends AuthenticationPluginBase implements ContainerFactoryPluginInt /** * {@inheritdoc} */ - public function getAuthenticationOptions() { + public function getAuthenticationOptions(): array { return [ 'auth' => [ $this->configuration['username'], diff --git a/src/Plugin/migrate_plus/authentication/OAuth2.php b/src/Plugin/migrate_plus/authentication/OAuth2.php index 0be3f0810fa80bd167b07e7333fcf49a8b0336c4..2d5f5aa7d27ae3ea0c537d40c5de4d11d6e08f7d 100755 --- a/src/Plugin/migrate_plus/authentication/OAuth2.php +++ b/src/Plugin/migrate_plus/authentication/OAuth2.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate_plus\authentication; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -29,7 +31,7 @@ class OAuth2 extends AuthenticationPluginBase implements ContainerFactoryPluginI /** * {@inheritdoc} */ - public function getAuthenticationOptions() { + public function getAuthenticationOptions(): array { $handlerStack = HandlerStack::create(); $client = new Client([ 'handler' => $handlerStack, diff --git a/src/Plugin/migrate_plus/data_fetcher/File.php b/src/Plugin/migrate_plus/data_fetcher/File.php index 33e3cae5c5d665cb0f0e9cbca82bd8f9d8237d61..5a21a1813a7c416587ec41c2b7076bac00da459b 100644 --- a/src/Plugin/migrate_plus/data_fetcher/File.php +++ b/src/Plugin/migrate_plus/data_fetcher/File.php @@ -1,7 +1,11 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate_plus\data_fetcher; +use GuzzleHttp\Psr7\Response; +use Psr\Http\Message\ResponseInterface; use Drupal\migrate\MigrateException; use Drupal\migrate_plus\DataFetcherPluginBase; @@ -18,14 +22,14 @@ class File extends DataFetcherPluginBase { /** * {@inheritdoc} */ - public function setRequestHeaders(array $headers) { + public function setRequestHeaders(array $headers): void { // Does nothing. } /** * {@inheritdoc} */ - public function getRequestHeaders() { + public function getRequestHeaders(): array { // Does nothing. return []; } @@ -33,20 +37,19 @@ class File extends DataFetcherPluginBase { /** * {@inheritdoc} */ - public function getResponse($url) { + public function getResponse($url): ResponseInterface { $response = @file_get_contents($url); if ($response === FALSE) { throw new MigrateException('file parser plugin: could not retrieve data from ' . $url); } - return $response; + return new Response(200, [], $response); } /** * {@inheritdoc} */ - public function getResponseContent($url) { - $response = $this->getResponse($url); - return $response; + public function getResponseContent(string $url): string { + return (string) $this->getResponse($url)->getBody(); } } diff --git a/src/Plugin/migrate_plus/data_fetcher/Http.php b/src/Plugin/migrate_plus/data_fetcher/Http.php index 46f245149252b135cee83022fa41e752b4d42a8f..d1a71d192ef701c41f04e166e892c64eb71dd771 100755 --- a/src/Plugin/migrate_plus/data_fetcher/Http.php +++ b/src/Plugin/migrate_plus/data_fetcher/Http.php @@ -1,7 +1,12 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate_plus\data_fetcher; +use GuzzleHttp\Client; +use Drupal\migrate_plus\AuthenticationPluginInterface; +use Psr\Http\Message\ResponseInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\MigrateException; use Drupal\migrate_plus\DataFetcherPluginBase; @@ -32,24 +37,18 @@ class Http extends DataFetcherPluginBase implements ContainerFactoryPluginInterf /** * The HTTP client. - * - * @var \GuzzleHttp\Client */ - protected $httpClient; + protected ?Client $httpClient; /** * The request headers. - * - * @var array */ - protected $headers = []; + protected array $headers = []; /** * The data retrieval client. - * - * @var \Drupal\migrate_plus\AuthenticationPluginInterface */ - protected $authenticationPlugin; + protected AuthenticationPluginInterface $authenticationPlugin; /** * {@inheritdoc} @@ -66,10 +65,9 @@ class Http extends DataFetcherPluginBase implements ContainerFactoryPluginInterf /** * Returns the initialized authentication plugin. * - * @return \Drupal\migrate_plus\AuthenticationPluginInterface * The authentication plugin. */ - public function getAuthenticationPlugin() { + public function getAuthenticationPlugin(): AuthenticationPluginInterface { if (!isset($this->authenticationPlugin)) { $this->authenticationPlugin = \Drupal::service('plugin.manager.migrate_plus.authentication')->createInstance($this->configuration['authentication']['plugin'], $this->configuration['authentication']); } @@ -79,21 +77,21 @@ class Http extends DataFetcherPluginBase implements ContainerFactoryPluginInterf /** * {@inheritdoc} */ - public function setRequestHeaders(array $headers) { + public function setRequestHeaders(array $headers): void { $this->headers = $headers; } /** * {@inheritdoc} */ - public function getRequestHeaders() { + public function getRequestHeaders(): array { return !empty($this->headers) ? $this->headers : []; } /** * {@inheritdoc} */ - public function getResponse($url) { + public function getResponse($url): ResponseInterface { try { $options = ['headers' => $this->getRequestHeaders()]; if (!empty($this->configuration['authentication'])) { @@ -116,9 +114,8 @@ class Http extends DataFetcherPluginBase implements ContainerFactoryPluginInterf /** * {@inheritdoc} */ - public function getResponseContent($url) { - $response = $this->getResponse($url); - return $response->getBody(); + public function getResponseContent(string $url): string { + return (string) $this->getResponse($url)->getBody(); } } diff --git a/src/Plugin/migrate_plus/data_parser/Json.php b/src/Plugin/migrate_plus/data_parser/Json.php index 37a924f401ffb7574feafb4029429e84f0973fad..7b1b6356776567f93392df51e752c653caf4ec7c 100755 --- a/src/Plugin/migrate_plus/data_parser/Json.php +++ b/src/Plugin/migrate_plus/data_parser/Json.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate_plus\data_parser; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -17,10 +19,8 @@ class Json extends DataParserPluginBase implements ContainerFactoryPluginInterfa /** * Iterator over the JSON data. - * - * @var \Iterator */ - protected $iterator; + protected ?\ArrayIterator $iterator = NULL; /** * Retrieves the JSON data and returns it as an array. @@ -28,22 +28,19 @@ class Json extends DataParserPluginBase implements ContainerFactoryPluginInterfa * @param string $url * URL of a JSON feed. * - * @return array - * The selected data to be iterated. - * * @throws \GuzzleHttp\Exception\RequestException */ - protected function getSourceData($url) { + protected function getSourceData(string $url): array { $response = $this->getDataFetcherPlugin()->getResponseContent($url); // Convert objects to associative arrays. - $source_data = json_decode($response, TRUE); + $source_data = json_decode($response, TRUE, 512, JSON_THROW_ON_ERROR); // If json_decode() has returned NULL, it might be that the data isn't // valid utf8 - see http://php.net/manual/en/function.json-decode.php#86997. if (is_null($source_data)) { $utf8response = utf8_encode($response); - $source_data = json_decode($utf8response, TRUE); + $source_data = json_decode($utf8response, TRUE, 512, JSON_THROW_ON_ERROR); } // Backwards-compatibility for depth selection. @@ -52,7 +49,7 @@ class Json extends DataParserPluginBase implements ContainerFactoryPluginInterfa } // Otherwise, we're using xpath-like selectors. - $selectors = explode('/', trim($this->itemSelector, '/')); + $selectors = explode('/', trim((string) $this->itemSelector, '/')); foreach ($selectors as $selector) { if (!empty($selector) || $selector === '0') { $source_data = $source_data[$selector]; @@ -67,10 +64,9 @@ class Json extends DataParserPluginBase implements ContainerFactoryPluginInterfa * @param array $raw_data * Raw data from the JSON feed. * - * @return array * Selected items at the requested depth of the JSON feed. */ - protected function selectByDepth(array $raw_data) { + protected function selectByDepth(array $raw_data): array { // Return the results in a recursive iterator that can traverse // multidimensional arrays. $iterator = new \RecursiveIteratorIterator( @@ -95,7 +91,7 @@ class Json extends DataParserPluginBase implements ContainerFactoryPluginInterfa /** * {@inheritdoc} */ - protected function openSourceUrl($url) { + protected function openSourceUrl(string $url): bool { // (Re)open the provided URL. $source_data = $this->getSourceData($url); $this->iterator = new \ArrayIterator($source_data); @@ -105,12 +101,12 @@ class Json extends DataParserPluginBase implements ContainerFactoryPluginInterfa /** * {@inheritdoc} */ - protected function fetchNextRow() { + protected function fetchNextRow(): void { $current = $this->iterator->current(); if ($current) { foreach ($this->fieldSelectors() as $field_name => $selector) { $field_data = $current; - $field_selectors = explode('/', trim($selector, '/')); + $field_selectors = explode('/', trim((string) $selector, '/')); foreach ($field_selectors as $field_selector) { if (is_array($field_data) && array_key_exists($field_selector, $field_data)) { $field_data = $field_data[$field_selector]; diff --git a/src/Plugin/migrate_plus/data_parser/SimpleXml.php b/src/Plugin/migrate_plus/data_parser/SimpleXml.php index 5e09822287d97f89faeccea88458bea22f6f6371..0d6eb9ec49dcf78c838435109c84e32cfd15d4be 100644 --- a/src/Plugin/migrate_plus/data_parser/SimpleXml.php +++ b/src/Plugin/migrate_plus/data_parser/SimpleXml.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate_plus\data_parser; use Drupal\migrate\MigrateException; @@ -20,7 +22,7 @@ class SimpleXml extends DataParserPluginBase { /** * Array of matches from item_selector. * - * @var array + * @var \SimpleXMLElement[]|bool */ protected $matches = []; @@ -37,7 +39,7 @@ class SimpleXml extends DataParserPluginBase { /** * {@inheritdoc} */ - protected function openSourceUrl($url) { + protected function openSourceUrl($url): bool { // Clear XML error buffer. Other Drupal code that executed during the // migration may have polluted the error buffer and could create false // positives in our error check below. We are only concerned with errors @@ -59,7 +61,7 @@ class SimpleXml extends DataParserPluginBase { /** * {@inheritdoc} */ - protected function fetchNextRow() { + protected function fetchNextRow(): void { $target_element = array_shift($this->matches); // If we've found the desired element, populate the currentItem and diff --git a/src/Plugin/migrate_plus/data_parser/Soap.php b/src/Plugin/migrate_plus/data_parser/Soap.php index 3f8a75421a9e42ba7eefff18e7f31b6bf6f9c63c..a804637d7b355839e74ae73334e68fdb7bd80107 100755 --- a/src/Plugin/migrate_plus/data_parser/Soap.php +++ b/src/Plugin/migrate_plus/data_parser/Soap.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate_plus\data_parser; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -19,31 +21,23 @@ class Soap extends DataParserPluginBase implements ContainerFactoryPluginInterfa /** * Iterator over the SOAP data. - * - * @var \Iterator */ - protected $iterator; + protected ?\ArrayIterator $iterator = NULL; /** * Method to call on the SOAP service. - * - * @var string */ - protected $function; + protected string $function; /** * Parameters to pass to the SOAP service function. - * - * @var array */ - protected $parameters; + protected array $parameters; /** * Form of the function response - 'xml', 'object', or 'array'. - * - * @var string */ - protected $responseType; + protected string $responseType; /** * {@inheritdoc} @@ -69,7 +63,7 @@ class Soap extends DataParserPluginBase implements ContainerFactoryPluginInterfa * @throws \Drupal\migrate\MigrateException * If we can't resolve the SOAP function or its response property. */ - protected function openSourceUrl($url) { + protected function openSourceUrl($url): bool { // Will throw SoapFault if there's an error in a SOAP call. $client = new \SoapClient($url); // Determine the response property name. @@ -120,7 +114,7 @@ class Soap extends DataParserPluginBase implements ContainerFactoryPluginInterfa /** * {@inheritdoc} */ - protected function fetchNextRow() { + protected function fetchNextRow(): void { $current = $this->iterator->current(); if ($current) { foreach ($this->fieldSelectors() as $field_name => $selector) { diff --git a/src/Plugin/migrate_plus/data_parser/Xml.php b/src/Plugin/migrate_plus/data_parser/Xml.php index 2eb4314296e3192ddda0000bfb2e323ec1502cb1..ead05917b9eb17138a3766c2966727510637b17c 100644 --- a/src/Plugin/migrate_plus/data_parser/Xml.php +++ b/src/Plugin/migrate_plus/data_parser/Xml.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate_plus\data_parser; use Drupal\migrate\MigrateException; @@ -19,30 +21,24 @@ class Xml extends DataParserPluginBase { /** * The XMLReader we are encapsulating. - * - * @var \XMLReader */ - protected $reader; + protected \XMLReader $reader; /** * Array of the element names from the query. * * 0-based from the first (root) element. For example, '//file/article' would * be stored as [0 => 'file', 1 => 'article']. - * - * @var array */ - protected $elementsToMatch = []; + protected array $elementsToMatch = []; /** * An optional xpath predicate. * * Restricts the matching elements based on values in their children. Parsed * from the element query at construct time. - * - * @var string */ - protected $xpathPredicate = NULL; + protected ?string $xpathPredicate = NULL; /** * Array representing the path to the current element as we traverse the XML. @@ -50,10 +46,8 @@ class Xml extends DataParserPluginBase { * For example, if in an XML string like '<file><article>...</article></file>' * we are positioned within the article element, currentPath will be * [0 => 'file', 1 => 'article']. - * - * @var array */ - protected $currentPath = []; + protected array $currentPath = []; /** * Retains all elements with a given name to support extraction from parents. @@ -64,27 +58,21 @@ class Xml extends DataParserPluginBase { * around parent elements again once we've located an element of interest. So, * grab elements with matching names and their depths, and refer back to it * when building the source row. - * - * @var array */ - protected $parentXpathCache = []; + protected array $parentXpathCache = []; /** * Hash of the element names that should be captured into $parentXpathCache. - * - * @var array */ - protected $parentElementsOfInterest = []; + protected array $parentElementsOfInterest = []; /** * Element name matching mode. * * When matching element names, whether to compare to the namespace-prefixed * name, or the local name. - * - * @var bool */ - protected $prefixedName = FALSE; + protected bool $prefixedName = FALSE; /** * {@inheritdoc} @@ -131,13 +119,13 @@ class Xml extends DataParserPluginBase { * The resulting SimpleXmlElement also contains any child nodes of the current * element. * - * @return \SimpleXmlElement|false - * A \SimpleXmlElement when the document is parseable, or false if a + * @return \SimpleXmlElement|null + * A \SimpleXmlElement when the document is parseable, or null if a * parsing error occurred. * * @throws \Drupal\migrate\MigrateException */ - protected function getSimpleXml() { + protected function getSimpleXml(): ?\SimpleXMLElement { $node = $this->reader->expand(); if ($node) { // We must associate the DOMNode with a DOMDocument to be able to import @@ -155,14 +143,14 @@ class Xml extends DataParserPluginBase { $error_string = self::parseLibXmlError($error); throw new MigrateException($error_string); } - return FALSE; + return NULL; } } /** * {@inheritdoc} */ - public function rewind() { + public function rewind(): void { // Reset our path tracker. $this->currentPath = []; parent::rewind(); @@ -171,7 +159,7 @@ class Xml extends DataParserPluginBase { /** * {@inheritdoc} */ - protected function openSourceUrl($url) { + protected function openSourceUrl($url): bool { // (Re)open the provided URL. $this->reader->close(); @@ -187,7 +175,7 @@ class Xml extends DataParserPluginBase { /** * {@inheritdoc} */ - protected function fetchNextRow() { + protected function fetchNextRow(): void { $target_element = NULL; // Loop over each node in the XML file, looking for elements at a path @@ -210,7 +198,7 @@ class Xml extends DataParserPluginBase { // We're positioned to the right element path - build the SimpleXML // object to enable proper xpath predicate evaluation. $target_element = $this->getSimpleXml(); - if ($target_element !== FALSE) { + if ($target_element !== NULL) { if (empty($this->xpathPredicate) || $this->predicateMatches($target_element)) { break; } @@ -279,10 +267,9 @@ class Xml extends DataParserPluginBase { * @param \SimpleXMLElement $elem * The element to test. * - * @return bool * True if the element matches the predicate, false if not. */ - protected function predicateMatches(\SimpleXMLElement $elem) { + protected function predicateMatches(\SimpleXMLElement $elem): bool { return !empty($elem->xpath('/*[' . $this->xpathPredicate . ']')); } diff --git a/src/Plugin/migrate_plus/data_parser/XmlTrait.php b/src/Plugin/migrate_plus/data_parser/XmlTrait.php index 28519ba516ad38d0e6965eacc9d0baa8b1bf0163..b298a6885141eef07f564ee726344cbcc107ee0f 100644 --- a/src/Plugin/migrate_plus/data_parser/XmlTrait.php +++ b/src/Plugin/migrate_plus/data_parser/XmlTrait.php @@ -1,7 +1,11 @@ <?php +declare(strict_types = 1); + namespace Drupal\migrate_plus\Plugin\migrate_plus\data_parser; +use Drupal\Core\StringTranslation\TranslatableMarkup; + /** * Common functionality for XML data parsers. */ @@ -13,7 +17,7 @@ trait XmlTrait { * @param \SimpleXMLElement $xml * The element to apply namespace registrations to. */ - protected function registerNamespaces(\SimpleXMLElement $xml) { + protected function registerNamespaces(\SimpleXMLElement $xml): void { if (isset($this->configuration['namespaces']) && is_array($this->configuration['namespaces'])) { foreach ($this->configuration['namespaces'] as $prefix => $ns) { $xml->registerXPathNamespace($prefix, $ns); @@ -30,7 +34,7 @@ trait XmlTrait { * @return string * Error message */ - public static function parseLibXmlError(\LibXMLError $error) { + public static function parseLibXmlError(\LibXMLError $error): TranslatableMarkup { $error_code_name = 'Unknown Error'; switch ($error->level) { case LIBXML_ERR_WARNING: @@ -51,10 +55,10 @@ trait XmlTrait { [ '@libxmlerrorcodename' => $error_code_name, '@libxmlerrorcode' => $error->code, - '@libxmlerrormessage' => trim($error->message), + '@libxmlerrormessage' => trim((string) $error->message), '@libxmlerrorline' => $error->line, '@libxmlerrorcolumn' => $error->column, - '@libxmlerrorfile' => (($error->file)) ? $error->file : NULL, + '@libxmlerrorfile' => $error->file ?: NULL, ] ); } diff --git a/tests/modules/migrate_plus_test/migrate_plus_test.info.yml b/tests/modules/migrate_plus_test/migrate_plus_test.info.yml index faac06f5818bcde32121c8fb916bdef16a7cae32..1a923bb181db27baf1de90aea17c0e7c4db7c933 100644 --- a/tests/modules/migrate_plus_test/migrate_plus_test.info.yml +++ b/tests/modules/migrate_plus_test/migrate_plus_test.info.yml @@ -2,7 +2,7 @@ type: module name: Migrate Plus Test description: 'Test module to test Migrate Plus.' package: Testing -core_version_requirement: ^8.8 || ^9 +core_version_requirement: '>=9.1' dependencies: - drupal:migrate - migrate_plus:migrate_plus diff --git a/tests/src/Functional/LoadTest.php b/tests/src/Functional/LoadTest.php index 02edda0ee98c3a5c252de00adf4f00ba0ea19661..257e13e55569f7c9e7552d7e3557cd0f258ea59b 100644 --- a/tests/src/Functional/LoadTest.php +++ b/tests/src/Functional/LoadTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Functional; use Drupal\Core\Url; @@ -10,7 +12,7 @@ use Drupal\Tests\BrowserTestBase; * * @group migrate_plus */ -class LoadTest extends BrowserTestBase { +final class LoadTest extends BrowserTestBase { /** * {@inheritdoc} diff --git a/tests/src/Kernel/EntityLookupAccessTest.php b/tests/src/Kernel/EntityLookupAccessTest.php index 794484f99371d4192bc7b2bc5c1ed47638a558c1..1d417eceb08af0514a70cf0b32cd60d774ce11b7 100644 --- a/tests/src/Kernel/EntityLookupAccessTest.php +++ b/tests/src/Kernel/EntityLookupAccessTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel; use Drupal\entity_test\Entity\EntityTest; @@ -14,7 +16,7 @@ use Drupal\user\Entity\User; * * @group migrate_plus */ -class EntityLookupAccessTest extends KernelTestBase { +final class EntityLookupAccessTest extends KernelTestBase { use UserCreationTrait; /** @@ -31,16 +33,14 @@ class EntityLookupAccessTest extends KernelTestBase { /** * A user. * - * @var \Drupal\user\Entity\User + * @var bool|\Drupal\user\Entity\User */ protected $user; /** * A test entity. - * - * @var \Drupal\entity_test\Entity\EntityTest */ - protected $entity; + protected ?EntityTest $entity; /** * {@inheritdoc} diff --git a/tests/src/Kernel/MigrateTableBatchTest.php b/tests/src/Kernel/MigrateTableBatchTest.php index 4458b23667eb97ca8a933164e2a07a1f7307e5c6..892248b7965df8215150578db96d45fa2d89a572 100755 --- a/tests/src/Kernel/MigrateTableBatchTest.php +++ b/tests/src/Kernel/MigrateTableBatchTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel; /** @@ -7,7 +9,7 @@ namespace Drupal\Tests\migrate_plus\Kernel; * * @group migrate */ -class MigrateTableBatchTest extends MigrateTableTest { +final class MigrateTableBatchTest extends MigrateTableTest { /** * The batch size to configure (a size of 1 disables batching). diff --git a/tests/src/Kernel/MigrateTableEvenBatchTest.php b/tests/src/Kernel/MigrateTableEvenBatchTest.php index 1c060e4ff3228c7021436f384ccc31cd49414fa6..7bfdaf387f283c65b459fbbd00a080befbcabf34 100755 --- a/tests/src/Kernel/MigrateTableEvenBatchTest.php +++ b/tests/src/Kernel/MigrateTableEvenBatchTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel; /** @@ -7,7 +9,7 @@ namespace Drupal\Tests\migrate_plus\Kernel; * * @group migrate */ -class MigrateTableEvenBatchTest extends MigrateTableTest { +final class MigrateTableEvenBatchTest extends MigrateTableTest { /** * The batch size to configure (a size of 1 disables batching). diff --git a/tests/src/Kernel/MigrateTableIncrementBatchTest.php b/tests/src/Kernel/MigrateTableIncrementBatchTest.php index 32edb2a8f4784bab40f27d4245ddc7928f88ddb8..7d07f8b083827b755e82f1b34b9c1515a0cb55ce 100755 --- a/tests/src/Kernel/MigrateTableIncrementBatchTest.php +++ b/tests/src/Kernel/MigrateTableIncrementBatchTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel; /** @@ -7,7 +9,7 @@ namespace Drupal\Tests\migrate_plus\Kernel; * * @group migrate */ -class MigrateTableIncrementBatchTest extends MigrateTableIncrementTest { +final class MigrateTableIncrementBatchTest extends MigrateTableIncrementTest { /** * The batch size to configure. diff --git a/tests/src/Kernel/MigrateTableIncrementEvenBatchTest.php b/tests/src/Kernel/MigrateTableIncrementEvenBatchTest.php index 66a4879ba81dde932ab07b1df3b133a3e3e23075..b858cddeda0d2d04c72c2a338c4e9a1582fb61e1 100755 --- a/tests/src/Kernel/MigrateTableIncrementEvenBatchTest.php +++ b/tests/src/Kernel/MigrateTableIncrementEvenBatchTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel; /** @@ -7,7 +9,7 @@ namespace Drupal\Tests\migrate_plus\Kernel; * * @group migrate */ -class MigrateTableIncrementEvenBatchTest extends MigrateTableIncrementTest { +final class MigrateTableIncrementEvenBatchTest extends MigrateTableIncrementTest { /** * The batch size to configure. diff --git a/tests/src/Kernel/MigrateTableIncrementTest.php b/tests/src/Kernel/MigrateTableIncrementTest.php index f1454982f5cf5c7b29a6a19079a432ec7d5ecd6f..ab83a7824e058d4db5dfbe4579d8483758628f4b 100755 --- a/tests/src/Kernel/MigrateTableIncrementTest.php +++ b/tests/src/Kernel/MigrateTableIncrementTest.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel; +use Drupal\Core\Database\Connection; use Drupal\migrate\MigrateExecutable; use Drupal\Tests\migrate\Kernel\MigrateTestBase; @@ -12,14 +15,12 @@ use Drupal\Tests\migrate\Kernel\MigrateTestBase; */ class MigrateTableIncrementTest extends MigrateTestBase { - const TABLE_NAME = 'migrate_test_destination_table'; + public const TABLE_NAME = 'migrate_test_destination_table'; /** * The database connection. - * - * @var \Drupal\Core\Database\Connection */ - protected $connection; + protected ?Connection $connection = NULL; /** * {@inheritdoc} diff --git a/tests/src/Kernel/MigrateTableTest.php b/tests/src/Kernel/MigrateTableTest.php index 27e2eb9d4ce68635fd0d18d26ab3ad5fb21b08e2..959da3fbd6fe450344e73ead8bfb9bcd2cb764db 100755 --- a/tests/src/Kernel/MigrateTableTest.php +++ b/tests/src/Kernel/MigrateTableTest.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel; +use Drupal\Core\Database\Connection; use Drupal\migrate\MigrateExecutable; use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Row; @@ -14,15 +17,13 @@ use Drupal\Tests\migrate\Kernel\MigrateTestBase; */ class MigrateTableTest extends MigrateTestBase { - const SOURCE_TABLE_NAME = 'migrate_test_source_table'; - const DEST_TABLE_NAME = 'migrate_test_destination_table'; + public const SOURCE_TABLE_NAME = 'migrate_test_source_table'; + public const DEST_TABLE_NAME = 'migrate_test_destination_table'; /** * The database connection. - * - * @var \Drupal\Core\Database\Connection */ - protected $connection; + protected ?Connection $connection = NULL; /** * The batch size to configure (a size of 1 disables batching). diff --git a/tests/src/Kernel/MigrationConfigEntityTest.php b/tests/src/Kernel/MigrationConfigEntityTest.php index f7f9841d90531dd41bea74d873d8082b06e7e83f..2053c0cdb9588565618e7db7952745451dea6c7f 100644 --- a/tests/src/Kernel/MigrationConfigEntityTest.php +++ b/tests/src/Kernel/MigrationConfigEntityTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel; use Drupal\Component\Plugin\Exception\PluginNotFoundException; @@ -12,7 +14,7 @@ use Drupal\Tests\migrate\Kernel\MigrateTestBase; * * @group migrate_plus */ -class MigrationConfigEntityTest extends MigrateTestBase { +final class MigrationConfigEntityTest extends MigrateTestBase { /** * {@inheritdoc} diff --git a/tests/src/Kernel/MigrationGroupTest.php b/tests/src/Kernel/MigrationGroupTest.php index eb62bb4547b23c435f07c8b24d5301d095267781..aa9fbf2f3df04d75ac050ad5fdb5492597ab5ec7 100644 --- a/tests/src/Kernel/MigrationGroupTest.php +++ b/tests/src/Kernel/MigrationGroupTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel; use Drupal\KernelTests\KernelTestBase; @@ -11,7 +13,7 @@ use Drupal\migrate_plus\Entity\MigrationGroup; * * @group migrate_plus */ -class MigrationGroupTest extends KernelTestBase { +final class MigrationGroupTest extends KernelTestBase { /** * {@inheritdoc} diff --git a/tests/src/Kernel/Plugin/migrate/process/DefaultEntityValueTest.php b/tests/src/Kernel/Plugin/migrate/process/DefaultEntityValueTest.php index 1d4769b09fd9e003a8b44bddef9c1af7f5d3ca01..898e3133bf426fd98aaa2d13b345678a726c4e5c 100644 --- a/tests/src/Kernel/Plugin/migrate/process/DefaultEntityValueTest.php +++ b/tests/src/Kernel/Plugin/migrate/process/DefaultEntityValueTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process; use Drupal\KernelTests\KernelTestBase; @@ -15,7 +17,7 @@ use Drupal\Tests\user\Traits\UserCreationTrait; * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\DefaultEntityValue * @group migrate_plus */ -class DefaultEntityValueTest extends KernelTestBase { +final class DefaultEntityValueTest extends KernelTestBase { use UserCreationTrait; diff --git a/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php b/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php index 32b4c7e306b33b7428db2c1fa986a43567e7c033..a0277a28c0e1426c3455e0b1fd1fb65b41c83c5d 100644 --- a/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php +++ b/tests/src/Kernel/Plugin/migrate/process/EntityGenerateTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process; use Drupal\Core\Config\Entity\ConfigEntityInterface; @@ -10,6 +12,7 @@ use Drupal\field\Entity\FieldStorageConfig; use Drupal\KernelTests\KernelTestBase; use Drupal\migrate\MigrateExecutable; use Drupal\migrate\MigrateMessageInterface; +use Drupal\migrate\Plugin\MigrationPluginManager; use Drupal\node\Entity\NodeType; use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Vocabulary; @@ -21,7 +24,7 @@ use Drupal\Tests\field\Traits\EntityReferenceTestTrait; * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\EntityGenerate * @group migrate_plus */ -class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterface { +final class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterface { use EntityReferenceTestTrait; @@ -40,33 +43,10 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa 'filter', ]; - /** - * The bundle used in this test. - * - * @var string - */ - protected $bundle = 'page'; - - /** - * The name of the field used in this test. - * - * @var string - */ - protected $fieldName = 'field_entity_reference'; - - /** - * The vocabulary id. - * - * @var string - */ - protected $vocabulary = 'fruit'; - - /** - * The migration plugin manager. - * - * @var \Drupal\migrate\Plugin\MigrationPluginManager - */ - protected $migrationPluginManager; + protected ?string $bundle = 'page'; + protected ?string $fieldName = 'field_entity_reference'; + protected ?string $vocabulary = 'fruit'; + protected ?MigrationPluginManager $migrationPluginManager; /** * {@inheritdoc} @@ -151,7 +131,7 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa $migration = $this->migrationPluginManager->createStubMigration($definition); $reflector = new \ReflectionObject($migration->getDestinationPlugin()); $attribute = $reflector->getProperty('storage'); - $attribute->setAccessible(true); + $attribute->setAccessible(TRUE); /** @var \Drupal\Core\Entity\EntityStorageBase $storage */ $storage = $attribute->getValue($migration->getDestinationPlugin()); $migrationExecutable = (new MigrateExecutable($migration, $this)); @@ -224,7 +204,7 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa /** * Test lookup without a reference field. */ - public function testNonReferenceField() { + public function testNonReferenceField(): void { $values = [ 'name' => 'Apples', 'vid' => $this->vocabulary, @@ -317,7 +297,7 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa /** * Provides multiple migration definitions for "transform" test. */ - public function transformDataProvider() { + public function transformDataProvider(): array { return [ 'no arguments' => [ 'definition' => [ @@ -965,7 +945,7 @@ class EntityGenerateTest extends KernelTestBase implements MigrateMessageInterfa /** * {@inheritdoc} */ - public function display($message, $type = 'status') { + public function display($message, $type = 'status'): void { $this->assertTrue($type == 'status', $message); } diff --git a/tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php b/tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php index 8793609cfdf095cc9693f821814095696d81f3aa..b47ef8b7fb08b268c65afbeecdc31509cd8bb1b6 100644 --- a/tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php +++ b/tests/src/Kernel/Plugin/migrate/process/EntityLookupTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process; use Drupal\KernelTests\KernelTestBase; @@ -15,7 +17,7 @@ use Drupal\Tests\user\Traits\UserCreationTrait; * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\EntityLookup * @group migrate_plus */ -class EntityLookupTest extends KernelTestBase { +final class EntityLookupTest extends KernelTestBase { use UserCreationTrait; diff --git a/tests/src/Kernel/Plugin/migrate/process/EntityValueTest.php b/tests/src/Kernel/Plugin/migrate/process/EntityValueTest.php index 9ffe66570bbd31a291d20e731991cf1c06c90d3b..34dd35a9b7e6c4e571570680b483cb0e484870d1 100644 --- a/tests/src/Kernel/Plugin/migrate/process/EntityValueTest.php +++ b/tests/src/Kernel/Plugin/migrate/process/EntityValueTest.php @@ -1,11 +1,14 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process; use Drupal\KernelTests\KernelTestBase; use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; +use Drupal\migrate_plus\Plugin\migrate\process\EntityValue; use Drupal\node\Entity\Node; use Drupal\language\Entity\ConfigurableLanguage; use Drupal\node\Entity\NodeType; @@ -16,35 +19,27 @@ use Drupal\node\Entity\NodeType; * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\EntityValue * @group migrate_drupal */ -class EntityValueTest extends KernelTestBase { +final class EntityValueTest extends KernelTestBase { /** * The generated title. - * - * @var string */ - protected $title; + protected ?string $title; /** * The generated Spanish title. - * - * @var string */ - protected $titleSpanish; + protected ?string $titleSpanish; /** * The generated node ID. - * - * @var int */ - protected $uid; + protected ?string $uid; /** * The plugin to test. - * - * @var \Drupal\migrate_plus\Plugin\migrate\process\EntityValue */ - protected $plugin; + protected ?EntityValue $plugin; /** @@ -92,7 +87,7 @@ class EntityValueTest extends KernelTestBase { * * @covers ::transform */ - public function testEntityValueSuccess() { + public function testEntityValueSuccess(): void { $this->plugin = \Drupal::service('plugin.manager.migrate.process') ->createInstance('entity_value', [ 'entity_type' => 'node', @@ -129,7 +124,7 @@ class EntityValueTest extends KernelTestBase { * * @covers ::transform */ - public function testEntityValueLangSuccess() { + public function testEntityValueLangSuccess(): void { $this->plugin = \Drupal::service('plugin.manager.migrate.process') ->createInstance('entity_value', [ 'entity_type' => 'node', @@ -157,7 +152,7 @@ class EntityValueTest extends KernelTestBase { * * @covers ::transform */ - public function testEntityValueLangException() { + public function testEntityValueLangException(): void { $config_entity = NodeType::create(['type' => 'page', 'name' => 'page']); $config_entity->save(); $this->plugin = \Drupal::service('plugin.manager.migrate.process') @@ -186,7 +181,7 @@ class EntityValueTest extends KernelTestBase { * @covers ::__construct * @dataProvider entityValueFailureConfigData */ - public function testEntityValueConfig($config) { + public function testEntityValueConfig($config): void { $this->expectException(\InvalidArgumentException::class); \Drupal::service('plugin.manager.migrate.process') ->createInstance('entity_value', $config); @@ -195,10 +190,9 @@ class EntityValueTest extends KernelTestBase { /** * Provides data for entityLoadFailureConfigData. * - * @return array * The data. */ - public function entityValueFailureConfigData() { + public function entityValueFailureConfigData(): array { return [ [ [ diff --git a/tests/src/Kernel/Plugin/migrate/process/FileBlobTest.php b/tests/src/Kernel/Plugin/migrate/process/FileBlobTest.php index 378965c72a576557f2accc4835998d31140325d7..42270b3844dda3aaffe55065b7137a96737ff648 100644 --- a/tests/src/Kernel/Plugin/migrate/process/FileBlobTest.php +++ b/tests/src/Kernel/Plugin/migrate/process/FileBlobTest.php @@ -1,10 +1,13 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process; use Drupal\Core\File\FileSystemInterface; use Drupal\KernelTests\KernelTestBase; use Drupal\migrate\MigrateExecutableInterface; +use Drupal\migrate\Plugin\MigratePluginManagerInterface; use Drupal\migrate\Row; use Drupal\Tests\user\Traits\UserCreationTrait; @@ -14,7 +17,7 @@ use Drupal\Tests\user\Traits\UserCreationTrait; * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\FileBlob * @group migrate_plus */ -class FileBlobTest extends KernelTestBase { +final class FileBlobTest extends KernelTestBase { use UserCreationTrait; @@ -29,31 +32,23 @@ class FileBlobTest extends KernelTestBase { /** * The process plugin manager. - * - * @var \Drupal\migrate\Plugin\MigratePluginManagerInterface */ - protected $pluginManager; + protected ?MigratePluginManagerInterface $pluginManager; /** * The blob representation of a cat image. - * - * @var string */ - protected $blob; + protected ?string $blob; /** * The sha1sum of the blob. - * - * @var string */ - protected $sha1sum; + protected ?string $sha1sum; /** * The filesystem interface. - * - * @var \Drupal\Core\File\FileSystemInterface */ - protected $filesystem; + protected ?FileSystemInterface $filesystem = NULL; /** * {@inheritdoc} diff --git a/tests/src/Kernel/Plugin/migrate/process/ServiceTest.php b/tests/src/Kernel/Plugin/migrate/process/ServiceTest.php index 59086865d208cba9d8874790336d187352a6e13f..3745ca417938238c7f4a23a59a33dd02a9c84ba3 100644 --- a/tests/src/Kernel/Plugin/migrate/process/ServiceTest.php +++ b/tests/src/Kernel/Plugin/migrate/process/ServiceTest.php @@ -1,9 +1,12 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\process; use Drupal\KernelTests\KernelTestBase; use Drupal\migrate\MigrateExecutableInterface; +use Drupal\migrate\Plugin\MigratePluginManagerInterface; use Drupal\migrate\Row; /** @@ -12,7 +15,7 @@ use Drupal\migrate\Row; * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\Service * @group migrate_plus */ -class ServiceTest extends KernelTestBase { +final class ServiceTest extends KernelTestBase { /** * {@inheritdoc} @@ -25,10 +28,8 @@ class ServiceTest extends KernelTestBase { /** * The process plugin manager. - * - * @var \Drupal\migrate\Plugin\MigratePluginManagerInterface */ - protected $pluginManager; + protected ?MigratePluginManagerInterface $pluginManager = NULL; /** * {@inheritdoc} @@ -79,7 +80,7 @@ class ServiceTest extends KernelTestBase { * * @dataProvider providerConfig */ - public function testInvalidConfig(array $configuration, $message): void { + public function testInvalidConfig(array $configuration, string $message): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage($message); $this->pluginManager->createInstance('service', $configuration); @@ -88,7 +89,7 @@ class ServiceTest extends KernelTestBase { /** * Data provider for testInvalidConfig. */ - public function providerConfig() { + public function providerConfig(): array { return [ 'missing service name' => [ 'configuration' => [], diff --git a/tests/src/Kernel/Plugin/migrate/source/TableTest.php b/tests/src/Kernel/Plugin/migrate/source/TableTest.php index d01f02fbfd60b6dcf30a1ea23143278fe6ce870d..260d613b97c3ded5128dc464f0e11e518463b3c3 100644 --- a/tests/src/Kernel/Plugin/migrate/source/TableTest.php +++ b/tests/src/Kernel/Plugin/migrate/source/TableTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate\source; use Drupal\migrate\Exception\RequirementsException; @@ -12,7 +14,7 @@ use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase; * * @group migrate_plus */ -class TableTest extends MigrateDrupal7TestBase { +final class TableTest extends MigrateDrupal7TestBase { /** * {@inheritdoc} @@ -28,10 +30,8 @@ class TableTest extends MigrateDrupal7TestBase { /** * Definition of a test migration. - * - * @var array */ - protected $migrationDefinition; + protected ?array $migrationDefinition; /** * {@inheritdoc} @@ -72,7 +72,7 @@ class TableTest extends MigrateDrupal7TestBase { * * @dataProvider badConfigurationProvider */ - public function testTableBadConfiguration($configuration, $message): void { + public function testTableBadConfiguration($configuration, string $message): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage($message); $configuration['plugin'] = 'table'; @@ -84,10 +84,9 @@ class TableTest extends MigrateDrupal7TestBase { /** * Data provider with invalid plugin configurations. * - * @return array * Plugin configurations and messages. */ - public function badConfigurationProvider() { + public function badConfigurationProvider(): array { return [ 'Missing table_name' => [ [], diff --git a/tests/src/Kernel/Plugin/migrate_plus/data_fetcher/HttpTest.php b/tests/src/Kernel/Plugin/migrate_plus/data_fetcher/HttpTest.php index c3ee25e785f082dc80d4b2aa1e588487465e5253..d4b3186822de97ed998c2e8146b5045eb230c4e0 100644 --- a/tests/src/Kernel/Plugin/migrate_plus/data_fetcher/HttpTest.php +++ b/tests/src/Kernel/Plugin/migrate_plus/data_fetcher/HttpTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate_plus\data_fetcher; use Drupal\KernelTests\KernelTestBase; @@ -11,7 +13,7 @@ use Drupal\migrate_plus\Plugin\migrate_plus\data_fetcher\Http; * @group migrate_plus * @package Drupal\Tests\migrate_plus\Unit\migrate_plus\data_fetcher */ -class HttpTest extends KernelTestBase { +final class HttpTest extends KernelTestBase { /** * Test http headers option. diff --git a/tests/src/Kernel/Plugin/migrate_plus/data_parser/JsonTest.php b/tests/src/Kernel/Plugin/migrate_plus/data_parser/JsonTest.php index 2069b78ed620027d464db70d209198cf70c93bfa..e862885de097f2a53ab2bd3128abb8aa93dcce3e 100644 --- a/tests/src/Kernel/Plugin/migrate_plus/data_parser/JsonTest.php +++ b/tests/src/Kernel/Plugin/migrate_plus/data_parser/JsonTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate_plus\data_parser; use Drupal\KernelTests\KernelTestBase; @@ -9,7 +11,7 @@ use Drupal\KernelTests\KernelTestBase; * * @group migrate_plus */ -class JsonTest extends KernelTestBase { +final class JsonTest extends KernelTestBase { /** * {@inheritdoc} diff --git a/tests/src/Kernel/Plugin/migrate_plus/data_parser/SimpleXmlTest.php b/tests/src/Kernel/Plugin/migrate_plus/data_parser/SimpleXmlTest.php index 77ab9768307f0cdd8da1e0cf9590458f96c04354..dfa9039fc0d2101f1fded62f7d4829bd1c840ad9 100644 --- a/tests/src/Kernel/Plugin/migrate_plus/data_parser/SimpleXmlTest.php +++ b/tests/src/Kernel/Plugin/migrate_plus/data_parser/SimpleXmlTest.php @@ -1,16 +1,19 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate_plus\data_parser; use Drupal\KernelTests\KernelTestBase; use Drupal\migrate\MigrateException; +use Drupal\migrate_plus\DataParserPluginManager; /** * Test of the data_parser SimpleXml migrate_plus plugin. * * @group migrate_plus */ -class SimpleXmlTest extends KernelTestBase { +final class SimpleXmlTest extends KernelTestBase { /** * {@inheritdoc} @@ -19,31 +22,23 @@ class SimpleXmlTest extends KernelTestBase { /** * Path for the xml file. - * - * @var string */ - protected $path; + protected ?string $path; /** * The plugin manager. - * - * @var \Drupal\migrate_plus\DataParserPluginManager */ - protected $pluginManager; + protected ?DataParserPluginManager $pluginManager = NULL; /** * The plugin configuration. - * - * @var array */ - protected $configuration; + protected ?array $configuration; /** * The expected result. - * - * @var array */ - protected $expected; + protected ?array $expected; /** * {@inheritdoc} @@ -89,7 +84,7 @@ class SimpleXmlTest extends KernelTestBase { /** * Tests current URL of parsed XML item. */ - public function testCurrentUrl() { + public function testCurrentUrl(): void { $urls = [ $this->path . '/tests/data/simple_xml_current_url1.xml', $this->path . '/tests/data/simple_xml_current_url2.xml', @@ -214,7 +209,7 @@ class SimpleXmlTest extends KernelTestBase { * @param \Traversable $parser * An iterable data result to parse. */ - protected function assertResults($expected, \Traversable $parser) { + protected function assertResults($expected, \Traversable $parser): void { $data = []; foreach ($parser as $item) { $values = []; diff --git a/tests/src/Kernel/Plugin/migrate_plus/data_parser/XmlTest.php b/tests/src/Kernel/Plugin/migrate_plus/data_parser/XmlTest.php index 55ad3509d8b35bac60b8a0c60309c2b11528836b..18fc1f980cc6a6665199a803d57487c19537efe9 100644 --- a/tests/src/Kernel/Plugin/migrate_plus/data_parser/XmlTest.php +++ b/tests/src/Kernel/Plugin/migrate_plus/data_parser/XmlTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Kernel\Plugin\migrate_plus\data_parser; use Drupal\KernelTests\KernelTestBase; @@ -9,7 +11,7 @@ use Drupal\KernelTests\KernelTestBase; * * @group migrate_plus */ -class XmlTest extends KernelTestBase { +final class XmlTest extends KernelTestBase { protected static $modules = ['migrate', 'migrate_plus']; @@ -19,7 +21,7 @@ class XmlTest extends KernelTestBase { * @throws \Drupal\Component\Plugin\Exception\PluginException * @throws \Exception */ - public function testSingleValue() { + public function testSingleValue(): void { $path = $this->container ->get('module_handler') ->getModule('migrate_plus') diff --git a/tests/src/Unit/DataParserPluginBaseTest.php b/tests/src/Unit/DataParserPluginBaseTest.php index 3aea50e80b302f5493bc43cbab1a133d8b4fc8fa..f9a2d6e2dd13e6d52a04de5ddf30765815b4388b 100644 --- a/tests/src/Unit/DataParserPluginBaseTest.php +++ b/tests/src/Unit/DataParserPluginBaseTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit; use Drupal\migrate_plus\DataParserPluginBase; @@ -10,7 +12,7 @@ use Drupal\Tests\migrate\Unit\MigrateTestCase; * * @group migrate_plus */ -class DataParserPluginBaseTest extends MigrateTestCase { +final class DataParserPluginBaseTest extends MigrateTestCase { /** * @covers ::nextSource @@ -92,7 +94,7 @@ abstract class DataParserPluginBaseMock extends DataParserPluginBase { * * phpcs:disable Generic.CodeAnalysis.UselessOverridingMethod.Found */ - public function nextSource() { + public function nextSource(): bool { return parent::nextSource(); } diff --git a/tests/src/Unit/data_fetcher/FileTest.php b/tests/src/Unit/data_fetcher/FileTest.php index 746f44a66ed51024aba26c82b3e6fb0aea067e07..b83e8a1c4d28c29e2b7ce6bac29c925aa510178d 100644 --- a/tests/src/Unit/data_fetcher/FileTest.php +++ b/tests/src/Unit/data_fetcher/FileTest.php @@ -1,7 +1,10 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\data_fetcher; +use org\bovigo\vfs\vfsStreamDirectory; use Drupal\migrate\MigrateException; use Drupal\migrate_plus\Plugin\migrate_plus\data_fetcher\File; use Drupal\Tests\migrate\Unit\MigrateTestCase; @@ -17,21 +20,19 @@ use org\bovigo\vfs\vfsStream; * * @group migrate_plus */ -class FileTest extends MigrateTestCase { +final class FileTest extends MigrateTestCase { /** * Directory where test data will be created. * * @var string */ - const BASE_DIRECTORY = 'migration_data'; + public const BASE_DIRECTORY = 'migration_data'; /** * Minimal migration configuration data. - * - * @var array */ - private $specificMigrationConfig = [ + private array $specificMigrationConfig = [ 'source' => 'url', 'data_fetcher_plugin' => 'file', 'data_parser_plugin' => 'json', @@ -46,27 +47,21 @@ class FileTest extends MigrateTestCase { /** * The data fetcher plugin ID being tested. - * - * @var string */ - private $dataFetcherPluginId = 'file'; + private string $dataFetcherPluginId = 'file'; /** * The data fetcher plugin definition. - * - * @var array */ - private $pluginDefinition = [ + private array $pluginDefinition = [ 'id' => 'file', 'title' => 'File', ]; /** * Test data to populate a file with. - * - * @var string */ - private $testData = '[ + private string $testData = '[ { "id": 1, "name": "Joe Bloggs" @@ -75,10 +70,8 @@ class FileTest extends MigrateTestCase { /** * Define virtual dir where we'll be creating files in/fetching files from. - * - * @var \org\bovigo\vfs\vfsStreamDirectory */ - private $baseDir; + private vfsStreamDirectory $baseDir; /** * Set up test environment. @@ -92,7 +85,10 @@ class FileTest extends MigrateTestCase { */ public function testFetchFile(): void { $file_name = 'file.json'; - $file_path = vfsStream::url(implode(DIRECTORY_SEPARATOR, [self::BASE_DIRECTORY, $file_name])); + $file_path = vfsStream::url(implode(DIRECTORY_SEPARATOR, [ + self::BASE_DIRECTORY, + $file_name, + ])); $migration_config = $this->specificMigrationConfig + [ 'urls' => [$file_path], ]; @@ -109,8 +105,8 @@ class FileTest extends MigrateTestCase { vfsStream::create($tree, $this->baseDir); - $expected = json_decode($this->testData, TRUE); - $retrieved = json_decode($plugin->getResponseContent($file_path), TRUE); + $expected = json_decode($this->testData, TRUE, 512, JSON_THROW_ON_ERROR); + $retrieved = json_decode($plugin->getResponseContent($file_path), TRUE, 512, JSON_THROW_ON_ERROR); $this->assertEquals($expected, $retrieved); } @@ -126,7 +122,10 @@ class FileTest extends MigrateTestCase { for ($i = 0; $i < $number_of_files; $i++) { $file_name = 'file_' . $i . '.json'; $file_names[] = $file_name; - $file_paths[] = vfsStream::url(implode(DIRECTORY_SEPARATOR, [self::BASE_DIRECTORY, $file_name])); + $file_paths[] = vfsStream::url(implode(DIRECTORY_SEPARATOR, [ + self::BASE_DIRECTORY, + $file_name, + ])); } $migration_config = $this->specificMigrationConfig + [ @@ -149,8 +148,8 @@ class FileTest extends MigrateTestCase { vfsStream::create($tree, $this->baseDir); - $expected = json_decode($this->testData); - $retrieved = json_decode($plugin->getResponseContent($file_path)); + $expected = json_decode($this->testData, NULL, 512, JSON_THROW_ON_ERROR); + $retrieved = json_decode($plugin->getResponseContent($file_path), NULL, 512, JSON_THROW_ON_ERROR); $this->assertEquals($expected, $retrieved); } @@ -161,7 +160,10 @@ class FileTest extends MigrateTestCase { */ public function testFetchUnreadableFile(): void { $file_name = 'file.json'; - $file_path = vfsStream::url(implode(DIRECTORY_SEPARATOR, [self::BASE_DIRECTORY, $file_name])); + $file_path = vfsStream::url(implode(DIRECTORY_SEPARATOR, [ + self::BASE_DIRECTORY, + $file_name, + ])); $migration_config = $this->specificMigrationConfig + [ 'urls' => [$file_path], ]; diff --git a/tests/src/Unit/data_fetcher/HttpTest.php b/tests/src/Unit/data_fetcher/HttpTest.php index 48d3663cabff8f9bac33ea99a4fdd0caab7960fb..a35f09595db7d2b1639d72533ba6266021f7ea10 100644 --- a/tests/src/Unit/data_fetcher/HttpTest.php +++ b/tests/src/Unit/data_fetcher/HttpTest.php @@ -1,7 +1,11 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\data_fetcher; +use PHPUnit\Framework\MockObject\MockObject; +use Drupal\migrate_plus\AuthenticationPluginInterface; use Drupal\migrate\MigrateException; use Drupal\migrate_plus\DataFetcherPluginBase; use Drupal\migrate_plus\Plugin\migrate_plus\authentication\Basic; @@ -22,14 +26,12 @@ use GuzzleHttp\Psr7\Response; * * @group migrate_plus */ -class HttpTest extends MigrateTestCase { +final class HttpTest extends MigrateTestCase { /** * Minimal migration configuration data. - * - * @var array */ - private $specificMigrationConfig = [ + private array $specificMigrationConfig = [ 'source' => 'url', 'urls' => ['http://example.org/http_fetcher_test'], 'data_fetcher_plugin' => 'http', @@ -50,27 +52,21 @@ class HttpTest extends MigrateTestCase { /** * The data fetcher plugin ID being tested. - * - * @var string */ - private $dataFetcherPluginId = 'http'; + private string $dataFetcherPluginId = 'http'; /** * The data fetcher plugin definition. - * - * @var array */ - private $pluginDefinition = [ + private array $pluginDefinition = [ 'id' => 'http', 'title' => 'HTTP', ]; /** * Test data to validate an HTTP response against. - * - * @var string */ - private $testData = ' + private string $testData = ' { "id": 1, "name": "Joe Bloggs" @@ -79,19 +75,15 @@ class HttpTest extends MigrateTestCase { /** * Mocked up Basic authentication plugin. - * - * @var \PHPUnit_Framework_MockObject_MockObject */ - private $basicAuthenticator = NULL; + private ?MockObject $basicAuthenticator = NULL; /** * Set up test environment. */ public function setUp(): void { // Mock up a Basic authentication plugin that will be used in requests. - $basic_authenticator = $this->getMockBuilder(Basic::class) - ->disableOriginalConstructor() - ->getMock(); + $basic_authenticator = $this->createMock(Basic::class); $basic_authenticator->method('getAuthenticationOptions') ->will($this->returnValue([ @@ -117,10 +109,10 @@ class HttpTest extends MigrateTestCase { // http://docs.guzzlephp.org/en/latest/psr7.html $stream = $plugin->getResponseContent($migration_config['urls'][0]); - $body = json_decode((string) $stream, TRUE); + $body = json_decode((string) $stream, TRUE, 512, JSON_THROW_ON_ERROR); // Compare what we got back from the parser to what we expected to get. - $expected = json_decode($this->testData, TRUE); + $expected = json_decode($this->testData, TRUE, 512, JSON_THROW_ON_ERROR); $this->assertSame($expected, $body); } @@ -136,9 +128,9 @@ class HttpTest extends MigrateTestCase { $stream = $plugin->getResponseContent($migration_config['urls'][0]); - $body = json_decode((string) $stream, TRUE); + $body = json_decode((string) $stream, TRUE, 512, JSON_THROW_ON_ERROR); - $expected = json_decode($this->testData, TRUE); + $expected = json_decode($this->testData, TRUE, 512, JSON_THROW_ON_ERROR); $this->assertSame($expected, $body); } @@ -175,7 +167,7 @@ class HttpTest extends MigrateTestCase { /** * Test class to mock an HTTP request. */ -class TestHttp extends Http { +final class TestHttp extends Http { /** * Mocked authenticator plugin. @@ -193,7 +185,7 @@ class TestHttp extends Http { * @param object $authenticator * Mocked authenticator plugin. */ - public function mockHttpClient(array $responses, object $authenticator = NULL) { + public function mockHttpClient(array $responses, object $authenticator = NULL): void { // Set mocked authentication plugin to be used for the request auth plugin. $this->authenticator = $authenticator; @@ -230,10 +222,9 @@ class TestHttp extends Http { * * So we can mock the authentication plugin. * - * @return \PHPUnit_Framework_MockObject_MockObject * A mocked authentication plugin. */ - public function getAuthenticationPlugin() { + public function getAuthenticationPlugin(): AuthenticationPluginInterface { if (!isset($this->authenticationPlugin)) { $this->authenticationPlugin = $this->authenticator; } diff --git a/tests/src/Unit/process/ArrayPopTest.php b/tests/src/Unit/process/ArrayPopTest.php index c651f57c6615330ed11454c39d43a0b118309d98..dfb0c8b49a37b32829b837b1b1c2c603048aaec8 100644 --- a/tests/src/Unit/process/ArrayPopTest.php +++ b/tests/src/Unit/process/ArrayPopTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; use Drupal\migrate\MigrateException; @@ -12,7 +14,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\ArrayPop */ -class ArrayPopTest extends MigrateProcessTestCase { +final class ArrayPopTest extends MigrateProcessTestCase { /** * {@inheritdoc} diff --git a/tests/src/Unit/process/ArrayShiftTest.php b/tests/src/Unit/process/ArrayShiftTest.php index 1a8991a8853c9484c42a8725e361101795db5c48..96b9af6d849ac8cc4e6e953cb3a84f3c7cbbb6e6 100644 --- a/tests/src/Unit/process/ArrayShiftTest.php +++ b/tests/src/Unit/process/ArrayShiftTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; use Drupal\migrate\MigrateException; @@ -12,7 +14,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\ArrayShift */ -class ArrayShiftTest extends MigrateProcessTestCase { +final class ArrayShiftTest extends MigrateProcessTestCase { /** * {@inheritdoc} diff --git a/tests/src/Unit/process/DomApplyStylesTest.php b/tests/src/Unit/process/DomApplyStylesTest.php index 5ed3e5448d94b1812751d342e343c68d6254477f..adc8e99e59bc5c936228a6b2d2dbb2465c0c2ba5 100644 --- a/tests/src/Unit/process/DomApplyStylesTest.php +++ b/tests/src/Unit/process/DomApplyStylesTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; @@ -16,7 +18,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\DomApplyStyles */ -class DomApplyStylesTest extends MigrateProcessTestCase { +final class DomApplyStylesTest extends MigrateProcessTestCase { /** * Example configuration for the dom_apply_styles process plugin. @@ -40,10 +42,8 @@ class DomApplyStylesTest extends MigrateProcessTestCase { /** * Mock a config factory object. - * - * @var \Drupal\Core\Config\ConfigFactoryInterface */ - protected $configFactory = NULL; + protected ?object $configFactory = NULL; /** * {@inheritdoc} @@ -70,7 +70,7 @@ class DomApplyStylesTest extends MigrateProcessTestCase { * * @dataProvider providerTestConfig */ - public function testValidateRules(array $config_overrides, $message): void { + public function testValidateRules(array $config_overrides, string $message): void { $configuration = $config_overrides + $this->exampleConfiguration; $value = '<p>A simple paragraph.</p>'; $this->expectException(InvalidPluginDefinitionException::class); diff --git a/tests/src/Unit/process/DomMigrationLookupTest.php b/tests/src/Unit/process/DomMigrationLookupTest.php index 278eac22b5a4703c99b95c2397e9f7b674bc5f23..bc78dd245215be0637d512c08e0160aec73e3390 100644 --- a/tests/src/Unit/process/DomMigrationLookupTest.php +++ b/tests/src/Unit/process/DomMigrationLookupTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; @@ -17,7 +19,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\DomMigrationLookup */ -class DomMigrationLookupTest extends MigrateProcessTestCase { +final class DomMigrationLookupTest extends MigrateProcessTestCase { /** * Example configuration for the dom_migration_lookup process plugin. @@ -46,14 +48,14 @@ class DomMigrationLookupTest extends MigrateProcessTestCase { * * @var \Drupal\migrate\Plugin\MigrationInterface */ - protected $migration; + protected object $migration; /** * Mock a process plugin manager. * * @var \Drupal\migrate\Plugin\MigratePluginManagerInterface */ - protected $processPluginManager; + protected object $processPluginManager; /** * {@inheritdoc} @@ -107,7 +109,7 @@ class DomMigrationLookupTest extends MigrateProcessTestCase { * * @dataProvider providerTestConfigValidation */ - public function testConfigValidation(array $config_overrides, $message): void { + public function testConfigValidation(array $config_overrides, string $message): void { $configuration = $config_overrides + $this->exampleConfiguration; $value = '<p>A simple paragraph.</p>'; $this->expectException(InvalidPluginDefinitionException::class); diff --git a/tests/src/Unit/process/DomRemoveTest.php b/tests/src/Unit/process/DomRemoveTest.php index 76b9e6fa64f4681739fa12fbe7d92cc1321d66f2..94b47338e2eb199153b60b9414296acf9fdaf1f6 100644 --- a/tests/src/Unit/process/DomRemoveTest.php +++ b/tests/src/Unit/process/DomRemoveTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; use Drupal\Component\Utility\Html; @@ -12,7 +14,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\DomRemove */ -class DomRemoveTest extends MigrateProcessTestCase { +final class DomRemoveTest extends MigrateProcessTestCase { /** * @covers ::transform diff --git a/tests/src/Unit/process/DomSelectTest.php b/tests/src/Unit/process/DomSelectTest.php index 143777553685edea89f6cf3a970c61ac90778d13..7b596ba07f6914f1a301719da9a4d1f4018b75cd 100644 --- a/tests/src/Unit/process/DomSelectTest.php +++ b/tests/src/Unit/process/DomSelectTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; use Drupal\Component\Utility\Html; @@ -12,7 +14,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\DomSelect */ -class DomSelectTest extends MigrateProcessTestCase { +final class DomSelectTest extends MigrateProcessTestCase { /** * @covers ::transform diff --git a/tests/src/Unit/process/DomStrReplaceTest.php b/tests/src/Unit/process/DomStrReplaceTest.php index bdcd80369244b4a4c92727a75e6878387e71eefc..47dfb536b96c742656b5057114549e32170f1cc4 100644 --- a/tests/src/Unit/process/DomStrReplaceTest.php +++ b/tests/src/Unit/process/DomStrReplaceTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; @@ -14,7 +16,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\DomStrReplace */ -class DomStrReplaceTest extends MigrateProcessTestCase { +final class DomStrReplaceTest extends MigrateProcessTestCase { /** * Example configuration for the dom_str_replace process plugin. @@ -36,7 +38,7 @@ class DomStrReplaceTest extends MigrateProcessTestCase { * * @dataProvider providerTestConfigEmpty */ - public function testConfigValidation(array $config_overrides, $message): void { + public function testConfigValidation(array $config_overrides, string $message): void { $configuration = $config_overrides + $this->exampleConfiguration; $value = '<p>A simple paragraph.</p>'; $this->expectException(InvalidPluginDefinitionException::class); diff --git a/tests/src/Unit/process/DomTest.php b/tests/src/Unit/process/DomTest.php index 78abf8587aae04d29186c7fa1eb2864edb285a8b..d87be09373c8cb00f7221c08cf4fd6d198b4e2bd 100644 --- a/tests/src/Unit/process/DomTest.php +++ b/tests/src/Unit/process/DomTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; use Drupal\Component\Utility\Html; @@ -13,7 +15,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\Dom */ -class DomTest extends MigrateProcessTestCase { +final class DomTest extends MigrateProcessTestCase { /** * @covers ::__construct @@ -31,6 +33,7 @@ class DomTest extends MigrateProcessTestCase { * @covers ::__construct */ public function testConfigMethodInvalid(): void { + $configuration = []; $configuration['method'] = 'invalid'; $value = '<p>A simple paragraph.</p>'; $this->expectException(\InvalidArgumentException::class); @@ -43,6 +46,7 @@ class DomTest extends MigrateProcessTestCase { * @covers ::import */ public function testImportNonRoot(): void { + $configuration = []; $configuration['method'] = 'import'; $value = '<p>A simple paragraph.</p>'; $document = (new Dom($configuration, 'dom', [])) @@ -54,6 +58,7 @@ class DomTest extends MigrateProcessTestCase { * @covers ::import */ public function testImportNonRootInvalidInput(): void { + $configuration = []; $configuration['method'] = 'import'; $value = [1, 1]; $this->expectException(MigrateException::class); @@ -66,6 +71,7 @@ class DomTest extends MigrateProcessTestCase { * @covers ::export */ public function testExportNonRoot(): void { + $configuration = []; $configuration['method'] = 'export'; $partial = '<p>A simple paragraph.</p>'; $document = Html::load($partial); @@ -78,6 +84,7 @@ class DomTest extends MigrateProcessTestCase { * @covers ::export */ public function testExportNonRootInvalidInput(): void { + $configuration = []; $configuration['method'] = 'export'; $this->expectException(MigrateException::class); $this->expectExceptionMessage('Cannot export a "string".'); diff --git a/tests/src/Unit/process/GateTest.php b/tests/src/Unit/process/GateTest.php index 79c7ae60c865b256f1140126f6c40958ebcedd87..c4c4a33011a6edcb27a5cd2c916cb0dc97833e7a 100644 --- a/tests/src/Unit/process/GateTest.php +++ b/tests/src/Unit/process/GateTest.php @@ -1,8 +1,9 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; -use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateSkipProcessException; use Drupal\migrate\Row; use Drupal\migrate_plus\Plugin\migrate\process\Gate; @@ -14,7 +15,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\Gate */ -class GateTest extends MigrateProcessTestCase { +final class GateTest extends MigrateProcessTestCase { /** * Test Gate plugin. @@ -42,10 +43,8 @@ class GateTest extends MigrateProcessTestCase { /** * Row and plugin configuration for tests. - * - * @return array */ - public function gateProvider() { + public function gateProvider(): array { return [ 'Gate does not unlock' => [ [ @@ -155,7 +154,7 @@ class GateTest extends MigrateProcessTestCase { * * @dataProvider badConfigurationProvider */ - public function testGateBadConfiguration($configuration, $message): void { + public function testGateBadConfiguration($configuration, string $message): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage($message); new Gate($configuration, 'gate', []); @@ -163,10 +162,8 @@ class GateTest extends MigrateProcessTestCase { /** * Provider for bad configuration. - * - * @return array */ - public function badConfigurationProvider() { + public function badConfigurationProvider(): array { return [ 'Missing use_as_key' => [ [ @@ -203,4 +200,5 @@ class GateTest extends MigrateProcessTestCase { ], ]; } + } diff --git a/tests/src/Unit/process/MultipleValuesTest.php b/tests/src/Unit/process/MultipleValuesTest.php index 604d3c61249b9e09b6bafa318723081943c9245a..77f211ab38c55a1f98b2c90cfc30847f7fd08db2 100644 --- a/tests/src/Unit/process/MultipleValuesTest.php +++ b/tests/src/Unit/process/MultipleValuesTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; use Drupal\migrate_plus\Plugin\migrate\process\MultipleValues; @@ -9,7 +11,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\MultipleValues * @group migrate */ -class MultipleValuesTest extends MigrateProcessTestCase { +final class MultipleValuesTest extends MigrateProcessTestCase { /** * {@inheritdoc} diff --git a/tests/src/Unit/process/SingleValueTest.php b/tests/src/Unit/process/SingleValueTest.php index fe8d0748361a246edb65a7f44d20704cac2e1821..520bffa70180a8b4e792550b2f2e59b89222e209 100644 --- a/tests/src/Unit/process/SingleValueTest.php +++ b/tests/src/Unit/process/SingleValueTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; use Drupal\migrate_plus\Plugin\migrate\process\SingleValue; @@ -9,7 +11,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\SingleValue * @group migrate */ -class SingleValueTest extends MigrateProcessTestCase { +final class SingleValueTest extends MigrateProcessTestCase { /** * {@inheritdoc} diff --git a/tests/src/Unit/process/SkipOnValueTest.php b/tests/src/Unit/process/SkipOnValueTest.php index cea468d2bce0b7bdd0011e869af5c85b35355310..f5bda750c40efda2a6e6b8f054256530f448e543 100644 --- a/tests/src/Unit/process/SkipOnValueTest.php +++ b/tests/src/Unit/process/SkipOnValueTest.php @@ -1,8 +1,9 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; -use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateSkipProcessException; use Drupal\migrate\MigrateSkipRowException; use Drupal\migrate_plus\Plugin\migrate\process\SkipOnValue; @@ -14,12 +15,13 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\SkipOnValue */ -class SkipOnValueTest extends MigrateProcessTestCase { +final class SkipOnValueTest extends MigrateProcessTestCase { /** * @covers ::process */ public function testProcessSkipsOnValue(): void { + $configuration = []; $configuration['method'] = 'process'; $configuration['value'] = 86; $this->expectException(MigrateSkipProcessException::class); @@ -31,6 +33,7 @@ class SkipOnValueTest extends MigrateProcessTestCase { * @covers ::process */ public function testProcessSkipsOnMultipleValue(): void { + $configuration = []; $configuration['method'] = 'process'; $configuration['value'] = [1, 1, 2, 3, 5, 8]; $this->expectException(MigrateSkipProcessException::class); @@ -42,6 +45,7 @@ class SkipOnValueTest extends MigrateProcessTestCase { * @covers ::process */ public function testProcessBypassesOnNonValue(): void { + $configuration = []; $configuration['method'] = 'process'; $configuration['value'] = 'sourcevalue'; $configuration['not_equals'] = TRUE; @@ -58,6 +62,7 @@ class SkipOnValueTest extends MigrateProcessTestCase { * @covers ::process */ public function testProcessSkipsOnMultipleNonValue(): void { + $configuration = []; $configuration['method'] = 'process'; $configuration['value'] = [1, 1, 2, 3, 5, 8]; $value = (new SkipOnValue($configuration, 'skip_on_value', [])) @@ -69,6 +74,7 @@ class SkipOnValueTest extends MigrateProcessTestCase { * @covers ::process */ public function testProcessBypassesOnMultipleNonValue(): void { + $configuration = []; $configuration['method'] = 'process'; $configuration['value'] = [1, 1, 2, 3, 5, 8]; $configuration['not_equals'] = TRUE; @@ -84,6 +90,7 @@ class SkipOnValueTest extends MigrateProcessTestCase { * @covers ::row */ public function testRowBypassesOnMultipleNonValue(): void { + $configuration = []; $configuration['method'] = 'row'; $configuration['value'] = [1, 1, 2, 3, 5, 8]; $configuration['not_equals'] = TRUE; @@ -99,6 +106,7 @@ class SkipOnValueTest extends MigrateProcessTestCase { * @covers ::row */ public function testRowSkipsOnValue(): void { + $configuration = []; $configuration['method'] = 'row'; $configuration['value'] = 86; $this->expectException(MigrateSkipRowException::class); @@ -111,7 +119,7 @@ class SkipOnValueTest extends MigrateProcessTestCase { * * @covers ::row */ - public function testRowSkipWithMessage() { + public function testRowSkipWithMessage(): void { $configuration = [ 'method' => 'row', 'value' => 86, @@ -127,6 +135,7 @@ class SkipOnValueTest extends MigrateProcessTestCase { * @covers ::row */ public function testRowBypassesOnNonValue(): void { + $configuration = []; $configuration['method'] = 'row'; $configuration['value'] = 'sourcevalue'; $configuration['not_equals'] = TRUE; @@ -142,7 +151,8 @@ class SkipOnValueTest extends MigrateProcessTestCase { /** * @covers ::__construct */ - public function testRequiredConfiguration() { + public function testRequiredConfiguration(): void { + $configuration = []; // It doesn't meter which method we will put here, because it should throw // error on contraction of Plugin. $configuration['method'] = 'row'; diff --git a/tests/src/Unit/process/StrReplaceTest.php b/tests/src/Unit/process/StrReplaceTest.php index 6f306dfa3825b8712fd62dec1220c9e319859c7f..320c4c9ffb6e98ae53ca73316cd8e471138c5c0d 100644 --- a/tests/src/Unit/process/StrReplaceTest.php +++ b/tests/src/Unit/process/StrReplaceTest.php @@ -1,8 +1,9 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; -use Drupal\migrate\MigrateException; use Drupal\migrate_plus\Plugin\migrate\process\StrReplace; use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; @@ -12,12 +13,13 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\StrReplace */ -class StrReplaceTest extends MigrateProcessTestCase { +final class StrReplaceTest extends MigrateProcessTestCase { /** * Test for a simple str_replace string. */ public function testStrReplace(): void { + $configuration = []; $value = 'vero eos et accusam et justo vero'; $configuration['search'] = 'et'; $configuration['replace'] = 'that'; @@ -31,6 +33,7 @@ class StrReplaceTest extends MigrateProcessTestCase { * Test for case insensitive searches. */ public function testStrIreplace(): void { + $configuration = []; $value = 'VERO eos et accusam et justo vero'; $configuration['search'] = 'vero'; $configuration['replace'] = 'that'; @@ -45,6 +48,7 @@ class StrReplaceTest extends MigrateProcessTestCase { * Test for regular expressions. */ public function testPregReplace(): void { + $configuration = []; $value = 'vero eos et 123 accusam et justo 123 duo'; $configuration['search'] = '/[0-9]{3}/'; $configuration['replace'] = 'the'; @@ -58,6 +62,7 @@ class StrReplaceTest extends MigrateProcessTestCase { * Test for InvalidArgumentException for "search" configuration. */ public function testSearchInvalidArgumentException(): void { + $configuration = []; $configuration['replace'] = 'that'; $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "search" must be set.'); @@ -68,6 +73,7 @@ class StrReplaceTest extends MigrateProcessTestCase { * Test for InvalidArgumentException for "replace" configuration. */ public function testReplaceInvalidArgumentException(): void { + $configuration = []; $configuration['search'] = 'et'; $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The "replace" must be set.'); @@ -78,6 +84,7 @@ class StrReplaceTest extends MigrateProcessTestCase { * Test for multiple. */ public function testIsMultiple(): void { + $configuration = []; $value = [ 'vero eos et accusam et justo vero', 'et eos vero accusam vero justo et', diff --git a/tests/src/Unit/process/TransliterationTest.php b/tests/src/Unit/process/TransliterationTest.php deleted file mode 100644 index f38bde0f0f5f67d275febc64907647668950c85d..0000000000000000000000000000000000000000 --- a/tests/src/Unit/process/TransliterationTest.php +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -namespace Drupal\Tests\migrate_plus\Unit\process; - -use Drupal\Component\Transliteration\PhpTransliteration; -use Drupal\migrate\MigrateExecutableInterface; -use Drupal\migrate\Row; -use Drupal\migrate_plus\Plugin\migrate\process\Transliteration; -use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; - -/** - * Tests the transliteration process plugin. - * - * @group migrate_plus - */ -class TransliterationTest extends MigrateProcessTestCase { - - /** - * A transliteration instance. - * - * @var \Drupal\Component\Transliteration\TransliterationInterface - */ - protected $transliteration; - - /** - * {@inheritdoc} - */ - protected function setUp(): void { - $this->transliteration = new PhpTransliteration(); - $this->row = $this->getMockBuilder(Row::class) - ->disableOriginalConstructor() - ->getMock(); - $this->migrateExecutable = $this->getMockBuilder(MigrateExecutableInterface::class) - ->disableOriginalConstructor() - ->getMock(); - parent::setUp(); - } - - /** - * Tests transliteration transformation of non-alphanumeric characters. - */ - public function testTransform(): void { - $actual = '9000004351_53494854_Spøgelsesjægerneáéö'; - $expected_result = '9000004351_53494854_Spogelsesjaegerneaeo'; - - $plugin = new Transliteration([], 'transliteration', [], $this->transliteration); - $value = $plugin->transform($actual, $this->migrateExecutable, $this->row, 'destinationproperty'); - $this->assertEquals($expected_result, $value); - } - - /** - * Tests deprecation notice of Transliteration process plugin. - * - * @group legacy - */ - public function testDeprecationMessage() { - $this->expectDeprecation("Drupal\migrate_plus\Plugin\migrate\process\Transliteration is deprecated in migrate_plus:8.x-5.3 and is removed from migrate_plus:6.0.0. Use Drupal\migrate_plus\Plugin\migrate\process\Service process plugin instead. See https://www.drupal.org/node/3255994"); - new Transliteration([], 'transliteration', [], $this->transliteration); - } - -} diff --git a/tests/src/Unit/process/TransposeTest.php b/tests/src/Unit/process/TransposeTest.php index 453b602cf892bab9e04d1233108f62889e50b0c3..6bdf3e7efabac7968cbb205be5b598aea7301d32 100644 --- a/tests/src/Unit/process/TransposeTest.php +++ b/tests/src/Unit/process/TransposeTest.php @@ -1,5 +1,7 @@ <?php +declare(strict_types = 1); + namespace Drupal\Tests\migrate_plus\Unit\process; use Drupal\migrate_plus\Plugin\migrate\process\Transpose; @@ -11,7 +13,7 @@ use Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase; * @group migrate * @coversDefaultClass \Drupal\migrate_plus\Plugin\migrate\process\Transpose */ -class TransposeTest extends MigrateProcessTestCase { +final class TransposeTest extends MigrateProcessTestCase { /** * {@inheritdoc}