Passed
Pull Request — master (#336)
by Tim
03:28 queued 01:20
created

MockContainer::getPOSTRedirectURL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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