PhpBinaryUtility::getPhpBinary()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 10
c 2
b 0
f 0
nc 4
nop 0
dl 0
loc 18
ccs 10
cts 10
cp 1
crap 4
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Utility;
6
7
/*
8
 * (c) 2020 AOE GmbH <[email protected]>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21
22
use AOE\Crawler\Configuration\ExtensionConfigurationProvider;
23
use AOE\Crawler\Exception\CommandNotFoundException;
24
use AOE\Crawler\Exception\ExtensionSettingsException;
25
use TYPO3\CMS\Core\Utility\CommandUtility;
26
use TYPO3\CMS\Core\Utility\GeneralUtility;
27
28
/**
29
 * @internal since v9.2.5
30
 */
31
class PhpBinaryUtility
32
{
33 12
    public static function getPhpBinary(): string
34
    {
35 12
        $extensionSettings = GeneralUtility::makeInstance(ExtensionConfigurationProvider::class)->getExtensionConfiguration();
36
37 12
        if (empty($extensionSettings)) {
38 1
            throw new ExtensionSettingsException('ExtensionSettings are empty', 1587066853);
39
        }
40
41 11
        if (empty($extensionSettings['phpPath'])) {
42 9
            $phpPath = CommandUtility::getCommand($extensionSettings['phpBinary']);
43 9
            if ($phpPath === false) {
44 9
                throw new CommandNotFoundException('The phpBinary: "' . $extensionSettings['phpBinary'] . '" could not be found!', 1587068215);
45
            }
46
        } else {
47 3
            $phpPath = $extensionSettings['phpPath'];
48
        }
49
50 10
        return $phpPath;
51
    }
52
}
53