Passed
Branch master (2cc707)
by Vítězslav
41:09 queued 16:07
created

common.php ➔ askForFlexiBeeID()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
/**
3
 * FlexiPeeHP - Shared functions
4
 *
5
 * @author     Vítězslav Dvořák <[email protected]>
6
 * @copyright  (G) 2017 Vitex Software
7
 */
8
9
namespace Example\FlexiPeeHP;
10
11
/**
12
 * Ask For Invoice ID
13
 *
14
 * @param string $type Requested type for documents
15
 * @return int|string id or code
16
 */
17
function askForFlexiBeeID($type = 'invoice')
18
{
19
    $invoiceID = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $invoiceID is dead and can be removed.
Loading history...
20
    echo "Please enter $type ID:";
21
    $input     = fopen("php://stdin", "r");
22
    $invoiceID = trim(fgets($input));
0 ignored issues
show
Bug introduced by
It seems like $input can also be of type false; however, parameter $handle of fgets() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

22
    $invoiceID = trim(fgets(/** @scrutinizer ignore-type */ $input));
Loading history...
23
    fclose($input);
0 ignored issues
show
Bug introduced by
It seems like $input can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

23
    fclose(/** @scrutinizer ignore-type */ $input);
Loading history...
24
    if (is_numeric($invoiceID)) {
25
        $invoiceID = intval($invoiceID);
26
    }
27
    return $invoiceID;
28
}
29