diff -u b/gist_filter.module b/gist_filter.module --- b/gist_filter.module +++ b/gist_filter.module @@ -15,7 +15,7 @@ function gist_filter_theme() { - return array( - 'gist_filter_code' => array( - 'variables' => array('file' => array()), - ), - ); + return [ + 'gist_filter_code' => [ + 'variables' => ['file' => []], + ], + ]; } diff -u b/src/GistFilterCacheDecoratorClient.php b/src/GistFilterCacheDecoratorClient.php --- b/src/GistFilterCacheDecoratorClient.php +++ b/src/GistFilterCacheDecoratorClient.php @@ -1,30 +1,26 @@ httpClient = $http_client; + public function __construct(ClientFactory $http_client) { + $this->httpClientFactory = $http_client; } /** @@ -41,7 +37,7 @@ public function getGist($id) { try { $url = 'https://api.github.com/gists/' . $id; - $response = $this->httpClient->request('GET', $url, array('headers' => array('Accept' => 'application/json'))); + $response = $this->httpClientFactory->fromOptions()->request('GET', $url, ['headers' => ['Accept' => 'application/json']]); $data = (string) $response->getBody(); } catch (RequestException $e) { diff -u b/src/GitHubRequestException.php b/src/GitHubRequestException.php --- b/src/GitHubRequestException.php +++ b/src/GitHubRequestException.php @@ -1,10 +1,5 @@ gitHubClient = $github_client; $this->renderer = $renderer; @@ -86,9 +83,9 @@ */ public function process($text, $language) { - $text = preg_replace_callback('@\[gist\:(?[\w/]+)(?:\:(?[\w\.]+))?\]@', array($this, gistDisplayEmbed), $text); - $text = preg_replace_callback('@\[gistcode\:(?[\w/]+)(?:\:(?[\w\.]+))?\]@', array($this, gistDisplayCode), $text); - $text = preg_replace_callback('@\[gistlink\:(?[\w/]+)(?:\:(?[\w\.]+))?\]@', array($this, gistDisplayLink), $text); + $text = preg_replace_callback('@\[gist\:(?[\w/]+)(?:\:(?[\w\.]+))?\]@', [$this, 'gistDisplayEmbed'], $text); + $text = preg_replace_callback('@\[gistcode\:(?[\w/]+)(?:\:(?[\w\.]+))?\]@', [$this, 'gistDisplayCode'], $text); + $text = preg_replace_callback('@\[gistlink\:(?[\w/]+)(?:\:(?[\w\.]+))?\]@', [$this, 'gistDisplayLink'], $text); return new FilterProcessResult($text); } @@ -96,16 +93,15 @@ /** * {@inheritdoc} */ - public function tips($long = true) { + public function tips($long = TRUE) { - $output = $this->t('Use [gist:#####] for using the default embed method.', '
'; - $output = $this->t('You can use [gist:#####] for displaying just the code of your gist, or [gistlink:#####] for displaying the link of your gist.', '
'; - $output.= $this->t('You may also include a specific file within a multi-file gist with [gist:####:my_file].'); + $output = $this->t('Use [gist:#####] for using the default embed method.', '
'); + $output .= $this->t('You can use [gist:#####] for displaying just the code of your gist, or [gistlink:#####] for displaying the link of your gist.', '
'); + $output .= $this->t('You may also include a specific file within a multi-file gist with [gist:####:my_file].'); return $output; } - /** * Replace the text with the content of the Gist, wrapped in
 tags.
    */
@@ -117,19 +113,19 @@
       $build = [];
       // If a file was specified, just render that one file.
       if (isset($matches['file']) && !empty($matches['file']) && isset($data['files'][$matches['file']])) {
-        $build[] = array(
+        $build[] = [
           '#theme' => 'gist_filter_code',
           '#file' => $data['files'][$matches['file']],
-        );
+        ];
 
       }
       // Otherwise, render all files.
       else {
         foreach ($data['files'] as $file) {
-          $build[] = array(
+          $build[] = [
             '#theme' => 'gist_filter_code',
             '#file' => $file,
-          );
+          ];
         }
       }
 
@@ -137,7 +133,7 @@
 
     }
     catch (GitHubRequestException $e) {
-      $this->logger->notice('Error retrieving gist %gist: %error', array('%gist' => $matches['id'], '%error' => $e->getMessage()));
+      $this->logger->notice('Error retrieving gist %gist: %error', ['%gist' => $matches['id'], '%error' => $e->getMessage()]);
     }
   }
 
@@ -150,7 +146,10 @@
       ? $gist_url . '.js?file=' . $matches['file']
       : $gist_url . '.js';
 
-    // Also grab the content and display it in code tags (in case the user does not have JS).
+    /*
+    * Also grab the content and display it in code tags (in case the user does
+    * not have JS).
+    */
     $output = '';
     $output .= '';
 
diff -u b/src/Tests/GistFilterTestCase.php b/src/Tests/GistFilterTestCase.php
--- b/src/Tests/GistFilterTestCase.php
+++ b/src/Tests/GistFilterTestCase.php
@@ -1,15 +1,9 @@
 contentType = $this->drupalCreateContentType();
 
     // Create and log in our user.
-    $this->user = $this->drupalCreateUser(array(
+    $this->user = $this->drupalCreateUser([
       'create ' . $this->contentType->id() . ' content',
       'administer filters',
-    ));
+    ]);
     $this->drupalLogin($this->user);
   }
 
@@ -48,16 +42,14 @@
    */
   public function testEmbedStyle() {
     // Turn on our input filter and set the option to embed.
-    $edit = array(
-      'filters[gist_filter][status]' => 1,
-    );
+    $edit = ['filters[gist_filter][status]' => 1];
 
     $this->drupalPostForm('admin/config/content/formats/manage/plain_text', $edit, t('Save configuration'));
 
-    $edit = array(
+    $edit = [
       'title[0][value]' => $this->randomMachineName(),
       'body[0][value]' => 'Hello! [gist:865412]',
-    );
+    ];
 
     $this->drupalPostForm('node/add/' . $this->contentType->id(), $edit, t('Save'));
     $this->assertResponse(200);
@@ -71,16 +63,14 @@
    */
   public function testEmbedStyleWithFile() {
     // Turn on our input filter and set the option to embed.
-    $edit = array(
-      'filters[gist_filter][status]' => 1,
-    );
+    $edit = ['filters[gist_filter][status]' => 1];
 
     $this->drupalPostForm('admin/config/content/formats/manage/plain_text', $edit, t('Save configuration'));
 
-    $edit = array(
+    $edit = [
       'title[0][value]' => $this->randomMachineName(),
       'body[0][value]' => 'Hello! [gist:865412:php_file.php]',
-    );
+    ];
 
     $this->drupalPostForm('node/add/' . $this->contentType->id(), $edit, t('Save'));
     $this->assertResponse(200);
@@ -95,16 +85,14 @@
   public function testLinkStyle() {
 
     // Turn on our input filter and set the option to link.
-    $edit = array(
-      'filters[gist_filter][status]' => 1,
-    );
+    $edit = ['filters[gist_filter][status]' => 1];
 
     $this->drupalPostForm('admin/config/content/formats/manage/plain_text', $edit, t('Save configuration'));
 
-    $edit = array(
+    $edit = [
       'title[0][value]' => $this->randomMachineName(),
       'body[0][value]' => 'Hello! [gistlink:865412]',
-    );
+    ];
 
     $this->drupalPostForm('node/add/' . $this->contentType->id(), $edit, t('Save'));
     $this->assertResponse(200);
@@ -118,16 +106,14 @@
   public function testLinkStyleWithFile() {
 
     // Turn on our input filter.
-    $edit = array(
-      'filters[gist_filter][status]' => 1,
-    );
+    $edit = ['filters[gist_filter][status]' => 1];
 
     $this->drupalPostForm('admin/config/content/formats/manage/plain_text', $edit, t('Save configuration'));
 
-    $edit = array(
+    $edit = [
       'title[0][value]' => $this->randomMachineName(),
       'body[0][value]' => 'Hello! [gistlink:865412:php_file.php]',
-    );
+    ];
 
     $this->drupalPostForm('node/add/' . $this->contentType->id(), $edit, t('Save'));
     $this->assertResponse(200);
@@ -141,16 +127,14 @@
   public function testCodeTagStyle() {
 
     // Turn on our input filter.
-    $edit = array(
-      'filters[gist_filter][status]' => 1,
-    );
+    $edit = ['filters[gist_filter][status]' => 1];
 
     $this->drupalPostForm('admin/config/content/formats/manage/plain_text', $edit, t('Save configuration'));
 
-    $edit = array(
+    $edit = [
       'title[0][value]' => $this->randomMachineName(),
       'body[0][value]' => 'Hello! [gistcode:865412]',
-    );
+    ];
 
     $this->drupalPostForm('node/add/' . $this->contentType->id(), $edit, t('Save'));
     $this->assertResponse(200);
diff -u b/templates/gist-filter-code.html.twig b/templates/gist-filter-code.html.twig
--- b/templates/gist-filter-code.html.twig
+++ b/templates/gist-filter-code.html.twig
@@ -19 +19,2 @@
-
\ No newline at end of file
+
+
diff -u b/tests/src/Unit/GistFilterCacheDecoratorClientTest.php b/tests/src/Unit/GistFilterCacheDecoratorClientTest.php
--- b/tests/src/Unit/GistFilterCacheDecoratorClientTest.php
+++ b/tests/src/Unit/GistFilterCacheDecoratorClientTest.php
@@ -1,10 +1,5 @@
 method('request')
       ->will($this->returnValue($response));
 
-    $client = new GistFilterGitHubClient($httpClient);
+    $httpClientFactory = $this->getMockBuilder('\Drupal\Core\Http\ClientFactory')
+      ->disableOriginalConstructor()
+      ->getMock();
+
+    $httpClientFactory->expects($this->once())
+      ->method('fromOptions')
+      ->will($this->returnValue($httpClient));
+
+    $client = new GistFilterGitHubClient($httpClientFactory););
     $client->getGist('foo');
 
   }
@@ -78,12 +82,12 @@
 
 
   /**
-   * Generates a GuzzleClient with the mocked responses.
+   * Generates a Drupal\Core\Http\ClientFactory with the mocked responses.
    *
    * @param array $responses
    *   Collection of responses returned by the client.
    *
-   * @return GuzzleClient
+   * @return \Drupal\Core\Http\ClientFactory
    */
   protected function getHttpClient(array $responses = []) {
     if (empty($responses)) {
@@ -92,7 +96,7 @@
 
     $this->mock = new MockHandler($responses);
     $handlerStack = HandlerStack::create($this->mock);
-    $guzzle = new GuzzleClient(array('handler' => $handlerStack));
+    $guzzle = new GuzzleClient(['handler' => $handlerStack]);
 
     return $guzzle;
   }
only in patch2:
unchanged:
--- /dev/null
+++ b/gist_filter.services.yml
@@ -0,0 +1,9 @@
+services:
+  gist_filter_github_client:
+    class: Drupal\gist_filter\GistFilterGitHubClient
+    arguments: ['@http_client_factory']
+
+  gist_filter_cached_github_client:
+    class: Drupal\gist_filter\GistFilterCacheDecoratorClient
+    arguments: ['@gist_filter_github_client', '@cache.default']
+