Passed
Push — develop ( e4768a...6d9d8a )
by Nikolay
04:23
created

BaseForm   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
dl 0
loc 28
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 3 1
A addTextArea() 0 11 2
1
<?php
2
/*
3
 * MikoPBX - free phone system for small business
4
 * Copyright (C) 2017-2023 Alexey Portnov and Nikolay Beketov
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with this program.
17
 * If not, see <https://www.gnu.org/licenses/>.
18
 */
19
20
namespace MikoPBX\AdminCabinet\Forms;
21
22
23
use MikoPBX\Common\Models\PbxExtensionModules;
24
use MikoPBX\Common\Providers\PBXConfModulesProvider;
25
use MikoPBX\Modules\Config\WebUIConfigInterface;
26
use Phalcon\Forms\Element\TextArea;
27
use Phalcon\Forms\Form;
28
29
abstract class BaseForm extends Form
30
{
31
32
    public function initialize($entity = null, $options = null): void
33
    {
34
        PBXConfModulesProvider::hookModulesMethod(WebUIConfigInterface::ON_BEFORE_FORM_INITIALIZE, [$this, $entity, $options]);
35
    }
36
37
    /**
38
     * Add a textarea form element.
39
     *
40
     * @param string $areaName The name of the textarea field.
41
     * @param string $areaValue The initial value for the textarea field.
42
     * @param int $areaWidth The width of the textarea field in columns (optional, default: 85).
43
     *
44
     * @return void
45
     */
46
    public function addTextArea(string $areaName, string $areaValue, int $areaWidth = 85): void
0 ignored issues
show
Unused Code introduced by
The parameter $areaWidth is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
    public function addTextArea(string $areaName, string $areaValue, /** @scrutinizer ignore-unused */ int $areaWidth = 85): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
        $rows = 1;
49
        $strings = explode("\n", $areaValue);
50
        foreach ($strings as $string) {
51
            $rows += ceil(strlen($string) / 65);
52
        }
53
        $this->add(new TextArea($areaName,
54
                [
55
                    "rows" => max($rows, 2),
56
                    "value" => $areaValue
57
                ])
58
        );
59
60
    }
61
}