Completed
Push — search ( 076ba7...2a5267 )
by Simon
16:36 queued 11:48
created

WikiTextHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
namespace Waca\Helpers;
10
11
use Waca\SiteConfiguration;
0 ignored issues
show
Bug introduced by
The type Waca\SiteConfiguration 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...
12
13
class WikiTextHelper
14
{
15
    /**
16
     * @var SiteConfiguration
17
     */
18
    private $configuration;
19
    /**
20
     * @var HttpHelper
21
     */
22
    private $http;
23
24
    /**
25
     * WikiTextHelper constructor.
26
     *
27
     * @param SiteConfiguration $configuration
28
     * @param HttpHelper        $http
29
     */
30 1
    public function __construct(SiteConfiguration $configuration, HttpHelper $http)
31
    {
32 1
        $this->configuration = $configuration;
33 1
        $this->http = $http;
34 1
    }
35
36
    /**
37
     * Gets the HTML for the provided wiki-markup from the MediaWiki service endpoint
38
     *
39
     * @param string $wikiText
40
     *
41
     * @return string
42
     */
43 1
    public function getHtmlForWikiText($wikiText)
44
    {
45 1
        $endpoint = $this->configuration->getMediawikiWebServiceEndpoint();
46
47
        $parameters = array(
48 1
            'action'             => 'parse',
49
            'pst'                => true,
50 1
            'contentmodel'       => 'wikitext',
51
            'disablelimitreport' => true,
52
            'disabletoc'         => true,
53
            'disableeditsection' => true,
54 1
            'format'             => 'php',
55 1
            'text'               => $wikiText,
56
        );
57
58 1
        $apiResult = $this->http->get($endpoint, $parameters);
59 1
        $parseResult = unserialize($apiResult);
60
61 1
        return $parseResult['parse']['text']['*'];
62
    }
63
}