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

valksor / php-dev-build / 21323318062

24 Jan 2026 11:21PM UTC coverage: 27.706% (-2.8%) from 30.503%
21323318062

push

github

k0d3r1s
wip

1 of 2 new or added lines in 2 files covered. (50.0%)

909 existing lines in 16 files now uncovered.

791 of 2855 relevant lines covered (27.71%)

0.96 hits per line

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

0.0
/Util/ConsoleCommandBuilder.php
1
<?php declare(strict_types = 1);
2

3
/*
4
 * This file is part of the Valksor package.
5
 *
6
 * (c) Davis Zalitis (k0d3r1s)
7
 * (c) SIA Valksor <packages@valksor.com>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12

13
namespace ValksorDev\Build\Util;
14

15
use Symfony\Component\Process\Process;
16

17
use function is_string;
18
use function str_starts_with;
19

20
/**
21
 * Utility class for building console commands with standardized options.
22
 *
23
 * This class eliminates the repetition of 'php bin/console' string construction
24
 * across providers by providing a fluent interface for command building.
25
 */
26
final class ConsoleCommandBuilder
27
{
28
    public const string CONSOLE_COMMAND = 'bin/console';
29
    public const string PHP_CONSOLE = 'php';
30

31
    /**
32
     * Build a console command process with options or arguments.
33
     *
34
     * @param string $command The console command (e.g., 'valksor:tailwind' or 'assets:install')
35
     * @param array  $options Command options:
36
     *                        For valksor commands:
37
     *                        - 'app' (string): Application ID for multi-app setup
38
     *                        - 'minify' (bool): Whether to add minification flag
39
     *                        - 'watch' (bool): Whether to add watch flag
40
     *                        For generic commands:
41
     *                        - Array of command-line arguments (e.g., ['--relative', '--no-interaction'])
42
     *
43
     * @return Process The configured process ready to run
44
     */
45
    public function build(
46
        string $command,
47
        array $options = [],
48
    ): Process {
UNCOV
49
        $arguments = [self::PHP_CONSOLE, self::CONSOLE_COMMAND, $command];
×
50

51
        // Handle valksor-specific options
52
        if (isset($options['app'])) {
×
UNCOV
53
            $arguments[] = '--id=' . $options['app'];
×
54
        }
55

56
        if ($options['minify'] ?? false) {
×
UNCOV
57
            $arguments[] = '--minify';
×
58
        }
59

60
        if ($options['watch'] ?? false) {
×
UNCOV
61
            $arguments[] = '--watch';
×
62
        }
63

64
        // Handle generic command arguments (non-valksor commands)
65
        // Check if this is a valksor command or generic command by looking for known options
UNCOV
66
        if (!str_starts_with($command, 'valksor:') && !str_starts_with($command, 'valksor-prod:')) {
×
67
            // Add all options as command-line arguments for generic commands
68
            foreach ($options as $option) {
×
69
                if (is_string($option)) {
×
UNCOV
70
                    $arguments[] = $option;
×
71
                }
72
            }
73
        }
74

UNCOV
75
        return new Process($arguments);
×
76
    }
77

78
    /**
79
     * Build command arguments array for use with ProcessManager::executeProcess().
80
     *
81
     * @param string $command The console command (e.g., 'valksor:tailwind')
82
     * @param array  $options Command options (same as build())
83
     *
84
     * @return array<string> Command arguments excluding 'php bin/console'
85
     */
86
    public function buildArguments(
87
        string $command,
88
        array $options = [],
89
    ): array {
UNCOV
90
        $arguments = [$command];
×
91

92
        // Add app ID if specified
93
        if (isset($options['app'])) {
×
UNCOV
94
            $arguments[] = '--id=' . $options['app'];
×
95
        }
96

97
        // Add minification flag
98
        if ($options['minify'] ?? false) {
×
UNCOV
99
            $arguments[] = '--minify';
×
100
        }
101

102
        // Add watch flag
103
        if ($options['watch'] ?? false) {
×
UNCOV
104
            $arguments[] = '--watch';
×
105
        }
106

UNCOV
107
        return $arguments;
×
108
    }
109
}
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