Passed
Pull Request — master (#18)
by ANTHONIUS
03:48 queued 01:30
created

RemoteSession::doStartSession()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 3
nop 0
dl 0
loc 12
ccs 0
cts 11
cp 0
crap 6
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the doyo/code-coverage project.
5
 *
6
 * (c) Anthonius Munthi <https://itstoni.com>
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\TestCase;
17
18
class RemoteSession extends AbstractSession
19
{
20
    const HEADER_SESSION_KEY   = 'HTTP_DOYO_COVERAGE_SESSION';
21
    const HEADER_TEST_CASE_KEY = 'HTTP_DOYO_COVERAGE_TESTCASE';
22
23 2
    public static function startSession()
24
    {
25 2
        if (!isset($_SERVER[static::HEADER_SESSION_KEY])) {
26 1
            return false;
27
        }
28
29 1
        if(!isset($_SERVER[static::HEADER_TEST_CASE_KEY])){
30 1
            return false;
31
        }
32
33
        $sessionName = $_SERVER[static::HEADER_SESSION_KEY];
34
        $session = new static($sessionName);
35
        $testCaseName = $_SERVER[static::HEADER_TEST_CASE_KEY];
36
        $testCase = new TestCase($testCaseName);
37
38
        try{
39
            $session->setTestCase($testCase);
40
            $session->start();
41 1
            $session->save();
42 1
            return true;
43
        }catch (\Exception $e){
44
            $session->addException($e);
45
            $session->save();
46
            return false;
47
        }
48
    }
49
}
50