Passed
Push — master ( e9da9b...d96a4c )
by Carlos C
07:22 queued 11s
created

file_extension()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 3
nc 1
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogosPopulate\Utils;
6
7
use RuntimeException;
8
9
function array_rtrim(array $input): array
10
{
11 43
    $count = count($input);
12 43
    while ($count > 0 && '' === (string) $input[$count - 1]) {
13 38
        array_pop($input);
14 38
        $count = $count - 1;
15
    }
16
17 43
    return $input;
18
}
19
20
/**
21
 * @param string $dir
22
 * @param string $prefix
23
 * @return string
24
 * @throws RuntimeException Cannot create a temporary file name
25
 */
26
function tempname($dir = '', $prefix = ''): string
27
{
28
    /** @noinspection PhpUsageOfSilenceOperatorInspection */
29 6
    $tempname = @tempnam($dir, $prefix);
30 6
    if (false === $tempname) {
31
        throw new RuntimeException('Cannot create a temporary file name');
32
    }
33 6
    return $tempname;
34
}
35
36
/**
37
 * @param string $dir
38
 * @param string $prefix
39
 * @return string
40
 * @throws RuntimeException Cannot create a temporary file name
41
 */
42
function tempdir(string $dir = '', string $prefix = ''): string
43
{
44 5
    $dirname = tempname($dir, $prefix);
45 5
    if (file_exists($dirname)) {
46 5
        unlink($dirname);
47
    }
48 5
    mkdir($dirname);
49 5
    return $dirname;
50
}
51
52
function preg_is_valid(string $input): bool
53
{
54
    /** @noinspection PhpUsageOfSilenceOperatorInspection */
55 6
    return (false !== @preg_match('/' . $input . '/', ''));
56
}
57