Factory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 40
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMockServer() 0 7 1
A getStaticRouter() 0 4 1
A getLastRequest() 0 9 2
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