Passed
Pull Request — master (#2)
by Tim
02:16
created

CDC   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 72
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A resume() 0 24 5
A server() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\Module\cdc\Controller;
6
7
use SimpleSAML\Auth;
8
use SimpleSAML\Configuration;
9
use SimpleSAML\Error;
10
use SimpleSAML\HTTP\RunnableResponse;
11
use SimpleSAML\Module\cdc\Client;
12
use SimpleSAML\Module\cdc\Server;
13
use SimpleSAML\Session;
14
use Symfony\Component\HttpFoundation\Request;
15
16
/**
17
 * Controller class for the cdc module.
18
 *
19
 * This class serves the different views available in the module.
20
 *
21
 * @package simplesamlphp/simplesamlphp-module-cdc
22
 */
23
class CDC
24
{
25
    /** @var \SimpleSAML\Configuration */
26
    protected Configuration $config;
27
28
    /** @var \SimpleSAML\Session */
29
    protected Session $session;
30
31
32
    /**
33
     * Controller constructor.
34
     *
35
     * It initializes the global configuration and session for the controllers implemented here.
36
     *
37
     * @param \SimpleSAML\Configuration $config The configuration to use by the controllers.
38
     * @param \SimpleSAML\Session $session The session to use by the controllers.
39
     *
40
     * @throws \Exception
41
     */
42
    public function __construct(
43
        Configuration $config,
44
        Session $session
45
    ) {
46
        $this->config = $config;
47
        $this->session = $session;
48
    }
49
50
51
    /**
52
     * Server
53
     *
54
     * @param \Symfony\Component\HttpFoundation\Request $request The current request.
55
     *
56
     * @return \SimpleSAML\HTTP\RunnableResponse
57
     */
58
    public function server(Request $request): RunnableResponse
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

58
    public function server(/** @scrutinizer ignore-unused */ Request $request): RunnableResponse

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
59
    {
60
        return new RunnableResponse([Server::class, 'processRequest'], []);
61
    }
62
63
64
    /**
65
     * Resume
66
     *
67
     * @param \Symfony\Component\HttpFoundation\Request $request The current request.
68
     *
69
     * @return \SimpleSAML\HTTP\RunnableResponse
70
     */
71
    public function resume(Request $request): RunnableResponse
72
    {
73
        $domain = $request->get('domain');
74
        if ($domain === null) {
75
            throw new Error\BadRequest('Missing domain to CDC resume handler.');
76
        }
77
78
        $client = new Client($domain);
79
80
        $response = $client->getResponse();
81
        if ($response === null) {
82
            throw new Error\BadRequest('Missing CDC response to CDC resume handler.');
83
        }
84
85
        if (!isset($response['id'])) {
86
            throw new Error\BadRequest('CDCResponse without id.');
87
        }
88
89
        $state = Auth\State::loadState($response['id'], 'cdc:resume');
90
        if (is_null($state)) {
91
            throw new Error\NoState();
92
        }
93
94
        return new RunningResponse([Auth\ProcessingChain::class, 'resumeProcessing'], [$state]);
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Module\cdc\Controller\RunningResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
95
    }
96
}
97