comparison vendor/phpunit/php-code-coverage/src/Report/PHP.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2 /*
3 * This file is part of the php-code-coverage package.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 namespace SebastianBergmann\CodeCoverage\Report;
12
13 use SebastianBergmann\CodeCoverage\CodeCoverage;
14 use SebastianBergmann\CodeCoverage\RuntimeException;
15
16 /**
17 * Uses var_export() to write a SebastianBergmann\CodeCoverage\CodeCoverage object to a file.
18 */
19 class PHP
20 {
21 /**
22 * @param CodeCoverage $coverage
23 * @param string $target
24 *
25 * @return string
26 */
27 public function process(CodeCoverage $coverage, $target = null)
28 {
29 $filter = $coverage->filter();
30
31 $buffer = \sprintf(
32 '<?php
33 $coverage = new SebastianBergmann\CodeCoverage\CodeCoverage;
34 $coverage->setData(%s);
35 $coverage->setTests(%s);
36
37 $filter = $coverage->filter();
38 $filter->setWhitelistedFiles(%s);
39
40 return $coverage;',
41 \var_export($coverage->getData(true), 1),
42 \var_export($coverage->getTests(), 1),
43 \var_export($filter->getWhitelistedFiles(), 1)
44 );
45
46 if ($target !== null) {
47 if (@\file_put_contents($target, $buffer) === false) {
48 throw new RuntimeException(
49 \sprintf(
50 'Could not write to "%s',
51 $target
52 )
53 );
54 }
55 }
56
57 return $buffer;
58 }
59 }