Passed
Push — release-11.0.x ( 910681...ed160c )
by Rafael
11:00
created

ShellUtility   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 38
ccs 10
cts 16
cp 0.625
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLanguagePrefix() 0 6 3
A escapeShellArgument() 0 19 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()
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
        $currentLocale = null;
47 4
        $isUTF8Filesystem = !empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']);
48 4
        if ($isUTF8Filesystem) {
49
            $currentLocale = setlocale(LC_CTYPE, 0);
50
            setlocale(
51
                LC_CTYPE,
52
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['systemLocale']
53
            );
54
        }
55
56 4
        $argument = escapeshellarg($argument);
57
58 4
        if ($isUTF8Filesystem) {
59
            setlocale(LC_CTYPE, $currentLocale);
0 ignored issues
show
Bug introduced by
It seems like $currentLocale can also be of type null; however, parameter $locales of setlocale() does only seem to accept array|integer|string, 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

59
            setlocale(LC_CTYPE, /** @scrutinizer ignore-type */ $currentLocale);
Loading history...
60
        }
61
62 4
        return $argument;
63
    }
64
}
65