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

eliashaeussler / typo3-codeception-helper / 9917386766

13 Jul 2024 02:01AM UTC coverage: 77.686%. Remained the same
9917386766

push

github

web-flow
[TASK] Update all dependencies

94 of 121 relevant lines covered (77.69%)

2.18 hits per line

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

100.0
/src/ValueObject/Entrypoint.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/typo3-codeception-helper".
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 2 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\Typo3CodeceptionHelper\ValueObject;
25

26
use EliasHaeussler\Typo3CodeceptionHelper\Exception;
27
use Symfony\Component\Filesystem;
28

29
use function array_key_exists;
30

31
/**
32
 * Entrypoint.
33
 *
34
 * @author Elias Häußler <elias@haeussler.dev>
35
 * @license GPL-2.0-or-later
36
 */
37
final class Entrypoint
38
{
39
    /**
40
     * @param non-empty-string $webDirectory
41
     * @param non-empty-string $mainEntrypoint
42
     * @param non-empty-string $appEntrypoint
43
     */
44
    public function __construct(
11✔
45
        private readonly string $webDirectory,
46
        private readonly string $mainEntrypoint = 'index.php',
47
        private readonly string $appEntrypoint = 'app.php',
48
    ) {}
11✔
49

50
    /**
51
     * @param array<string, mixed> $config
52
     * @param non-empty-string     $baseDirectory
53
     *
54
     * @throws Exception\ConfigIsEmpty
55
     * @throws Exception\ConfigIsInvalid
56
     */
57
    public static function fromConfig(array $config, string $baseDirectory): self
8✔
58
    {
59
        $webDirectory = Filesystem\Path::join($baseDirectory, self::parseConfig($config, 'web-dir'));
8✔
60
        $mainEntrypoint = self::parseConfig($config, 'main-entrypoint', 'index.php');
6✔
61
        $appEntrypoint = self::parseConfig($config, 'app-entrypoint', 'app.php');
4✔
62

63
        return new self($webDirectory, $mainEntrypoint, $appEntrypoint);
2✔
64
    }
65

66
    /**
67
     * @param array<string, mixed>  $config
68
     * @param non-empty-string      $name
69
     * @param non-empty-string|null $default
70
     *
71
     * @return non-empty-string
72
     *
73
     * @throws Exception\ConfigIsEmpty
74
     * @throws Exception\ConfigIsInvalid
75
     */
76
    private static function parseConfig(array $config, string $name, ?string $default = null): string
8✔
77
    {
78
        if (!array_key_exists($name, $config) && null !== $default) {
8✔
79
            return $default;
1✔
80
        }
81

82
        $value = $config[$name] ?? null;
8✔
83

84
        if (!is_string($value)) {
8✔
85
            throw new Exception\ConfigIsInvalid($name);
3✔
86
        }
87
        if ('' === $value) {
7✔
88
            throw new Exception\ConfigIsEmpty($name);
3✔
89
        }
90

91
        return $value;
6✔
92
    }
93

94
    /**
95
     * @return non-empty-string
96
     */
97
    public function getWebDirectory(): string
1✔
98
    {
99
        return $this->webDirectory;
1✔
100
    }
101

102
    /**
103
     * @return non-empty-string
104
     */
105
    public function getMainEntrypoint(): string
1✔
106
    {
107
        return Filesystem\Path::join($this->webDirectory, $this->mainEntrypoint);
1✔
108
    }
109

110
    /**
111
     * @return non-empty-string
112
     */
113
    public function getAppEntrypoint(): string
1✔
114
    {
115
        return Filesystem\Path::join($this->webDirectory, $this->appEntrypoint);
1✔
116
    }
117
}
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