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
Push — master ( c017f3...3478bb )
by Shcherbak
7s
created

ElementFinderFactory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 92%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 45
ccs 23
cts 25
cp 0.92
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C create() 0 37 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
    {
17 7
      $html = $response->getBody();
18 7
      $html = Helper::safeEncodeStr((string)$html);
19
20 7
      $supportedEncodings = [];
21 7
      foreach (mb_list_encodings() as $encoding) {
22 7
        if ($encoding == 'UTF-8' || $encoding == 'UTF8') {
23 7
          continue;
24
        }
25
26 7
        $supportedEncodings[] = $encoding;
27 7
        $supportedEncodings = array_merge($supportedEncodings, mb_encoding_aliases($encoding));
28 7
      }
29
30 7
      $contentType = $response->getHeaderLine('content-type');
31
32 7
      if ($contentType) {
33 1
        preg_match("!^.*charset=([A-Za-z0-9-]{4,})$!", $contentType, $contentTypeData);
34 1
        $encoding = strtoupper(trim($contentTypeData[1]));
35 1
      } else {
36 7
        preg_match("!.*<meta.*charset=\"?([A-Za-z0-9-]{4,})\"!mi", $html, $metaContentType);
37 7
        $encoding = !empty($metaContentType[1]) ? strtoupper(trim($metaContentType[1])) : '';
38
      }
39
40 7
      if (in_array($encoding, $supportedEncodings)) {
41 2
        $html = mb_convert_encoding($html, 'UTF-8', $encoding);
42 2
      }
43
44 7
      $page = new ElementFinder((string)$html);
45
46 7
      if ($url) {
47
        LinkConverter::convertUrlsToAbsolute($page, $url);
48
      }
49
50 7
      return $page;
51
    }
52
  }