simple_html_dom::file_get_html()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 42
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 20
nc 4
nop 11
dl 0
loc 42
rs 9.6
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace simplehtmldom;
4
5
/*
6
 * Website: http://sourceforge.net/projects/simplehtmldom/
7
 * Acknowledge: Jose Solorzano (https://sourceforge.net/projects/php-html/)
8
 *
9
 * Licensed under The MIT License
10
 * See the LICENSE file in the project root for more information.
11
 *
12
 * Authors:
13
 *   S.C. Chen
14
 *   John Schlick
15
 *   Rus Carroll
16
 *   logmanoriginal
17
 *
18
 * Contributors:
19
 *   Yousuke Kumakura
20
 *   Vadim Voituk
21
 *   Antcs
22
 *
23
 * Version Rev. 2.0-RC2 (415)
24
 */
25
26
//require_once __DIR__ . '/constants.php';
27
include_once __DIR__ . '/HtmlDocument.php';
28
include_once __DIR__ . '/HtmlNode.php';
29
30
if (!defined('DEFAULT_TARGET_CHARSET') && defined('\simplehtmldom\DEFAULT_TARGET_CHARSET')) {
31
  define('DEFAULT_TARGET_CHARSET', \simplehtmldom\DEFAULT_TARGET_CHARSET);
32
}
33
34
if (!defined('DEFAULT_BR_TEXT') && defined('\simplehtmldom\DEFAULT_BR_TEXT')) {
35
  define('DEFAULT_BR_TEXT', \simplehtmldom\DEFAULT_BR_TEXT);
36
}
37
38
if (!defined('DEFAULT_SPAN_TEXT') && defined('\simplehtmldom\DEFAULT_SPAN_TEXT')) {
39
  define('DEFAULT_SPAN_TEXT', \simplehtmldom\DEFAULT_SPAN_TEXT);
40
}
41
42
if (!defined('MAX_FILE_SIZE') && defined('\simplehtmldom\MAX_FILE_SIZE')) {
43
  define('MAX_FILE_SIZE', \simplehtmldom\MAX_FILE_SIZE);
44
}
45
46
if (!defined('DEFAULT_TARGET_CHARSET')) {
47
  define('DEFAULT_TARGET_CHARSET', 'UTF-8');
48
}
49
if (!defined('DEFAULT_BR_TEXT')) {
50
  define('DEFAULT_BR_TEXT', "\r\n");
51
}
52
if (!defined('DEFAULT_SPAN_TEXT')) {
53
  define('DEFAULT_SPAN_TEXT', ' ');
54
}
55
if (!defined('MAX_FILE_SIZE')) {
56
  define('MAX_FILE_SIZE', 2621440);
57
}
58
if (!defined('HDOM_SMARTY_AS_TEXT')) {
59
  define('HDOM_SMARTY_AS_TEXT', 1);
60
}
61
62
define('HDOM_TYPE_ELEMENT', \simplehtmldom\HtmlNode::HDOM_TYPE_ELEMENT);
63
define('HDOM_TYPE_COMMENT', \simplehtmldom\HtmlNode::HDOM_TYPE_COMMENT);
64
define('HDOM_TYPE_TEXT', \simplehtmldom\HtmlNode::HDOM_TYPE_TEXT);
65
define('HDOM_TYPE_ROOT', \simplehtmldom\HtmlNode::HDOM_TYPE_ROOT);
66
define('HDOM_TYPE_UNKNOWN', \simplehtmldom\HtmlNode::HDOM_TYPE_UNKNOWN);
67
define('HDOM_QUOTE_DOUBLE', \simplehtmldom\HtmlNode::HDOM_QUOTE_DOUBLE);
68
define('HDOM_QUOTE_SINGLE', \simplehtmldom\HtmlNode::HDOM_QUOTE_SINGLE);
69
define('HDOM_QUOTE_NO', \simplehtmldom\HtmlNode::HDOM_QUOTE_NO);
70
define('HDOM_INFO_BEGIN', \simplehtmldom\HtmlNode::HDOM_INFO_BEGIN);
71
define('HDOM_INFO_END', \simplehtmldom\HtmlNode::HDOM_INFO_END);
72
define('HDOM_INFO_QUOTE', \simplehtmldom\HtmlNode::HDOM_INFO_QUOTE);
73
define('HDOM_INFO_SPACE', \simplehtmldom\HtmlNode::HDOM_INFO_SPACE);
74
define('HDOM_INFO_TEXT', \simplehtmldom\HtmlNode::HDOM_INFO_TEXT);
75
define('HDOM_INFO_INNER', \simplehtmldom\HtmlNode::HDOM_INFO_INNER);
76
define('HDOM_INFO_OUTER', \simplehtmldom\HtmlNode::HDOM_INFO_OUTER);
77
define('HDOM_INFO_ENDSPACE', \simplehtmldom\HtmlNode::HDOM_INFO_ENDSPACE);
78
//define('HDOM_SMARTY_AS_TEXT', HDOM_SMARTY_AS_TEXT);
79
class_alias('\simplehtmldom\HtmlDocument', 'simple_html_dom', true);
80
//class_alias('\simplehtmldom\HtmlNode', 'simple_html_dom_node', true);
81
82
/**
83
 * String to get html dom.
84
 *
85
 * @param string $str HTML string
86
 */
