Passed
Pull Request — master (#326)
by Tim
02:30
created

MockContainer::getTempDir()   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
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Compat;
6
7
use Psr\Log\LoggerInterface;
8
use Psr\Log\NullLogger;
9
10
use function chmod;
11
use function file_put_contents;
12
use function sys_get_temp_dir;
13
14
/**
15
 * Class \SimpleSAML\SAML2\Compat\MockContainer
16
 */
17
class MockContainer extends AbstractContainer
18
{
19
    /**
20
     * @var string
21
     */
22
    private string $id = 's2a0da3504aff978b0f8c80f6a62c713c4a2f64c5b';
23
24
    /**
25
     * @var array
26
     */
27
    private array $debugMessages = [];
28
29
30
    /**
31
     * Get a PSR-3 compatible logger.
32
     * @return \Psr\Log\LoggerInterface
33
     */
34
    public function getLogger(): LoggerInterface
35
    {
36
        return new NullLogger();
37
    }
38
39
40
    /**
41
     * Generate a random identifier for identifying SAML2 documents.
42
     * @return string
43
     */
44
    public function generateId(): string
45
    {
46
        return $this->id;
47
    }
48
49
50
    /**
51
     * Log an incoming message to the debug log.
52
     *
53
     * Type can be either:
54
     * - **in** XML received from third party
55
     * - **out** XML that will be sent to third party
56
     * - **encrypt** XML that is about to be encrypted
57
     * - **decrypt** XML that was just decrypted
58
     *
59
     * @param \DOMElement|string $message
60
     * @param string $type
61
     */
62
    public function debugMessage($message, string $type): void
63
    {
64
        $this->debugMessages[$type] = $message;
65
    }
66
67
68
    /**
69
     * Trigger the user to perform a POST to the given URL with the given data.
70
     *
71
     * @param string|null $url
72
     * @param array $data
73
     * @return string
74
     */
75
    public function getPOSTRedirectURL(
76
        /** @scrutinizer ignore-unused */string $url = null,
77
        /** @scrutinizer ignore-unused */array $data = []
78
    ): string {
79
        return $url;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $url could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
80
    }
81
82
83
    /**
84
     * @return string
85
     */
86
    public function getTempDir(): string
87
    {
88
        return sys_get_temp_dir();
89
    }
90
91
92
    /**
93
     * @param string $filename
94
     * @param string $data
95
     * @param int|null $mode
96
     */
97
    public function writeFile(string $filename, string $data, int $mode = null): void
98
    {
99
        if ($mode === null) {
100
            $mode = 0600;
101
        }
102
        file_put_contents($filename, $data);
103
        chmod($filename, $mode);
104
    }
105
106
107
    /**
108
     * @inheritDoc
109
     */
110
    public function setBlacklistedAlgorithms(?array $algos): void
111
    {
112
        $this->blacklistedEncryptionAlgorithms = [];
113
    }
114
}
115