Completed
Push — develop ( c86111...2faf16 )
by ANTHONIUS
21s
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
<?php
2
3
/*
4
 * This file is part of the doyo/behat-coverage-extension 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\Behat\Coverage\Bridge\CodeCoverage\Session;
15
16
use Doyo\Behat\Coverage\Bridge\CodeCoverage\Driver\Dummy;
17
use Doyo\Behat\Coverage\Bridge\CodeCoverage\Processor;
18
use Doyo\Behat\Coverage\Bridge\CodeCoverage\TestCase;
19
use SebastianBergmann\CodeCoverage\Filter;
20
21
class RemoteSession extends Session
22
{
23
    const HEADER_SESSION_KEY   = 'HTTP_DOYO_COVERAGE_SESSION';
24
    const HEADER_TEST_CASE_KEY = 'HTTP_DOYO_COVERAGE_TESTCASE';
25
26 1
    public static function startSession()
27
    {
28
        if (!isset($_SERVER[static::HEADER_SESSION_KEY])) {
29
            return null;
30
        }
31
32
        $name    = $_SERVER[static::HEADER_SESSION_KEY];
33
        $session = new static($name);
34
        if (isset($_SERVER[static::HEADER_TEST_CASE_KEY])) {
35
            $name     = $_SERVER[static::HEADER_TEST_CASE_KEY];
36
            $testCase = new TestCase($name);
37
            $session->setTestCase($testCase);
38
39
            $session->start();
40 1
            register_shutdown_function([$session, 'shutdown']);
41
        }
42
43 1
        return $session;
44
    }
45
46 3
    public function init(array $config)
47
    {
48 3
        $filter = new Filter();
49 3
        if (isset($config['filterOptions'])) {
50 2
            $filter->setWhitelistedFiles($config['filterOptions']['whitelistedFiles']);
51
        }
52
53 3
        $processor    = new Processor(new Dummy(), $filter);
54 3
        $codeCoverage = $processor->getCodeCoverage();
55 3
        if (isset($config['codeCoverageOptions'])) {
56 3
            foreach ($config['codeCoverageOptions'] as $method => $option) {
57 2
                $method = 'set'.ucfirst($method);
58 2
                \call_user_func_array([$codeCoverage, $method], [$option]);
59
            }
60 3
            $processor->setCodeCoverageOptions($config['codeCoverageOptions']);
61
        }
62 3
        $this->setProcessor($processor);
63 3
        $this->reset();
64 1
    }
65
}
66