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

MockContainer::getIdentifierHandler()   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 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SAML2\Compat;
6
7
use Psr\Log\LoggerInterface;
8
use Psr\Log\NullLogger;
9
10
/**
11
 * Class \SAML2\Compat\MockContainer
12
 */
13
class MockContainer implements ContainerInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    private $id = '123';
19
20
    /**
21
     * @var array
22
     */
23
    private $debugMessages = [];
24
25
    /**
26
     * @var string
27
     */
28
    private $redirectUrl;
29
30
    /**
31
     * @var array
32
     */
33
    private $redirectData = [];
34
35
    /**
36
     * @var string|null
37
     */
38
    private $postRedirectUrl = null;
39
40
    /**
41
     * @var array
42
     */
43
    private $postRedirectData;
44
45
46
    /**
47
     * Get a PSR-3 compatible logger.
48
     * @return \Psr\Log\LoggerInterface
49
     */
50
    public function getLogger(): LoggerInterface
51
    {
52
        return new NullLogger();
53
    }
54
55
56
    /**
57
     * Generate a random identifier for identifying SAML2 documents.
58
     * @return string
59
     */
60
    public function generateId(): string
61
    {
62
        return $this->id;
63
    }
64
65
66
    /**
67
     * Log an incoming message to the debug log.
68
     *
69
     * Type can be either:
70
     * - **in** XML received from third party
71
     * - **out** XML that will be sent to third party
72
     * - **encrypt** XML that is about to be encrypted
73
     * - **decrypt** XML that was just decrypted
74
     *
75
     * @param \DOMElement|string $message
76
     * @param string $type
77
     * @return void
78
     */
79
    public function debugMessage($message, string $type): void
80
    {
81
        $this->debugMessages[$type] = $message;
82
    }
83
84
85
    /**
86
     * Trigger the user to perform a GET to the given URL with the given data.
87
     *
88
     * @param string $url
89
     * @param array $data
90
     * @return void
91
     */
92
    public function redirect(string $url, array $data = []): void
93
    {
94
        $this->redirectUrl = $url;
95
        $this->redirectData = $data;
96
    }
97
98
99
    /**
100
     * Trigger the user to perform a POST to the given URL with the given data.
101
     *
102
     * @param string|null $url
103
     * @param array $data
104
     * @return void
105
     */
106
    public function postRedirect(string $url = null, array $data = []): void
107
    {
108
        $this->postRedirectUrl = $url;
109
        $this->postRedirectData = $data;
110
    }
111
112
113
    /**
114
     * @return string
115
     */
116
    public function getTempDir(): string
117
    {
118
        return sys_get_temp_dir();
119
    }
120
121
122
    /**
123
     * @param string $filename
124
     * @param string $data
125
     * @param int|null $mode
126
     * @return void
127
     */
128
    public function writeFile(string $filename, string $data, int $mode = null): void
129
    {
130
        if ($mode === null) {
131
            $mode = 0600;
132
        }
133
        file_put_contents($filename, $data);
134
        chmod($filename, $mode);
135
    }
136
137
138
    /**
139
     * @inheritDoc
140
     */
141
    public function registerExtensionHandler(string $class): void
142
    {
143
    }
144
145
146
    /**
147
     * @inheritDoc
148
     */
149
    public function getElementHandler(string $namespace, string $element): ?string
150
    {
151
        return null;
152
    }
153
154
155
    /**
156
     * @inheritDoc
157
     */
158
    public function getIdentifierHandler(string $type): ?string
159
    {
160
        return null;
161
    }
162
}
163