Completed
Push — master ( 2483d3...f8ad5b )
by Lars
02:46
created

example_callback.php ➔ my_callback()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 1
Metric Value
cc 4
eloc 7
c 5
b 0
f 1
nc 8
nop 1
dl 0
loc 14
rs 9.2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 14 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use voku\helper\HtmlDomParser;
4
5
require_once '../vendor/autoload.php';
6
7
// 1. Write a function with parameter "$element"
8
9
/**
10
 * test callback
11
 *
12
 * @param $element
13
 */
14
function my_callback($element)
15
{
16
  if ($element->tag == 'input') {
17
    $element->outertext = 'input';
18
  }
19
20
  if ($element->tag == 'img') {
21
    $element->outertext = 'img';
22
  }
23
24
  if ($element->tag == 'a') {
25
    $element->outertext = 'a';
26
  }
27
}
28
29
30
// 2. create HTML Dom
31
$html = HtmlDomParser::file_get_html('http://www.google.com/');
0 ignored issues
show
Unused Code introduced by
The call to HtmlDomParser::file_get_html() has too many arguments starting with 'http://www.google.com/'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
32
33
34
// 3. Register the callback function with it's function name
35
$html->set_callback('my_callback');
36
37
38
// 4. Callback function will be invoked while dumping
39
echo $html;
40