Completed
Pull Request — newinternal (#547)
by Simon
05:45
created

smarty_modifier_iphex()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 15
rs 10
cc 3
nc 2
nop 1
1
<?php
2
/******************************************************************************
3
 * Wikipedia Account Creation Assistance tool                                 *
4
 *                                                                            *
5
 * All code in this file is released into the public domain by the ACC        *
6
 * Development Team. Please see team.json for a list of contributors.         *
7
 ******************************************************************************/
8
9
function smarty_modifier_iphex($input)
10
{
11
    $output = $input;
12
13
    if(filter_var($input, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false){
14
        $octets = explode('.', $input);
15
        $output = '';
16
        foreach ($octets as $octet){
17
            $output .= str_pad(dechex($octet), 2, '0', STR_PAD_LEFT);
0 ignored issues
show
Bug introduced by
$octet of type string is incompatible with the type integer expected by parameter $number of dechex(). ( Ignorable by Annotation )

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

17
            $output .= str_pad(dechex(/** @scrutinizer ignore-type */ $octet), 2, '0', STR_PAD_LEFT);
Loading history...
18
        }
19
20
        $output = str_pad($output, 32, '0', STR_PAD_LEFT);
21
    }
22
23
    return $output;
24
}
25