Completed
Push — next ( a537c2...29cbfe )
by Thomas
08:43
created

find_unicode_boms.php ➔ testForBom()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/***************************************************************************
3
 *  For license information see doc/license.txt
4
 *
5
 *  Unicode Reminder メモ
6
 *
7
 *  Searches for Unicode byte order marks in code and template files
8
 ***************************************************************************/
9
10
chdir(__DIR__ . '/../../htdocs');
11
require_once __DIR__ . '/../../htdocs/lib2/cli.inc.php';
12
13
scan('.', false);
0 ignored issues
show
Unused Code introduced by
The call to scan() has too many arguments starting with '.'.

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...
14
15 View Code Duplication
foreach (['api', 'lang', 'lib', 'lib2', 'okapi', 'src', 'templates2', 'util', 'util2', 'xml'] as $dir) {
16
    scan($dir, true);
0 ignored issues
show
Unused Code introduced by
The call to scan() has too many arguments starting with $dir.

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...
17
}
18
19
exit;
20
21
function scan($dir, $subdirs)
0 ignored issues
show
Best Practice introduced by
The function scan() has been defined more than once; this definition is ignored, only the first definition in htdocs/translate.php (L602-622) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
22
{
23
    $hDir = opendir($dir);
24 View Code Duplication
    if ($hDir !== false) {
25
        while (($file = readdir($hDir)) !== false) {
26
            $path = $dir . '/' . $file;
27
            if (is_dir($path) && substr($file, 0, 1) !== '.' && $subdirs) {
28
                scan($path, $subdirs);
0 ignored issues
show
Unused Code introduced by
The call to scan() has too many arguments starting with $path.

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...
29
            } else {
30
                if (is_file($path) && ((substr($file, - 4) === '.tpl') || (substr($file, - 4) === '.php'))) {
31
                    testForBom($path);
32
                }
33
            }
34
        }
35
        closedir($hDir);
36
    }
37
}
38
39
40
/**
41
 * @param string $path
42
 */
43
function testForBom($path)
44
{
45
    $filestart = file_get_contents($path, false, null, 0, 2);
46
    if (ord($filestart) > 126) {
47
        printf("%02X-%02X found in %s\n", ord($filestart), ord(substr($filestart, 1)), $path);
48
    }
49
}
50