Passed
Push — master ( 146be5...1e12ef )
by ANTHONIUS
06:12
created

RemoteSession::init()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4.2084

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 4
nop 1
dl 0
loc 18
ccs 13
cts 17
cp 0.7647
crap 4.2084
rs 9.8666
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A RemoteSession::doStartSession() 0 12 2
1
<?php
2
3
/*
4
 * This file is part of the doyo/code-coverage project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\Bridge\CodeCoverage\Session;
15
16
use Doyo\Bridge\CodeCoverage\ContainerFactory;
17
use Doyo\Bridge\CodeCoverage\Driver\Dummy;
18
use Doyo\Bridge\CodeCoverage\Exception\SessionException;
19
use Doyo\Bridge\CodeCoverage\Processor;
20
use Doyo\Bridge\CodeCoverage\TestCase;
21
use SebastianBergmann\CodeCoverage\Filter;
22
23
class RemoteSession extends AbstractSession
24
{
25
    const HEADER_SESSION_KEY   = 'HTTP_DOYO_COVERAGE_SESSION';
26
    const HEADER_TEST_CASE_KEY = 'HTTP_DOYO_COVERAGE_TESTCASE';
27
28
    public static function startSession()
29
    {
30
        if (!isset($_SERVER[static::HEADER_SESSION_KEY])) {
31
            return false;
32
        }
33
34
        $name    = $_SERVER[static::HEADER_SESSION_KEY];
35
        $session = new static($name);
36
37
        if (isset($_SERVER[static::HEADER_TEST_CASE_KEY])) {
38
            $session->doStartSession();
39
        } else {
40
            return false;
41
        }
42
        $session->save();
43
44
        return true;
45
    }
46
47
    public function doStartSession()
48
    {
49
        $name     = $_SERVER[static::HEADER_TEST_CASE_KEY];
50
        $testCase = new TestCase($name);
51
        $this->setTestCase($testCase);
52
53
        try {
54
            $this->start();
55
            register_shutdown_function([$this, 'shutdown']);
56
        } catch (\Exception $e) {
57
            $this->reset();
58
            $this->exceptions[] = $e;
59
        }
60
    }
61
}
62