Passed
Push — master ( 55799d...96950c )
by Tim
02:56
created

MockContainer::writeFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 7
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 array
21
     */
22
    private array $debugMessages = [];
23
24
25
    /**
26
     * Get a PSR-3 compatible logger.
27
     * @return \Psr\Log\LoggerInterface
28
     */
29
    public function getLogger(): LoggerInterface
30
    {
31
        return new NullLogger();
32
    }
33
34
35
    /**
36
     * Log an incoming message to the debug log.
37
     *
38
     * Type can be either:
39
     * - **in** XML received from third party
40
     * - **out** XML that will be sent to third party
41
     * - **encrypt** XML that is about to be encrypted
42
     * - **decrypt** XML that was just decrypted
43
     *
44
     * @param \DOMElement|string $message
45
     * @param string $type
46
     */
47
    public function debugMessage($message, string $type): void
48
    {
49
        $this->debugMessages[$type] = $message;
50
    }
51
52
53
    /**
54
     * Trigger the user to perform a POST to the given URL with the given data.
55
     *
56
     * @param string|null $url
57
     * @param array $data
58
     * @return string
59
     */
60
    public function getPOSTRedirectURL(
61
        /** @scrutinizer ignore-unused */string $url = null,
62
        /** @scrutinizer ignore-unused */array $data = []
63
    ): string {
64
        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...
65
    }
66
67
68
    /**
69
     * @return string
70
     */
71
    public function getTempDir(): string
72
    {
73
        return sys_get_temp_dir();
74
    }
75
76
77
    /**
78
     * @param string $filename
79
     * @param string $data
80
     * @param int|null $mode
81
     */
82
    public function writeFile(string $filename, string $data, int $mode = null): void
83
    {
84
        if ($mode === null) {
85
            $mode = 0600;
86
        }
87
        file_put_contents($filename, $data);
88
        chmod($filename, $mode);
89
    }
90
91
92
    /**
93
     * @inheritDoc
94
     */
95
    public function setBlacklistedAlgorithms(?array $algos): void
96
    {
97
        $this->blacklistedEncryptionAlgorithms = [];
98
    }
99
}
100