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

eliashaeussler / composer-package-template / 10609225944

29 Aug 2024 12:06AM UTC coverage: 99.502%. Remained the same
10609225944

push

github

web-flow
[TASK] Update all dependencies

400 of 402 relevant lines covered (99.5%)

3.5 hits per line

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

100.0
/src/Resource/ProcessFactory.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/composer-package-template".
7
 *
8
 * Copyright (C) 2023-2024 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\ComposerPackageTemplate\Resource;
25

26
use EliasHaeussler\ComposerPackageTemplate\Exception;
27
use Symfony\Component\Process;
28

29
use function array_shift;
30
use function array_unshift;
31

32
/**
33
 * ProcessFactory.
34
 *
35
 * @author Elias Häußler <elias@haeussler.dev>
36
 * @license GPL-3.0-or-later
37
 */
38
final class ProcessFactory
39
{
40
    /**
41
     * @var array<non-empty-string, string|null>
42
     */
43
    private array $executables = [];
44

45
    public function __construct(
4✔
46
        private readonly Process\ExecutableFinder $executableFinder,
47
    ) {}
4✔
48

49
    /**
50
     * @param non-empty-list<string> $command
51
     *
52
     * @throws Exception\ExecutableIsMissing
53
     */
54
    public function create(array $command): Process\Process
3✔
55
    {
56
        $name = array_shift($command);
3✔
57

58
        if ('' === $name || !$this->isExecutable($name)) {
3✔
59
            throw new Exception\ExecutableIsMissing($name);
2✔
60
        }
61

62
        array_unshift($command, $this->findExecutable($name));
1✔
63

64
        return new Process\Process($command);
1✔
65
    }
66

67
    /**
68
     * @param non-empty-string $name
69
     */
70
    public function isExecutable(string $name): bool
3✔
71
    {
72
        return null !== $this->findExecutable($name);
3✔
73
    }
74

75
    /**
76
     * @param non-empty-string $name
77
     */
78
    private function findExecutable(string $name): ?string
3✔
79
    {
80
        if (!isset($this->executables[$name])) {
3✔
81
            $this->executables[$name] = $this->executableFinder->find($name);
3✔
82
        }
83

84
        return $this->executables[$name];
3✔
85
    }
86
}
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