ShellUtility   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 56.25%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 37
ccs 9
cts 16
cp 0.5625
rs 10
c 2
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLanguagePrefix() 0 6 3
A escapeShellArgument() 0 18 3
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