Passed
Push — v5.x ( 6ac3c7...223ede )
by Thierry
02:17
created

Factory::rq()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Js;
4
5
/**
0 ignored issues
show
Coding Style introduced by
Block comments must be started with /*
Loading history...
6
 * Factory.php
7
 *
8
 * Gives access to the factories.
9
 *
10
 * @package jaxon-core
11
 * @author Thierry Feuzeu <[email protected]>
12
 * @copyright 2022 Thierry Feuzeu <[email protected]>
13
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
14
 * @link https://github.com/jaxon-php/jaxon-core
15
 */
16
17
use Jaxon\App\Dialog\DialogManager;
18
use Jaxon\Exception\SetupException;
19
use Jaxon\Plugin\Request\CallableClass\CallableRegistry;
20
21
use function trim;
22
23
class Factory
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Factory
Loading history...
24
{
25
    /**
26
     * @var CallableRegistry
27
     */
28
    private $xCallableRegistry;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
29
30
    /**
31
     * @var DialogManager
32
     */
33
    protected $xDialogManager;
34
35
    /**
36
     * @var ParameterFactory
37
     */
38
    protected $xParameterFactory;
39
40
    /**
41
     * @var CallFactory
42
     */
43
    protected $xRqFunctionFactory;
44
45
    /**
46
     * @var CallFactory
47
     */
48
    protected $xJsFunctionFactory;
49
50
    /**
51
     * The constructor.
52
     *
53
     * @param CallableRegistry $xCallableRegistry
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
54
     * @param DialogManager $xDialogManager
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
55
     * @param ParameterFactory $xParameterFactory
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
56
     * @param string $sFunctionPrefix
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 11 spaces after parameter type; 1 found
Loading history...
57
     */
58
    public function __construct(CallableRegistry $xCallableRegistry,
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
59
        DialogManager $xDialogManager, ParameterFactory $xParameterFactory, string $sFunctionPrefix)
60
    {
61
        $this->xCallableRegistry = $xCallableRegistry;
62
        $this->xDialogManager = $xDialogManager;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
63
        $this->xParameterFactory = $xParameterFactory;
64
        // Factory for registered functions
65
        $this->xRqFunctionFactory = new CallFactory($sFunctionPrefix, $this->xDialogManager);
66
        // Factory for Js functions
67
        $this->xJsFunctionFactory = new CallFactory('', $this->xDialogManager);
68
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
69
70
    /**
71
     * Get the js call factory.
72
     *
73
     * @param string $sClassName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
74
     *
75
     * @return CallFactory|null
76
     * @throws SetupException
77
     */
78
    public function rq(string $sClassName = ''): ?CallFactory
79
    {
80
        $sClassName = trim($sClassName);
81
        // There is a single request factory for all callable functions,
82
        // while each callable class has it own request factory.
83
        return !$sClassName ? $this->xRqFunctionFactory :
0 ignored issues
show
Coding Style introduced by
Expected 1 space after ":"; newline found
Loading history...
84
            $this->xCallableRegistry->getCallFactory($sClassName);
85
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
86
87
    /**
88
     * Get the js call factory.
89
     *
90
     * @param string $sClassName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
91
     *
92
     * @return CallFactory|null
93
     */
94
    public function js(string $sClassName = ''): ?CallFactory
95
    {
96
        $sClassName = trim($sClassName);
97
        // There is a single request factory for all js functions,
98
        // while each js object has it own request factory.
99
        return !$sClassName ? $this->xJsFunctionFactory :
0 ignored issues
show
Coding Style introduced by
Expected 1 space after ":"; newline found
Loading history...
100
            new CallFactory($sClassName . '.', $this->xDialogManager);
101
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
102
103
    /**
104
     * Get the js call parameter factory.
105
     *
106
     * @return ParameterFactory
107
     */
108
    public function pm(): ParameterFactory
109
    {
110
        return $this->xParameterFactory;
111
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
112
}
113