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.

DfToolsPanelizerCommands   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 16
c 1
b 0
f 0
dl 0
loc 44
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A panelizerExport() 0 25 3
1
<?php
2
3
namespace Drupal\df_tools_panelizer\Commands;
4
5
use Drush\Commands\DrushCommands;
6
7
/**
8
 * A Drush commandfile.
9
 *
10
 * In addition to this file, you need a drush.services.yml
11
 * in root of your module, and a composer.json file that provides the name
12
 * of the services file to use.
13
 *
14
 * See these files for an example of injecting Drupal services:
15
 *   - http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
16
 *   - http://cgit.drupalcode.org/devel/tree/drush.services.yml
17
 */
18
class DfToolsPanelizerCommands extends DrushCommands {
19
20
  /**
21
   * Exports a given Node's Panelizer Display to a pseudo-config file.
22
   *
23
   * @param $nid
24
   *   The ID of the override Node.
25
   * @param $scenario
26
   *   The target Scenario.
27
   * @usage df-pe 1 dfs_tec
28
   *   Export the Panels Display of Node 1 to the given scenario's data directory.
29
   * @validate-module-enabled panelizer,df_tools_panelizer
30
   *
31
   * @command df:panelizer-export
32
   * @aliases df-pe,df-panelizer-export
33
   *
34
   * @return bool
35
   * @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
36
   */
37
  public function panelizerExport($nid, $scenario) {
38
    // Load the Node.
39
    $node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
40
41
    // Check if it is Panelized.
42
    if ($node->panelizer) {
0 ignored issues
show
Bug introduced by
Accessing panelizer on the interface Drupal\Core\Entity\EntityInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
43
      // Get the path to the current scenario.
44
      $base_path = drupal_get_path('module', $scenario);
45
      if (!$base_path) {
46
        drupal_set_message(t('The scenario @scenario is not installed.', ['@scenario' => $scenario]), 'error');
0 ignored issues
show
Deprecated Code introduced by
The function drupal_set_message() has been deprecated: in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

46
        /** @scrutinizer ignore-deprecated */ drupal_set_message(t('The scenario @scenario is not installed.', ['@scenario' => $scenario]), 'error');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
47
        return FALSE;
48
      }
49
50
      // Write YAML to a file.
51
      $panels_file = $base_path . '/data/panelizer.panels_display.node.'.$node->uuid() . '.yml';
52
      $configuration = \Drupal::service('panelizer')->getPanelsDisplay($node, 'full')->getConfiguration();
53
      $yaml = \Symfony\Component\Yaml\Yaml::dump($configuration, 99, 2);
54
      file_put_contents($panels_file, $yaml);
55
56
      drupal_set_message(t('Successfully exported Panelizer display for Node @nid to @panels_file', ['@nid' => $node->id(), '@panels_file' => $panels_file]));
0 ignored issues
show
Deprecated Code introduced by
The function drupal_set_message() has been deprecated: in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

56
      /** @scrutinizer ignore-deprecated */ drupal_set_message(t('Successfully exported Panelizer display for Node @nid to @panels_file', ['@nid' => $node->id(), '@panels_file' => $panels_file]));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
57
      return TRUE;
58
    }
59
    else {
60
      drupal_set_message(t('The given Node is not Panelized.'), 'error');
0 ignored issues
show
Deprecated Code introduced by
The function drupal_set_message() has been deprecated: in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

60
      /** @scrutinizer ignore-deprecated */ drupal_set_message(t('The given Node is not Panelized.'), 'error');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
61
      return FALSE;
62
    }
63
  }
64
65
}
66