Passed
Push — version-matrix ( df0591 )
by Tomas Norre
13:39 queued 08:00
created

PhpBinaryUtility::getPhpBinary()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.016

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 9
cts 10
cp 0.9
crap 4.016
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
class PhpBinaryUtility
29
{
30 16
    public static function getPhpBinary(): string
31
    {
32 16
        $extensionSettings = GeneralUtility::makeInstance(ExtensionConfigurationProvider::class)->getExtensionConfiguration();
33
34 16
        if (empty($extensionSettings)) {
35
            throw new ExtensionSettingsException('ExtensionSettings are empty', 1587066853);
36
        }
37
38 16
        if (empty($extensionSettings['phpPath'])) {
39 14
            $phpPath = CommandUtility::getCommand($extensionSettings['phpBinary']);
40 14
            if ($phpPath === false) {
41 14
                throw new CommandNotFoundException('The phpBinary: "' . $extensionSettings['phpBinary'] . '" could not be found!', 1587068215);
42
            }
43
        } else {
44 4
            $phpPath = $extensionSettings['phpPath'];
45
        }
46
47 16
        return $phpPath;
48
    }
49
}
50