Passed
Pull Request — master (#336)
by Tim
02:12
created

MockContainer::debugMessage()   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 2
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\Clock\ClockInterface;
8
use Psr\Log\LoggerInterface;
9
use Psr\Log\NullLogger;
10
11
use function chmod;
12
use function file_put_contents;
13
use function sys_get_temp_dir;
14
15
/**
16
 * Class \SimpleSAML\SAML2\Compat\MockContainer
17
 */
18
class MockContainer extends AbstractContainer
19
{
20
    /** @var \Psr\Clock\ClockInterface */
21
    private ClockInterface $clock;
22
23
    /** @var array */
24
    private array $debugMessages = [];
25
26
27
    /**
28
     * Get a PSR-3 compatible logger.
29
     * @return \Psr\Log\LoggerInterface
30
     */
31
    public function getLogger(): LoggerInterface
32
    {
33
        return new NullLogger();
34
    }
35
36
37
    /**
38
     * Log an incoming message to the debug log.
39
     *
40
     * Type can be either:
41
     * - **in** XML received from third party
42
     * - **out** XML that will be sent to third party
43
     * - **encrypt** XML that is about to be encrypted
44
     * - **decrypt** XML that was just decrypted
45
     *
46
     * @param \DOMElement|string $message
47
     * @param string $type
48
     */
49
    public function debugMessage($message, string $type): void
50
    {
51
        $this->debugMessages[$type] = $message;
52
    }
53
54
55
    /**
56
     * Trigger the user to perform a POST to the given URL with the given data.
57
     *
58
     * @param string|null $url
59
     * @param array $data
60
     * @return string
61
     */
62
    public function getPOSTRedirectURL(
63
        /** @scrutinizer ignore-unused */string $url = null,
64
        /** @scrutinizer ignore-unused */array $data = []
65
    ): string {
66
        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...
67
    }
68
69
70
    /**
71
     * @return string
72
     */
73
    public function getTempDir(): string
74
    {
75
        return sys_get_temp_dir();
76
    }
77
78
79
    /**
80
     * @param string $filename
81
     * @param string $data
82
     * @param int|null $mode
83
     */
84
    public function writeFile(string $filename, string $data, int $mode = null): void
85
    {
86
        if ($mode === null) {
87
            $mode = 0600;
88
        }
89
        file_put_contents($filename, $data);
90
        chmod($filename, $mode);
91
    }
92
93
94
    /**
95
     * @inheritDoc
96
     */
97
    public function setBlacklistedAlgorithms(?array $algos): void
98
    {
99
        $this->blacklistedEncryptionAlgorithms = [];
100
    }
101
102
103
    /**
104
     * Set the system clock
105
     *
106
     * @param \Psr\Clock\ClockInterface
107
     * @return void
108
     */
109
    public function setClock(ClockInterface $clock): void
110
    {
111
        $this->clock = $clock;
112
    }
113
114
115
    /**
116
     * Get the system clock
117
     *
118
     * @return \Psr\Clock\ClockInterface
119
     */
120
    public function getClock(): ClockInterface
121
    {
122
        return $this->clock;
123
    }
124
}
125