Passed
Push — master ( 6f7a23...2cf817 )
by Thierry
02:29
created

Factory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 60
rs 10
c 2
b 0
f 0
wmc 4

3 Methods

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