87
class simple_html_dom // extends HtmlDocument
88
{
89
  public $innertext;
90
  public $outertext;
91
92
  public function __construct()
93
  {
94
    //parent::__construct();
95
  }
96
97
  public function file_get_html(
98
    $url,
99
    $use_include_path = false,
100
    $context = null,
101
    $offset = 0,
102
    $maxLen = -1,
103
    $lowercase = true,
104
    $forceTagsClosed = true,
105
    $target_charset = \simplehtmldom\DEFAULT_TARGET_CHARSET,
106
    $stripRN = true,
107
    $defaultBRText = \simplehtmldom\DEFAULT_BR_TEXT,
108
    $defaultSpanText = \simplehtmldom\DEFAULT_SPAN_TEXT
109
  ) {
110
    if ($maxLen <= 0) {
111
      $maxLen = \simplehtmldom\MAX_FILE_SIZE;
112
    }
113
114
    $dom = new HtmlDocument(
115
      null,
116
      $lowercase,
117
      $forceTagsClosed,
118
      $target_charset,
119
      $stripRN,
120
      $defaultBRText,
121
      $defaultSpanText
122
    );
123
124
    $contents = file_get_contents(
125
      $url,
126
      $use_include_path,
127
      $context,
128
      $offset,
129
      $maxLen + 1 // Load extra byte for limit check
130
    );
131
132
    if (empty($contents) || strlen($contents) > $maxLen) {
133
      $dom->clear();
0 ignored issues
show
Bug introduced by
The method clear() does not exist on simplehtmldom\HtmlDocument. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

133
      $dom->/** @scrutinizer ignore-call */ 
134
            clear();
Loading history...
134
135
      return false;
136
    }
137
138
    return $dom->load($contents, $lowercase, $stripRN);
139
  }
140
141
  public function str_get_html(
142
    $str,
143
    $lowercase = true,
144
    $forceTagsClosed = true,
145
    $target_charset = DEFAULT_TARGET_CHARSET,
146
    $stripRN = true,
147
    $defaultBRText = DEFAULT_BR_TEXT,
148
    $defaultSpanText = DEFAULT_SPAN_TEXT
149
  ) {
150
    $dom = new HtmlDocument(
151
      null,
152
      $lowercase,
153
      $forceTagsClosed,
154
      $target_charset,
155
      $stripRN,
156
      $defaultBRText,
157
      $defaultSpanText
158
    );
159
160
    if (empty($str) || strlen($str) > MAX_FILE_SIZE) {
161
      $dom->clear();
162
163
      return false;
164
    }
165
166
    return $dom->load($str, $lowercase, $stripRN);
167
  }
168
}
169
170
/** @codeCoverageIgnore */
171
function dump_html_tree($node, $show_attr = true, $deep = 0)
0 ignored issues
show
Unused Code introduced by
The parameter $deep is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

171
function dump_html_tree($node, $show_attr = true, /** @scrutinizer ignore-unused */ $deep = 0)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $show_attr is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

171
function dump_html_tree($node, /** @scrutinizer ignore-unused */ $show_attr = true, $deep = 0)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
172
{
173
  $node->dump($node);
174
}
175