• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JBZoo / Cli / 5834950866

pending completion
5834950866

push

github

web-flow
Predefined output formats - ELK, cron. New demo and docs. (#15)

745 of 745 new or added lines in 16 files covered. (100.0%)

899 of 1078 relevant lines covered (83.4%)

136.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.14
/src/CliHelper.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - Cli.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/Cli
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\Cli;
18

19
use JBZoo\Utils\Env;
20
use JBZoo\Utils\Str;
21

22
use function JBZoo\Utils\int;
23
use function JBZoo\Utils\isStrEmpty;
24

25
class CliHelper
26
{
27
    public static function getRootPath(): string
28
    {
29
        $rootPath = \defined('JBZOO_PATH_ROOT') ? (string)JBZOO_PATH_ROOT : null;
16✔
30
        if (isStrEmpty($rootPath)) {
16✔
31
            return Env::string('JBZOO_PATH_ROOT');
4✔
32
        }
33

34
        return (string)$rootPath;
12✔
35
    }
36

37
    public static function getBinPath(): string
38
    {
39
        $binPath = \defined('JBZOO_PATH_BIN') ? (string)JBZOO_PATH_BIN : null;
16✔
40
        if (isStrEmpty($binPath)) {
16✔
41
            return Env::string('JBZOO_PATH_BIN');
4✔
42
        }
43

44
        return (string)$binPath;
12✔
45
    }
46

47
    /**
48
     * @see https://github.com/phpstan/phpstan-src/blob/f8be122188/src/Process/CpuCoreCounter.php
49
     */
50
    public static function getNumberOfCpuCores(): int
51
    {
52
        static $numberOfCpuCores = null;
8✔
53

54
        if ($numberOfCpuCores !== null) {
16✔
55
            return $numberOfCpuCores;
16✔
56
        }
57

58
        if (!\function_exists('proc_open')) {
16✔
59
            return $numberOfCpuCores = 1;
×
60
        }
61

62
        // from brianium/paratest
63
        // Linux (and potentially Windows with linux sub systems)
64
        if (\is_file('/proc/cpuinfo')) {
16✔
65
            $cpuinfo = \file_get_contents('/proc/cpuinfo');
16✔
66
            if ($cpuinfo !== false) {
16✔
67
                \preg_match_all('/^processor/m', $cpuinfo, $matches);
16✔
68

69
                return $numberOfCpuCores = \count($matches[0]);
16✔
70
            }
71
        }
72

73
        // Windows
74
        if (\DIRECTORY_SEPARATOR === '\\') {
×
75
            $process = \popen('wmic cpu get NumberOfLogicalProcessors', 'rb');
×
76
            if (\is_resource($process)) {
×
77
                /** @phan-suppress-next-line PhanPluginUseReturnValueInternalKnown */
78
                \fgets($process);
×
79
                $cores = int(\fgets($process));
×
80
                \pclose($process);
×
81

82
                return $numberOfCpuCores = $cores;
×
83
            }
84
        }
85

86
        // *nix (Linux, BSD and Mac)
87
        $process = \popen('sysctl -n hw.ncpu', 'rb');
×
88
        if (\is_resource($process)) {
×
89
            $cores = int(\fgets($process));
×
90
            \pclose($process);
×
91

92
            return $numberOfCpuCores = $cores;
×
93
        }
94

95
        return $numberOfCpuCores = 2;
×
96
    }
97

98
    public static function renderListForHelpDescription(array $keyValues): string
99
    {
100
        $result = '';
572✔
101

102
        foreach ($keyValues as $key => $value) {
572✔
103
            $result .= "<comment>{$key}</comment> - {$value}\n";
572✔
104
        }
105

106
        return $result;
572✔
107
    }
108

109
    public static function createOrGetTraceId(): string
110
    {
111
        static $traceId = null;
76✔
112

113
        if ($traceId === null) {
152✔
114
            $traceId = Str::uuid();
152✔
115
        }
116

117
        return $traceId;
152✔
118
    }
119

120
    public static function renderExpectedValues(array $values): string
121
    {
122
        $result = '';
×
123

124
        foreach ($values as $value) {
×
125
            $result .= "\"{$value}\", ";
×
126
        }
127

128
        return \rtrim($result);
×
129
    }
130
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc