Chris@14: Chris@14: * Chris@14: * For the full copyright and license information, please view the LICENSE Chris@14: * file that was distributed with this source code. Chris@14: */ Chris@14: Chris@14: namespace SebastianBergmann\CodeCoverage\Report; Chris@14: Chris@14: use SebastianBergmann\CodeCoverage\CodeCoverage; Chris@14: use SebastianBergmann\CodeCoverage\RuntimeException; Chris@14: Chris@14: /** Chris@14: * Uses var_export() to write a SebastianBergmann\CodeCoverage\CodeCoverage object to a file. Chris@14: */ Chris@14: class PHP Chris@14: { Chris@14: /** Chris@14: * @param CodeCoverage $coverage Chris@14: * @param string $target Chris@14: * Chris@14: * @return string Chris@14: */ Chris@14: public function process(CodeCoverage $coverage, $target = null) Chris@14: { Chris@14: $filter = $coverage->filter(); Chris@14: Chris@14: $buffer = \sprintf( Chris@14: 'setData(%s); Chris@14: $coverage->setTests(%s); Chris@14: Chris@14: $filter = $coverage->filter(); Chris@14: $filter->setWhitelistedFiles(%s); Chris@14: Chris@14: return $coverage;', Chris@14: \var_export($coverage->getData(true), 1), Chris@14: \var_export($coverage->getTests(), 1), Chris@14: \var_export($filter->getWhitelistedFiles(), 1) Chris@14: ); Chris@14: Chris@14: if ($target !== null) { Chris@14: if (@\file_put_contents($target, $buffer) === false) { Chris@14: throw new RuntimeException( Chris@14: \sprintf( Chris@14: 'Could not write to "%s', Chris@14: $target Chris@14: ) Chris@14: ); Chris@14: } Chris@14: } Chris@14: Chris@14: return $buffer; Chris@14: } Chris@14: }