Completed
Push — master ( 720d6c...037e93 )
by Terrence
15:17 queued 12s
created

convertidplist.php ➔ printUsage()   A

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/config' . PATH_SEPARATOR .
10
    '/var/www/html/vendor/pear/net_ldap2' . PATH_SEPARATOR .
11
    '/var/www/html/vendor/cilogon/service-lib/src/Service' . PATH_SEPARATOR .
12
    '.'
13
);
14
15
require_once 'config.php';
16
include_once 'config.secrets.php';
17
require_once 'DBService.php';
18
require_once 'Util.php';
19
require_once 'IdpList.php';
20
21
use CILogon\Service\IdpList;
22
23
if ($argc == 4) {
24
    $command = $argv[1];
25
    $file1 = $argv[2];
26
    $file2 = $argv[3];
27
28
29
    if ($command == 'xml2json') {
30
        $readtype = 'xml';
31
        $writetype = 'json';
32
    } elseif ($command = 'json2xml') {
33
        $readtype = 'json';
34
        $writetype = 'xml';
35
    } else {
36
        printUsage();
37
    }
38
39
    $idplist = new IdpList($file1, '', false, $readtype);
40
    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...
41
        fwrite(STDERR, "Unable to read from $file1\n");
42
        exit(1);
43
    }
44
45
    $idplist->setFilename($file2);
46
    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...
47
        fwrite(STDERR, "Unable to write to $file2\n");
48
        exit(1);
49
    }
50
} else {
51
    printUsage();
52
}
53
54
55
function printUsage()
56
{
57
    echo "Usage: convertidplist.php COMMAND {FILE1} {FILE2}\n";
58
    echo "     where COMMAND is one of the following:\n";
59
    echo "         xml2json - read FILE1 as XML and write FILE2 as JSON\n";
60
    echo "         json2xml - read FILE1 as JSON and write FILE2 as XML\n";
61
    echo "     FILE1 is the file to read from\n";
62
    echo "     FILE2 is the file to write to\n";
63
    echo "Convert the idplist file betwewn XML and JSON.\n";
64
}
65