convertidplist.php ➔ printUsage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
set_include_path(
4
    '/var/www/html' . PATH_SEPARATOR .
5
    '/var/www/html/vendor/pear/pear-core-minimal/src' . PATH_SEPARATOR .
6
    '/var/www/html/vendor/pear/pear_exception' . PATH_SEPARATOR .
7
    '/var/www/html/vendor/pear/log' . PATH_SEPARATOR .
8
    '/var/www/html/vendor/pear/db' . PATH_SEPARATOR .
9
    '/var/www/html/vendor/pear/net_ldap2' . PATH_SEPARATOR .
10
    '/var/www/html/vendor/cilogon/service-lib/src/Service' . PATH_SEPARATOR .
11
    '.'
12
);
13
14
require_once 'config.php';
15
include_once 'config.secrets.php';
16
require_once 'DBService.php';
17
require_once 'Util.php';
18
require_once 'IdpList.php';
19
20
use CILogon\Service\IdpList;
21
22
if ($argc == 4) {
23
    $command = $argv[1];
24
    $file1 = $argv[2];
25
    $file2 = $argv[3];
26
27
28
    if ($command == 'xml2json') {
29
        $readtype = 'xml';
30
        $writetype = 'json';
31
    } elseif ($command = 'json2xml') {
32
        $readtype = 'json';
33
        $writetype = 'xml';
34
    } else {
35
        printUsage();
36
    }
37
38
    $idplist = new IdpList($file1, '', false, $readtype);
39
    if (!$idplist->read($readtype)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $idplist->read($readtype) of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
40
        fwrite(STDERR, "Unable to read from $file1\n");
41
        exit(1);
42
    }
43
44
    $idplist->setFilename($file2);
45
    if (!$idplist->write($writetype)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $idplist->write($writetype) of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
46
        fwrite(STDERR, "Unable to write to $file2\n");
47
        exit(1);
48
    }
49
} else {
50
    printUsage();
51
}
52
53
54
function printUsage()
55
{
56
    echo "Usage: convertidplist.php COMMAND {FILE1} {FILE2}\n";
57
    echo "     where COMMAND is one of the following:\n";
58
    echo "         xml2json - read FILE1 as XML and write FILE2 as JSON\n";
59
    echo "         json2xml - read FILE1 as JSON and write FILE2 as XML\n";
60
    echo "     FILE1 is the file to read from\n";
61
    echo "     FILE2 is the file to write to\n";
62
    echo "Convert the idplist file betwewn XML and JSON.\n";
63
}
64