GithubMarkdownAdapter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 48
ccs 16
cts 16
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A transformText() 0 19 2
1
<?php
2
3
namespace MaglMarkdown\Adapter;
4
5
use MaglMarkdown\Adapter\Options\GithubMarkdownOptions;
6
use Zend\Http\Client;
7
use Zend\Http\Request;
8
9
/**
10
 * This is an implementation that uses github's markdown API to render Markdown
11
 *
12
 *
13
 * @see    https://developer.github.com/v3/
14
 * @see    https://developer.github.com/v3/markdown/
15
 * @author Matthias Glaub <[email protected]>
16
 */
17
class GithubMarkdownAdapter implements MarkdownAdapterInterface
18
{
19
20
    /**
21
     *
22
     * @var Client
23
     */
24
    private $httpClient;
25
26
    /**
27
     *
28
     * @var GithubMarkdownOptions
29
     */
30
    private $options;
31
32
    /**
33
     *
34
     * @var Request
35
     */
36
    private $request;
37
38 2
    public function __construct(Client $httpClient, Request $request, GithubMarkdownOptions $options)
39
    {
40 2
        $this->httpClient = $httpClient;
41 2
        $this->options = $options;
42 2
        $this->request = $request;
43 2
    }
44
45 1
    public function transformText($text)
46
    {
47
        $requestArray = array(
48 1
            'text' => $text,
49 1
            'mode' => $this->options->getMarkdownMode(),
50
        );
51
52 1
        $this->request->setUri($this->options->getMarkdownApiUri());
53 1
        $this->request->setMethod(Request::METHOD_POST);
54 1
        $this->request->setContent(json_encode($requestArray));
55 1
        if ($this->options->getAccessToken()) {
56 1
            $this->request->getHeaders()
57 1
                ->addHeaderLine('Authorization', 'token ' . $this->options->getAccessToken());
58
        }
59
60 1
        $response = $this->httpClient->send($this->request);
61
62 1
        return $response->getBody();
63
    }
64
}
65