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

FluidTYPO3 / vhs / 30001290505

23 Jul 2026 10:57AM UTC coverage: 70.309% (-1.7%) from 72.022%
30001290505

push

github

NamelessCoder
[TER] 8.0.0

4819 of 6854 relevant lines covered (70.31%)

6.54 hits per line

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

53.33
/Classes/ViewHelpers/Format/CaseViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Format;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use FluidTYPO3\Vhs\Core\ViewHelper\AbstractViewHelper;
12
use FluidTYPO3\Vhs\Utility\FrontendSimulationUtility;
13
use TYPO3\CMS\Core\Utility\GeneralUtility;
14
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
15

16
/**
17
 * Case Formatting ViewHelper
18
 *
19
 * Formats string case according to provided arguments.
20
 */
21
class CaseViewHelper extends AbstractViewHelper
22
{
23
    private const string CASE_UPPER = 'upper';
24
    private const string CASE_LOWER = 'lower';
25
    private const string CASE_UCWORDS = 'ucwords';
26
    private const string CASE_UCFIRST = 'ucfirst';
27
    private const string CASE_LCFIRST = 'lcfirst';
28
    private const string CASE_CAMELCASE = 'CamelCase';
29
    private const string CASE_LOWERCAMELCASE = 'lowerCamelCase';
30
    private const string CASE_UNDERSCORED = 'lowercase_underscored';
31

32
    public function initializeArguments(): void
33
    {
34
        $this->registerArgument('string', 'string', 'String to case format');
3✔
35
        $this->registerArgument('case', 'string', 'Case to convert to');
3✔
36
    }
37

38
    /**
39
     * @return mixed
40
     */
41
    public static function renderStatic(
42
        array $arguments,
43
        \Closure $renderChildrenClosure,
44
        RenderingContextInterface $renderingContext
45
    ) {
46
        /** @var string $string */
47
        $string = $arguments['string'] ?? $renderChildrenClosure();
3✔
48
        /** @var string $case */
49
        $case = $arguments['case'];
3✔
50

51
        $tsfeBackup = FrontendSimulationUtility::simulateFrontendEnvironment();
3✔
52

53
        switch ($case) {
54
            case self::CASE_LOWER:
55
                $string = mb_strtolower($string);
×
56
                break;
×
57
            case self::CASE_UPPER:
58
                $string = mb_strtoupper($string);
×
59
                break;
×
60
            case self::CASE_UCWORDS:
61
                $string = ucwords($string);
3✔
62
                break;
3✔
63
            case self::CASE_UCFIRST:
64
                $firstChar = mb_substr($string, 0, 1);
×
65
                $firstChar = mb_strtoupper($firstChar);
×
66
                $remainder = mb_substr($string, 1, null);
×
67
                $string = $firstChar . $remainder;
×
68
                break;
×
69
            case self::CASE_LCFIRST:
70
                $firstChar = mb_substr($string, 0, 1);
×
71
                $firstChar = mb_strtolower($firstChar);
×
72
                $remainder = mb_substr($string, 1, null);
×
73
                $string = $firstChar . $remainder;
×
74
                break;
×
75
            case self::CASE_CAMELCASE:
76
                $string = GeneralUtility::underscoredToUpperCamelCase($string);
3✔
77
                break;
3✔
78
            case self::CASE_LOWERCAMELCASE:
79
                $string = GeneralUtility::underscoredToLowerCamelCase($string);
3✔
80
                break;
3✔
81
            case self::CASE_UNDERSCORED:
82
                $string = GeneralUtility::camelCaseToLowerCaseUnderscored($string);
3✔
83
                break;
3✔
84
            default:
85
                break;
3✔
86
        }
87

88
        FrontendSimulationUtility::resetFrontendEnvironment($tsfeBackup);
3✔
89

90
        return $string;
3✔
91
    }
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc