Passed
Push — codeception ( 70a2c0...f5176b )
by Tomas Norre
06:16
created

PhpBinaryUtility   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 2
b 0
f 0
dl 0
loc 20
ccs 10
cts 15
cp 0.6667
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getPhpBinary() 0 18 4
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 6
    public static function getPhpBinary(): string
31
    {
32 6
        $extensionSettings = GeneralUtility::makeInstance(ExtensionConfigurationProvider::class)->getExtensionConfiguration();
33
34 5
        if (empty($extensionSettings)) {
35 1
            throw new ExtensionSettingsException('ExtensionSettings are empty', 1587066853);
36
        }
37
38 4
        if (empty($extensionSettings['phpPath'])) {
39 3
            $phpPath = CommandUtility::getCommand($extensionSettings['phpBinary']);
40 3
            if ($phpPath === false) {
41 3
                throw new CommandNotFoundException('The phpBinary: "' . $extensionSettings['phpBinary'] . '" could not be found!', 1587068215);
42
            }
43
        } else {
44 2
            $phpPath = $extensionSettings['phpPath'];
45
        }
46
47 3
        return $phpPath;
48
    }
49
}
50