Passed
Push — develop ( ec1e42...80559e )
by Brent
03:22
created

DevelopmentServer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A make() 0 8 1
A run() 0 11 2
1
<?php
2
3
namespace Stitcher\Application;
4
5
use Stitcher\Command\PartialParse;
6
7
class DevelopmentServer
8
{
9
    protected $rootDirectory;
10
    protected $uri = null;
11
    protected $partialParse;
12
13 3
    public function __construct(
14
        string $rootDirectory,
15
        PartialParse $partialParse,
16
        string $uri = null
17
    ) {
18 3
        $this->rootDirectory = $rootDirectory;
19 3
        $this->uri = $uri;
20 3
        $this->partialParse = $partialParse;
21 3
    }
22
23 2
    public static function make(
24
        string $rootDirectory,
25
        PartialParse $partialParse,
26
        string $uri = null
27
    ): DevelopmentServer
28
    {
29 2
        return new self($rootDirectory, $partialParse, $uri);
30
    }
31
32 2
    public function run(): string
33
    {
34 2
        $uri = $this->uri ?? $_SERVER['SCRIPT_NAME'];
35
36 2
        $this->partialParse->setFilter($uri);
37 2
        $this->partialParse->execute();
38
39 2
        $filename = ltrim($uri === '/' ? 'index.html' : "{$uri}.html", '/');
40
41 2
        return @file_get_contents("{$this->rootDirectory}/{$filename}");
42
    }
43
}
44