Passed
Push — master ( 25fd26...1cb796 )
by Jaime Pérez
02:17
created

Container::postRedirect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SAML2\Compat\Ssp;
6
7
use Psr\Log\LoggerInterface;
8
use SAML2\Compat\ContainerInterface;
9
use SAML2\XML\AbstractXMLElement;
10
use SAML2\XML\saml\CustomIdentifierInterface;
11
use SimpleSAML\Utils\HTTP;
1 ignored issue
show
Bug introduced by
The type SimpleSAML\Utils\HTTP 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...
12
use SimpleSAML\Utils\Random;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Utils\Random 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...
13
use SimpleSAML\Utils\System;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Utils\System 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...
14
use SimpleSAML\Utils\XML;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Utils\XML 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...
15
use Webmozart\Assert\Assert;
16
17
class Container implements ContainerInterface
18
{
19
    /**
20
     * @var \Psr\Log\LoggerInterface
21
     */
22
    protected $logger;
23
24
    /** @var array */
25
    protected $registry = [];
26
27
28
    /**
29
     * Create a new SimpleSAMLphp compatible container.
30
     */
31
    public function __construct()
32
    {
33
        $this->logger = new Logger();
34
    }
35
36
37
    /**
38
     * {@inheritdoc}
39
     * @return \Psr\Log\LoggerInterface
40
     */
41
    public function getLogger(): LoggerInterface
42
    {
43
        return $this->logger;
44
    }
45
46
47
    /**
48
     * {@inheritdoc}
49
     * @return string
50
     */
51
    public function generateId(): string
52
    {
53
        /** @psalm-suppress UndefinedClass */
54
        return Random::generateID();
55
    }
56
57
58
    /**
59
     * {@inheritdoc}
60
     * @param mixed $message
61
     * @param string $type
62
     * @return void
63
     */
64
    public function debugMessage($message, string $type): void
65
    {
66
        /** @psalm-suppress UndefinedClass */
67
        XML::debugSAMLMessage($message, $type);
68
    }
69
70
71
    /**
72
     * {@inheritdoc}
73
     * @param string $url
74
     * @param array $data
75
     * @return void
76
     */
77
    public function redirect(string $url, array $data = []): void
78
    {
79
        /** @psalm-suppress UndefinedClass */
80
        HTTP::redirectTrustedURL($url, $data);
81
    }
82
83
84
    /**
85
     * {@inheritdoc}
86
     * @param string $url
87
     * @param array $data
88
     * @return void
89
     */
90
    public function postRedirect(string $url, array $data = []): void
91
    {
92
        /** @psalm-suppress UndefinedClass */
93
        HTTP::submitPOSTData($url, $data);
94
    }
95
96
97
    /**
98
     * {@inheritdoc}
99
     * @return string
100
     */
101
    public function getTempDir(): string
102
    {
103
        /** @psalm-suppress UndefinedClass */
104
        return System::getTempDir();
105
    }
106
107
108
    /**
109
     * {@inheritdoc}
110
     * @param string $filename
111
     * @param string $date
112
     * @param int|null $mode
113
     * @return void
114
     */
115
    public function writeFile(string $filename, string $data, int $mode = null): void
116
    {
117
        if ($mode === null) {
118
            $mode = 0600;
119
        }
120
        /** @psalm-suppress UndefinedClass */
121
        System::writeFile($filename, $data, $mode);
122
    }
123
124
125
    /**
126
     * @inheritDoc
127
     */
128
    public function registerExtensionHandler(string $class): void
129
    {
130
        Assert::subclassOf($class, AbstractXMLElement::class);
131
132
        if (is_subclass_of($class, CustomIdentifierInterface::class, true)) {
133
            $key = $class::getXsiType() . ':BaseID';
134
        } else {
135
            $key = join(':', [urlencode($class::NS), AbstractXMLElement::getClassName($class)]);
136
        }
137
        $this->registry[$key] = $class;
138
    }
139
140
141
    /**
142
     * @inheritDoc
143
     */
144
    public function getElementHandler(string $namespace, string $element): ?string
145
    {
146
        Assert::notEmpty($namespace, 'Cannot search for handlers without an associated namespace URI.');
147
        Assert::notEmpty($element, 'Cannot search for handlers without an associated element name.');
148
149
        return $this->registry[join(':', [urlencode($namespace), $element])];
150
    }
151
152
153
    /**
154
     * @inheritDoc
155
     */
156
    public function getIdentifierHandler(string $type): ?string
157
    {
158
        Assert::notEmpty($type, 'Cannot search for identifier handlers with an empty type.');
159
        return $this->registry[$type . ':BaseID'];
160
    }
161
}
162