Passed
Push — v5.x ( fe38d4...6ac3c7 )
by Thierry
10:27
created

Factory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 17
c 2
b 0
f 0
dl 0
loc 88
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A rq() 0 7 2
A pm() 0 3 1
A __construct() 0 10 1
A js() 0 7 2
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Request\Factory;
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 JsCallFactory
42
     */
43
    protected $xRqFunctionFactory;
44
45
    /**
46
     * @var JsCallFactory
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 JsCallFactory($sFunctionPrefix, $this->xDialogManager);
66
        // Factory for Js functions
67
        $this->xJsFunctionFactory = new JsCallFactory($sFunctionPrefix, $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 JsCallFactory|null
76
     * @throws SetupException
77
     */
78
    public function rq(string $sClassName = ''): ?JsCallFactory
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->getJsCallFactory($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 JsCallFactory|null
93
     */
94
    public function js(string $sClassName = ''): ?JsCallFactory
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 JsCallFactory($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