Passed
Push — master ( e82656...5198fb )
by Thierry
03:06
created

Factory::parameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Jaxon\Request;
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\Request\Factory\ParameterFactory;
18
use Jaxon\Request\Factory\RequestFactory;
19
use Jaxon\Request\Plugin\CallableClass\CallableRegistry;
20
use Jaxon\Exception\SetupException;
21
22
use function trim;
23
24
class Factory
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Factory
Loading history...
25
{
26
    /**
27
     * @var CallableRegistry
28
     */
29
    private $xClassRegistry;
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
30
31
    /**
32
     * @var RequestFactory
33
     */
34
    protected $xRequestFactory;
35
36
    /**
37
     * @var ParameterFactory
38
     */
39
    protected $xParameterFactory;
40
41
    /**
42
     * The constructor.
43
     *
44
     * @param CallableRegistry $xClassRegistry
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
45
     * @param RequestFactory $xRequestFactory
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
46
     * @param ParameterFactory $xParameterFactory
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
47
     */
48
    public function __construct(CallableRegistry $xClassRegistry,
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
49
        RequestFactory $xRequestFactory, ParameterFactory $xParameterFactory)
50
    {
51
        $this->xClassRegistry = $xClassRegistry;
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...
52
        $this->xRequestFactory = $xRequestFactory;
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...
53
        $this->xParameterFactory = $xParameterFactory;
54
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
55
56
    /**
57
     * Get the ajax request factory.
58
     *
59
     * @param string $sClassName
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
60
     *
61
     * @return RequestFactory|null
62
     * @throws SetupException
63
     */
64
    public function request(string $sClassName = ''): ?RequestFactory
65
    {
66
        $sClassName = trim($sClassName);
67
        if(!$sClassName)
68
        {
69
            // There is a single request factory for all callable functions.
70
            return $this->xRequestFactory;
71
        }
72
        // While each callable class has it own request factory.
73
        return $this->xClassRegistry->getRequestFactory($sClassName);
74
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
75
76
    /**
77
     * Get the request parameter factory.
78
     *
79
     * @return ParameterFactory
80
     */
81
    public function parameter(): ParameterFactory
82
    {
83
        return $this->xParameterFactory;
84
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
85
}
86