ParameterFactory   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 131
rs 10
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A page() 0 4 1
A checked() 0 3 1
A int() 0 3 1
A javascript() 0 3 1
A string() 0 3 1
A js() 0 3 1
A select() 0 3 1
A html() 0 3 1
A input() 0 3 1
A numeric() 0 3 1
A form() 0 3 1
1
<?php
2
3
/**
4
 * ParameterFactory.php
5
 *
6
 * Create parameters for calls to js functions and selectors.
7
 *
8
 * @package jaxon-core
9
 * @author Thierry Feuzeu <[email protected]>
10
 * @copyright 2016 Thierry Feuzeu <[email protected]>
11
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
12
 * @link https://github.com/jaxon-php/jaxon-core
13
 */
14
15
namespace Jaxon\Script\Factory;
16
17
use Jaxon\Script\Call\Parameter;
18
19
class ParameterFactory
20
{
21
    /**
22
     * Make a parameter of type Parameter::FORM_VALUES
23
     *
24
     * @param string $sFormId    The id of the HTML form
25
     *
26
     * @return Parameter
27
     */
28
    public function form(string $sFormId): Parameter
29
    {
30
        return new Parameter(Parameter::FORM_VALUES, $sFormId);
31
    }
32
33
    /**
34
     * Make a parameter of type Parameter::INPUT_VALUE
35
     *
36
     * @param string $sInputId    the id of the HTML input element
37
     *
38
     * @return Parameter
39
     */
40
    public function input(string $sInputId): Parameter
41
    {
42
        return new Parameter(Parameter::INPUT_VALUE, $sInputId);
43
    }
44
45
    /**
46
     * Make a parameter of type Parameter::CHECKED_VALUE
47
     *
48
     * @param string $sInputId    the name of the HTML form element
49
     *
50
     * @return Parameter
51
     */
52
    public function checked(string $sInputId): Parameter
53
    {
54
        return new Parameter(Parameter::CHECKED_VALUE, $sInputId);
55
    }
56
57
    /**
58
     * Make a parameter of type Parameter::CHECKED_VALUE
59
     *
60
     * @param string $sInputId    the name of the HTML form element
61
     *
62
     * @return Parameter
63
     */
64
    public function select(string $sInputId): Parameter
65
    {
66
        return $this->input($sInputId);
67
    }
68
69
    /**
70
     * Make a parameter of type Parameter::ELEMENT_INNERHTML
71
     *
72
     * @param string $sElementId    the id of the HTML element
73
     *
74
     * @return Parameter
75
     */
76
    public function html(string $sElementId): Parameter
77
    {
78
        return new Parameter(Parameter::ELEMENT_INNERHTML, $sElementId);
79
    }
80
81
    /**
82
     * Make a parameter of type Parameter::QUOTED_VALUE
83
     *
84
     * @param string $sValue    the value of the parameter
85
     *
86
     * @return Parameter
87
     */
88
    public function string(string $sValue): Parameter
89
    {
90
        return new Parameter(Parameter::QUOTED_VALUE, $sValue);
91
    }
92
93
    /**
94
     * Make a parameter of type Parameter::NUMERIC_VALUE
95
     *
96
     * @param int $nValue    the value of the parameter
97
     *
98
     * @return Parameter
99
     */
100
    public function numeric(int $nValue): Parameter
101
    {
102
        return new Parameter(Parameter::NUMERIC_VALUE, intval($nValue));
103
    }
104
105
    /**
106
     * Make a parameter of type Parameter::NUMERIC_VALUE
107
     *
108
     * @param numeric $nValue    the value of the parameter
0 ignored issues
show
Bug introduced by
The type Jaxon\Script\Factory\numeric was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
109
     *
110
     * @return Parameter
111
     */
112
    public function int(int $nValue): Parameter
113
    {
114
        return $this->numeric($nValue);
115
    }
116
117
    /**
118
     * Make a parameter of type Parameter::JS_VALUE
119
     *
120
     * @param string $sValue    the javascript code of the parameter
121
     *
122
     * @return Parameter
123
     */
124
    public function javascript(string $sValue): Parameter
125
    {
126
        return new Parameter(Parameter::JS_VALUE, $sValue);
127
    }
128
129
    /**
130
     * Make a parameter of type Parameter::JS_VALUE
131
     *
132
     * @param string $sValue    the javascript code of the parameter
133
     *
134
     * @return Parameter
135
     */
136
    public function js(string $sValue): Parameter
137
    {
138
        return $this->javascript($sValue);
139
    }
140
141
    /**
142
     * Make a parameter of type Parameter::PAGE_NUMBER
143
     *
144
     * @return Parameter
145
     */
146
    public function page(): Parameter
147
    {
148
        // By default, the value of a parameter of type Parameter::PAGE_NUMBER is 0.
149
        return new Parameter(Parameter::PAGE_NUMBER, 0);
150
    }
151
}
152