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.
Passed
Push — 8.x-4.x-212 ( cd2d20 )
by Brant
12:06
created

ArticleNodeEndpointBlock   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 10 1
A create() 0 6 1
A __construct() 0 3 1
1
<?php
2
3
namespace Drupal\df_tools_articles\Plugin\Block;
4
5
use Drupal\Core\Block\BlockBase;
6
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use GuzzleHttp\Client;
9
10
/**
11
 * Provides a 'ArticleNodeEndpointBlock' block.
12
 *
13
 * @Block(
14
 *  id = "article_node_endpoint_block",
15
 *  admin_label = @Translation("Article node endpoint block"),
16
 *  category = "Lists",
17
 * )
18
 */
19
class ArticleNodeEndpointBlock extends BlockBase implements ContainerFactoryPluginInterface {
20
21
  /**
22
   * GuzzleHttp\Client definition.
23
   *
24
   * @var \GuzzleHttp\Client
25
   */
26
  protected $httpClient;
27
28
  /**
29
   * CollectionNodeEndpointBlock constructor.
30
   * @param array $configuration
31
   * @param string $plugin_id
32
   * @param mixed $plugin_definition
33
   * @param \GuzzleHttp\Client $http_client
34
   */
35
  public function __construct(array $configuration, $plugin_id, $plugin_definition, Client $http_client) {
36
    parent::__construct($configuration, $plugin_id, $plugin_definition);
37
    $this->httpClient = $http_client;
38
  }
39
40
  /**
41
   * {@inheritdoc}
42
   */
43
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
44
    return new static(
45
      $configuration,
46
      $plugin_id,
47
      $plugin_definition,
48
      $container->get('http_client')
0 ignored issues
show
Bug introduced by
It seems like $container->get('http_client') can also be of type null; however, parameter $http_client of Drupal\df_tools_articles...intBlock::__construct() does only seem to accept GuzzleHttp\Client, maybe add an additional type check? ( Ignorable by Annotation )

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

48
      /** @scrutinizer ignore-type */ $container->get('http_client')
Loading history...
49
    );
50
  }
51
52
  /**
53
   * {@inheritdoc}
54
   */
55
  public function build() {
56
    $build = array();
57
    global $base_url;
58
    header('Content-Type: application/json');
59
    $json_output = (string) $this->httpClient->get($base_url . '/api/node/article')->getBody();
60
    $json_pretty = json_encode(json_decode($json_output), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
61
    $json_indented_by_2 = preg_replace('/^(  +?)\\1(?=[^ ])/m', '$1', $json_pretty);
62
    $build['article_node_endpoint_block']['#markup'] = '<a data-toggle="language-json" class="button small">Expand Code</a> <div id="language-json" class="api-demo" data-toggler=".expanded"><pre><code class="language-json">' . $json_indented_by_2 . '</code></pre></div>';
63
    $build['article_node_endpoint_block']['#attached']['library'][] = 'df_tools_articles/main';
64
    return $build;
65
  }
66
67
}
68