Factory::getStaticRouter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\MockServer;
4
5
use Symfony\Component\HttpFoundation\Request;
6
7
/**
8
 * Class Factory
9
 *
10
 * @package         EdmondsCommerce\MockServer
11
 * @SuppressWarnings(PHPMD.StaticAccess)
12
 */
13
class Factory
14
{
15
    /**
16
     * @return MockServer
17
     * @throws \Exception
18
     */
19 3
    public static function getMockServer(): MockServer
20
    {
21 3
        return new MockServer(
22 3
            MockServerConfig::getRouterPath(),
23 3
            MockServerConfig::getHtdocsPath(),
24 3
            MockServerConfig::getIp(),
25 3
            MockServerConfig::getPort()
26
        );
27
    }
28
29
    /**
30
     * @return StaticRouter
31
     * @throws \RuntimeException
32
     */
33 8
    public static function getStaticRouter(): StaticRouter
34
    {
35 8
        return new StaticRouter(
36 8
            MockServerConfig::getHtdocsPath()
37
        );
38
    }
39
40
    /**
41
     * @return Request
42
     * @throws \RuntimeException
43
     */
44 2
    public static function getLastRequest(): Request
45
    {
46 2
        $requestPath = MockServerConfig::getLogsPath().'/'.MockServer::REQUEST_FILE;
47 2
        $serialized  = file_get_contents($requestPath);
48 2
        if (empty($serialized)) {
49 1
            throw new \RuntimeException('request log file ['.$requestPath.'] is empty');
50
        }
51
52 1
        return unserialize($serialized, ['allowed_classes' => [Request::class]]);
53
    }
54
}
55