Passed
Push — release-11.0.x ( ef2028...d0f0d9 )
by Rafael
18:22 queued 15:35
created

ShellUtility::escapeShellArgument()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
nc 4
nop 1
dl 0
loc 18
ccs 6
cts 12
cp 0.5
crap 4.125
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApacheSolrForTypo3\Tika\Utility;
6
7
/*
8
 * This file is part of the TYPO3 CMS project.
9
 *
10
 * It is free software; you can redistribute it and/or modify it under
11
 * the terms of the GNU General Public License, either version 2
12
 * of the License, or any later version.
13
 *
14
 * For the full copyright and license information, please read the
15
 * LICENSE.txt file that was distributed with this source code.
16
 *
17
 * The TYPO3 project - inspiring people to share!
18
 */
19
20
use TYPO3\CMS\Core\Core\Environment;
21
22
/**
23
 * Class ShellUtility
24
 */
25
class ShellUtility
26
{
27
    /**
28
     * @return string
29
     */
30 5
    public static function getLanguagePrefix(): string
31
    {
32 5
        if (!empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) && !Environment::isWindows()) {
33
            return 'LC_CTYPE="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale'] . '" ';
34
        }
35 5
        return '';
36
    }
37
38
    /**
39
     * Backwards compatibility to 6.x, is available in CommandUtility in 7.x
40
     *
41
     * @param string $argument
42
     * @return string
43
     */
44 4
    public static function escapeShellArgument(string $argument): string
45
    {
46 4
        $isUTF8Filesystem = !empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']);
47 4
        if ($isUTF8Filesystem) {
48
            $currentLocale = setlocale(LC_CTYPE, 0);
49
            setlocale(
50
                LC_CTYPE,
51
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']
52
            );
53
        }
54
55 4
        $argument = escapeshellarg($argument);
56
57 4
        if ($isUTF8Filesystem) {
58
            setlocale(LC_CTYPE, $currentLocale);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $currentLocale does not seem to be defined for all execution paths leading up to this point.
Loading history...
59
        }
60
61 4
        return $argument;
62
    }
63
}
64