Passed
Push — master ( 417a35...0ba0fc )
by Thierry
02:47
created

RequestFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
eloc 16
c 4
b 0
f 0
dl 0
loc 78
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A call() 0 7 1
A noPrefix() 0 4 1
A __call() 0 7 2
A __construct() 0 5 1
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
 * RequestFactory.php
7
 *
8
 * Create Jaxon client side requests, which will generate the client script necessary
9
 * to invoke a jaxon request from the browser to registered objects.
10
 *
11
 * @package jaxon-core
12
 * @author Thierry Feuzeu
13
 * @copyright 2022 Thierry Feuzeu <[email protected]>
14
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
15
 * @link https://github.com/jaxon-php/jaxon-core
16
 */
17
18
use Jaxon\App\Dialog\Library\DialogLibraryManager;
19
use Jaxon\Request\Call\Call;
20
use Jaxon\Request\Call\Paginator;
21
22
use function array_shift;
23
use function func_get_args;
24
25
class RequestFactory
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class RequestFactory
Loading history...
26
{
27
    /**
28
     * @var string
29
     */
30
    protected $sPrefix;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
31
32
    /**
33
     * @var bool
0 ignored issues
show
Bug introduced by
Expected "boolean" but found "bool" for @var tag in member variable comment
Loading history...
34
     */
35
    protected $bNoPrefix = false;
36
37
    /**
38
     * @var DialogLibraryManager
39
     */
40
    protected $xDialogLibraryManager;
41
42
    /**
43
     * @var Paginator
44
     */
45
    protected $xPaginator;
46
47
    /**
48
     * The class constructor
49
     *
50
     * @param string $sPrefix
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 15 spaces after parameter type; 1 found
Loading history...
51
     * @param DialogLibraryManager $xDialogLibraryManager
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
52
     * @param Paginator $xPaginator
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
53
     */
54
    public function __construct(string $sPrefix, DialogLibraryManager $xDialogLibraryManager, Paginator $xPaginator)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
55
    {
56
        $this->sPrefix = $sPrefix;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 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...
57
        $this->xDialogLibraryManager = $xDialogLibraryManager;
58
        $this->xPaginator = $xPaginator;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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...
59
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
60
61
    /**
62
     * @param bool $bNoPrefix
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
63
     *
64
     * @return RequestFactory
65
     */
66
    public function noPrefix(bool $bNoPrefix): RequestFactory
67
    {
68
        $this->bNoPrefix = $bNoPrefix;
69
        return $this;
70
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
71
72
    /**
73
     * Generate the javascript code for a call to a given method
74
     *
75
     * @param string $sFunction
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
76
     * @param array $aArguments
0 ignored issues
show
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
77
     *
78
     * @return Call
79
     */
80
    public function __call(string $sFunction, array $aArguments): Call
81
    {
82
        // Make the request
83
        $sPrefix = $this->bNoPrefix ? '' : $this->sPrefix;
84
        $xCall = new Call($sPrefix . $sFunction, $this->xDialogLibraryManager, $this->xPaginator);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 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...
85
        $xCall->addParameters($aArguments);
86
        return $xCall;
87
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
88
89
    /**
90
     * Return the javascript call to a Jaxon function or object method
91
     *
92
     * @param string $sFunction    The function or method (without class) name
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter name; 4 found
Loading history...
93
     *
94
     * @return Call
95
     */
96
    public function call(string $sFunction): Call
97
    {
98
        $aArguments = func_get_args();
99
        // Remove the function name from the arguments array.
100
        array_shift($aArguments);
101
        // Make the request
102
        return $this->__call($sFunction, $aArguments);
103
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
104
}
105