Lines 97.87% 46 / 47
Methods 91.66% 11 / 12
Classes 0.00% 0 / 1
Covered by tests of size
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 renderCaptcha 96.66% 29 / 30 0.00% 0 / 1 4
 [phpMyFAQ\Helper\AbstractHelper] setCategory 100.00% 2 / 2 100.00% 1 / 1 1
 [phpMyFAQ\Helper\AbstractHelper] getCategory 100.00% 1 / 1 100.00% 1 / 1 1
 [phpMyFAQ\Helper\AbstractHelper] category 100.00% 1 / 1 100.00% 1 / 1 1
 [phpMyFAQ\Helper\AbstractHelper] plurals 100.00% 1 / 1 100.00% 1 / 1 1
 [phpMyFAQ\Helper\AbstractHelper] setCategoryRelation 100.00% 2 / 2 100.00% 1 / 1 1
 [phpMyFAQ\Helper\AbstractHelper] setTags 100.00% 2 / 2 100.00% 1 / 1 1
 [phpMyFAQ\Helper\AbstractHelper] setPlurals 100.00% 2 / 2 100.00% 1 / 1 1
 [phpMyFAQ\Helper\AbstractHelper] setSessionId 100.00% 2 / 2 100.00% 1 / 1 1
 [phpMyFAQ\Helper\AbstractHelper] setConfiguration 100.00% 2 / 2 100.00% 1 / 1 1
 [phpMyFAQ\Helper\AbstractHelper] getConfiguration 100.00% 1 / 1 100.00% 1 / 1 1
32class BuiltinCaptchaAbstractHelper extends AbstractHelper implements CaptchaHelperInterface
33{
34    private const string FORM_ID = 'captcha';
35
36    private const string FORM_BUTTON = 'captcha-button';
37
38    /**
39     * Constructor.
40     */
41    public function __construct(
42        protected Configuration $configuration,
43    ) {
44    }
45
46    /**
47     * Renders the captcha check.
48     */
49    public function renderCaptcha(
50        CaptchaInterface $captcha,
51        string $action = '',
52        string $label = '',
53        bool $auth = false,
54    ): string {
55        if (!$captcha instanceof BuiltinCaptcha) {
56            return '';
57        }
58
59        $html = '';
60
61        if (true === $this->configuration->get(item: 'spam.enableCaptchaCode') && !$auth) {
62            $html .= '<div class="row g-4">';
63            $html .= sprintf('<label class="col-md-3 col-sm-12 col-form-label">%s</label>', $label);
64            $html .= '    <div class="col-md-4 col-sm-6 col-7">';
65            $html .= sprintf('<p class="form-control-static">%s</p>', $captcha->renderCaptchaImage());
66            $html .= '    </div>';
67            $html .= '    <div class="col-md-5 col-sm-6 col-5">';
68            $html .= '        <div class="input-group">';
69            $html .= sprintf(
70                '<input type="text" class="form-control" name="%s" id="%s" size="%d" autocomplete="off" required>',
71                self::FORM_ID,
72                self::FORM_ID,
73                $captcha->captchaLength,
74            );
75            $html .= '            <span class="input-group-btn">';
76            $html .= sprintf(
77                '<button type="button" class="btn btn-primary" id="%s" data-action="%s">'
78                . '<i aria-hidden="true" class="bi bi-arrow-repeat" data-action="%s"></i></button>',
79                self::FORM_BUTTON,
80                $action,
81                $action,
82            );
83            $html .= '            </span>';
84            $html .= '        </div>';
85            $html .= '    </div>';
86            $html .= '</div>';
87        }
88
89        return $html;
90    }
91}

Inherited from phpMyFAQ\Helper\AbstractHelper

47    public function setCategory(Category $Category): AbstractHelper
48    {
49        $this->Category = $Category;
50        return $this;
51    }
53    public function getCategory(): Category
54    {
55        return $this->category();
56    }
61    protected function category(): Category
62    {
63        return $this->Category ?? throw new \LogicException('setCategory() must be called before use.');
64    }
69    protected function plurals(): Plurals
70    {
71        return $this->plurals ?? throw new \LogicException('setPlurals() must be called before use.');
72    }
74    public function setCategoryRelation(Relation $categoryRelation): AbstractHelper
75    {
76        $this->categoryRelation = $categoryRelation;
77        return $this;
78    }
80    public function setTags(Tags $Tags): AbstractHelper
81    {
82        $this->Tags = $Tags;
83        return $this;
84    }
86    public function setPlurals(Plurals $plurals): AbstractHelper
87    {
88        $this->plurals = $plurals;
89        return $this;
90    }
92    public function setSessionId(int|string $sid): AbstractHelper
93    {
94        $this->sessionId = $sid;
95        return $this;
96    }
98    public function setConfiguration(Configuration $configuration): AbstractHelper
99    {
100        $this->configuration = $configuration;
101        return $this;
102    }
104    public function getConfiguration(): Configuration
105    {
106        return $this->configuration;
107    }