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

CPS-IT / project-builder / 24971672608

27 Apr 2026 01:01AM UTC coverage: 96.239% (-0.3%) from 96.489%
24971672608

push

github

web-flow
[TASK] Update all dependencies (#924)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

2226 of 2313 relevant lines covered (96.24%)

14.32 hits per line

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

96.08
/src/Naming/NameVariantBuilder.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "cpsit/project-builder".
7
 *
8
 * Copyright (C) 2022 Elias Häußler <e.haeussler@familie-redlich.de>
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 CPSIT\ProjectBuilder\Naming;
25

26
use CPSIT\ProjectBuilder\Builder;
27
use CPSIT\ProjectBuilder\Exception;
28
use CPSIT\ProjectBuilder\Helper;
29
use CPSIT\ProjectBuilder\StringCase;
30
use Webmozart\Assert;
31

32
use function is_string;
33

34
/**
35
 * NameVariantBuilder.
36
 *
37
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
38
 * @license GPL-3.0-or-later
39
 */
40
final class NameVariantBuilder
41
{
42
    public function __construct(
23✔
43
        private readonly Builder\BuildInstructions $instructions,
44
    ) {}
23✔
45

46
    /**
47
     * @param value-of<NameVariant>     $variant
48
     * @param value-of<StringCase>|null $case
49
     *
50
     * @throws Exception\StringConversionException
51
     */
52
    public function createVariant(string $variant, ?string $case = null): string
5✔
53
    {
54
        return match ($variant) {
×
55
            NameVariant::Abbreviation->value => $this->createAbbreviationVariant($case),
5✔
56
            NameVariant::ShortName->value => $this->createShortVariant($case),
4✔
57
            NameVariant::FullName->value => $this->createFullVariant($case),
5✔
58
        };
×
59
    }
60

61
    /**
62
     * @param value-of<StringCase>|null $case
63
     *
64
     * @throws Exception\StringConversionException
65
     */
66
    public function createShortVariant(?string $case = null): string
6✔
67
    {
68
        $customerName = $this->instructions->getTemplateVariable('project.customer_name');
6✔
69
        $projectName = $this->instructions->getTemplateVariable('project.name');
6✔
70

71
        Assert\Assert::string($customerName);
6✔
72

73
        if (!is_string($projectName) || self::isDefaultProjectName($projectName)) {
5✔
74
            $nameVariant = $customerName;
3✔
75
        } else {
76
            $nameVariant = $projectName;
2✔
77
        }
78

79
        if (null === $case) {
5✔
80
            return $nameVariant;
4✔
81
        }
82

83
        return Helper\StringHelper::convertCase(strtolower($nameVariant), $case);
1✔
84
    }
85

86
    /**
87
     * @param value-of<StringCase>|null $case
88
     *
89
     * @throws Exception\StringConversionException
90
     */
91
    public function createAbbreviationVariant(?string $case = null): string
6✔
92
    {
93
        $customerAbbreviation = $this->instructions->getTemplateVariable('project.customer_abbreviation');
6✔
94
        $projectName = $this->instructions->getTemplateVariable('project.name');
6✔
95

96
        Assert\Assert::string($customerAbbreviation);
6✔
97

98
        if (!is_string($projectName) || self::isDefaultProjectName($projectName)) {
5✔
99
            $nameVariant = $customerAbbreviation;
3✔
100
        } else {
101
            $nameVariant = $projectName;
2✔
102
        }
103

104
        if (null === $case) {
5✔
105
            return $nameVariant;
4✔
106
        }
107

108
        return Helper\StringHelper::convertCase(strtolower($nameVariant), $case);
1✔
109
    }
110

111
    /**
112
     * @param value-of<StringCase>|null $case
113
     *
114
     * @throws Exception\StringConversionException
115
     */
116
    public function createFullVariant(?string $case = null): string
7✔
117
    {
118
        $customerName = $this->instructions->getTemplateVariable('project.customer_name');
7✔
119
        $projectName = $this->instructions->getTemplateVariable('project.name');
7✔
120
        $components = [
7✔
121
            $customerName,
7✔
122
        ];
7✔
123

124
        Assert\Assert::string($customerName);
7✔
125

126
        if (is_string($projectName) && !self::isDefaultProjectName($projectName)) {
6✔
127
            $components[] = $projectName;
4✔
128
        }
129

130
        $nameVariant = ucwords(
6✔
131
            implode(
6✔
132
                ' ',
6✔
133
                array_filter(
6✔
134
                    $components,
6✔
135
                    static fn (mixed $component) => is_string($component) && '' !== trim($component),
6✔
136
                ),
6✔
137
            ),
6✔
138
        );
6✔
139

140
        if (null === $case) {
6✔
141
            return $nameVariant;
4✔
142
        }
143

144
        return Helper\StringHelper::convertCase($nameVariant, $case);
2✔
145
    }
146

147
    public static function isDefaultProjectName(?string $projectName): bool
17✔
148
    {
149
        return null === $projectName || 'basic' === $projectName;
17✔
150
    }
151
}
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