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.
Completed
Pull Request — master (#8)
by
unknown
06:15
created

ElementFinderFactory::create()   C

Complexity

Conditions 8
Paths 36

Size

Total Lines 36
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 25
CRAP Score 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 36
ccs 25
cts 25
cp 1
rs 5.3846
cc 8
eloc 22
nc 36
nop 2
crap 8
1
<?php
2
3
namespace Xparse\Parser\Helper;
4
5
use Xparse\ElementFinder\Helper;
6
use Xparse\ElementFinder\ElementFinder;
7
8
class ElementFinderFactory
9
{
10
    /**
11
     * @param $response
12
     * @param string $url
13
     * @return ElementFinder
14
     */
15 7
    public static function create($response, $url = '') {
16 7
        $html = $response->getBody();
17 7
        $html = Helper::safeEncodeStr((string) $html);
18
19 7
        $supportedEncodings = [];
20 7
        foreach (mb_list_encodings() as $encoding) {
21 7
            if ($encoding == 'UTF-8' || $encoding == 'UTF8') {
22 7
                continue;
23
            }
24
25 7
            $supportedEncodings[] = $encoding;
26 7
            $supportedEncodings = array_merge($supportedEncodings, mb_encoding_aliases($encoding));
27 7
        }
28
29 7
        $contentType = $response->getHeaderLine('content-type');
30
31 7
        if ($contentType) {
32 1
            preg_match("!^.*charset=([A-Za-z0-9-]{4,})$!", $contentType, $contentTypeData);
33 1
            $encoding = strtoupper(trim($contentTypeData[1]));
34 1
        } else {
35 7
            preg_match("!.*<meta.*charset=\"?([A-Za-z0-9-]{4,})\"!mi", $html, $metaContentType);
36 7
            $encoding = !empty($metaContentType[1]) ? strtoupper(trim($metaContentType[1])) : '';
37
        }
38
39 7
        if (in_array($encoding, $supportedEncodings)) {
40 5
            $html = mb_convert_encoding($html, 'UTF-8', $encoding);
41 5
        }
42
43 7
        $page = new ElementFinder((string) $html);
44
45 7
        if ($url) {
46 3
            LinkConverter::convertUrlsToAbsolute($page, $url);
47 3
        }
48
49 7
        return $page;
50
    }
51
}