GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ImageMigrationTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 13
dl 0
loc 40
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A setImageProperty() 0 16 2
1
<?php
2
3
namespace Drupal\df_tools_migration\Plugin\migrate\source;
4
5
use Drupal\migrate\Row;
6
7
/**
8
 * Provides shared methods for processing image migrations in Source Plugins.
9
 */
10
trait ImageMigrationTrait {
11
12
  /**
13
   * Configuration information passed into the plugin.
14
   *
15
   * @var array
16
   */
17
  protected $configuration;
18
19
  /**
20
   * The entity migration object.
21
   *
22
   * @var \Drupal\migrate\Entity\MigrationInterface
0 ignored issues
show
Bug introduced by
The type Drupal\migrate\Entity\MigrationInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
   */
24
  protected $migration;
25
26
27
  /**
28
   * Sets an image field and alt text in a migration based on the source
29
   * property (the name of the file).
30
   *
31
   * @param \Drupal\migrate\Row $row
32
   * @param string $source_property
33
   */
34
  protected function setImageProperty(Row $row, $source_property) {
35
    if ($value = $row->getSourceProperty($source_property)) {
36
      $path = dirname($this->configuration['path']) . '/images/' . $value;
37
      $data = file_get_contents($path);
38
      $uri = file_build_uri($value);
39
      $file = file_save_data($data, $uri);
40
41
      // Calculate alt text based on the filename.
42
      $alt_text = ucwords(str_replace(['_', '-'], ' ', preg_replace('/\..*/', '', $value)));
43
44
      $item = [[
45
        'target_id' => $file->id(),
46
        'alt' => $alt_text
47
      ]];
48
49
      $row->setSourceProperty($source_property, $item);
50
    }
51
  }
52
53
}
54