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

mimmi20 / laminasviewrenderer-bootstrap-form / 12160906017

04 Dec 2024 01:37PM UTC coverage: 97.314%. Remained the same
12160906017

push

github

web-flow
Merge pull request #310 from mimmi20/updates

upgrade to PHP 8.3

60 of 61 new or added lines in 40 files covered. (98.36%)

38 existing lines in 7 files now uncovered.

2174 of 2234 relevant lines covered (97.31%)

25.52 hits per line

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

89.66
/src/FormElement.php
1
<?php
2

3
/**
4
 * This file is part of the mimmi20/laminasviewrenderer-bootstrap-form package.
5
 *
6
 * Copyright (c) 2021-2024, Thomas Mueller <mimmi20@live.de>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types = 1);
13

14
namespace Mimmi20\LaminasView\BootstrapForm;
15

16
use Laminas\Form\Element;
17
use Laminas\Form\ElementInterface;
18
use Laminas\Form\Exception\InvalidArgumentException;
19
use Laminas\Form\View\Helper\FormElement as BaseFormElement;
20
use Laminas\View\Helper\HelperInterface;
21
use Laminas\View\Renderer\PhpRenderer;
22
use Mimmi20\Form\Links\Element\Links;
23
use Mimmi20\Form\Paragraph\Element\Paragraph;
24
use Override;
25

26
use function assert;
27
use function get_debug_type;
28
use function is_callable;
29
use function method_exists;
30
use function sprintf;
31

32
final class FormElement extends BaseFormElement implements FormIndentInterface, FormRenderInterface
33
{
34
    use FormTrait;
35

36
    /**
37
     * Instance map to view helper
38
     *
39
     * @var array<class-string<ElementInterface>, string>
40
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
41
     */
42
    protected $classMap = [
43
        Element\Button::class => 'formButton',
44
        Element\Captcha::class => 'formCaptcha',
45
        Element\Csrf::class => 'formHidden',
46
        Element\Collection::class => 'formCollection',
47
        Element\DateTimeSelect::class => 'formDateTimeSelect',
48
        Element\DateSelect::class => 'formDateSelect',
49
        Element\MonthSelect::class => 'formMonthSelect',
50
        Element\Submit::class => 'formSubmit',
51
        Links::class => 'formLinks',
52
        Paragraph::class => 'formParagraph',
53
    ];
54

55
    /**
56
     * Get default helper name
57
     *
58
     * @throws void
59
     *
60
     * @api
61
     */
62
    public function getDefaultHelper(): string
1✔
63
    {
64
        return $this->defaultHelper;
1✔
65
    }
66

67
    /**
68
     * Render element by helper name
69
     *
70
     * @throws InvalidArgumentException
71
     */
72
    #[Override]
44✔
73
    protected function renderHelper(string $name, ElementInterface $element): string
74
    {
75
        $renderer = $this->getView();
44✔
76
        assert(
44✔
77
            $renderer instanceof PhpRenderer,
44✔
78
            sprintf(
44✔
79
                '$renderer should be an Instance of %s, but was %s',
44✔
80
                PhpRenderer::class,
44✔
81
                get_debug_type($renderer),
44✔
82
            ),
44✔
83
        );
44✔
84

85
        $helper = $renderer->plugin($name);
44✔
86
        assert(
44✔
87
            $helper instanceof HelperInterface || is_callable($helper),
44✔
88
            sprintf(
44✔
89
                '$helper should be an Instance of %s or a Callable, but was %s',
44✔
90
                HelperInterface::class,
44✔
91
                get_debug_type($helper),
44✔
92
            ),
44✔
93
        );
44✔
94

95
        if ($helper instanceof HelperInterface) {
44✔
96
            if ($helper instanceof FormIndentInterface || method_exists($helper, 'setIndent')) {
44✔
97
                $helper->setIndent($this->getIndent());
44✔
98
            }
99

100
            if ($helper instanceof FormRenderInterface || method_exists($helper, 'render')) {
44✔
101
                return $helper->render($element);
44✔
102
            }
103
        }
104

105
        if (is_callable($helper)) {
×
UNCOV
106
            return $helper($element);
×
107
        }
108

UNCOV
109
        throw new InvalidArgumentException('the element does not support the render function');
×
110
    }
111
}
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

© 2025 Coveralls, Inc