Laravel 5.6 updates

Travis config update

Removed HHVM script as Laravel no longer support HHVM after releasing 5.3
This commit is contained in:
Manish Verma
2018-08-06 20:08:55 +05:30
parent 126fbb0255
commit 1ac0f42a58
2464 changed files with 65239 additions and 46734 deletions

View File

@@ -12,25 +12,19 @@ namespace SebastianBergmann\CodeCoverage\Report\Xml;
use SebastianBergmann\Environment\Runtime;
class BuildInformation
final class BuildInformation
{
/**
* @var \DOMElement
*/
private $contextNode;
/**
* @param \DOMElement $contextNode
*/
public function __construct(\DOMElement $contextNode)
{
$this->contextNode = $contextNode;
}
/**
* @param Runtime $runtime
*/
public function setRuntimeInformation(Runtime $runtime)
public function setRuntimeInformation(Runtime $runtime): void
{
$runtimeNode = $this->getNodeByName('runtime');
@@ -39,12 +33,6 @@ class BuildInformation
$runtimeNode->setAttribute('url', $runtime->getVendorUrl());
$driverNode = $this->getNodeByName('driver');
if ($runtime->isHHVM()) {
$driverNode->setAttribute('name', 'hhvm');
$driverNode->setAttribute('version', \constant('HHVM_VERSION'));
return;
}
if ($runtime->hasPHPDBGCodeCoverage()) {
$driverNode->setAttribute('name', 'phpdbg');
@@ -57,22 +45,28 @@ class BuildInformation
}
}
/**
* @param $name
*
* @return \DOMElement
*/
private function getNodeByName($name)
public function setBuildTime(\DateTime $date): void
{
$this->contextNode->setAttribute('time', $date->format('D M j G:i:s T Y'));
}
public function setGeneratorVersions(string $phpUnitVersion, string $coverageVersion): void
{
$this->contextNode->setAttribute('phpunit', $phpUnitVersion);
$this->contextNode->setAttribute('coverage', $coverageVersion);
}
private function getNodeByName(string $name): \DOMElement
{
$node = $this->contextNode->getElementsByTagNameNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
$name
)->item(0);
if (!$node) {
$node = $this->contextNode->appendChild(
$this->contextNode->ownerDocument->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
$name
)
);
@@ -80,22 +74,4 @@ class BuildInformation
return $node;
}
/**
* @param \DateTime $date
*/
public function setBuildTime(\DateTime $date)
{
$this->contextNode->setAttribute('time', $date->format('D M j G:i:s T Y'));
}
/**
* @param string $phpUnitVersion
* @param string $coverageVersion
*/
public function setGeneratorVersions($phpUnitVersion, $coverageVersion)
{
$this->contextNode->setAttribute('phpunit', $phpUnitVersion);
$this->contextNode->setAttribute('coverage', $coverageVersion);
}
}

View File

@@ -12,7 +12,7 @@ namespace SebastianBergmann\CodeCoverage\Report\Xml;
use SebastianBergmann\CodeCoverage\RuntimeException;
class Coverage
final class Coverage
{
/**
* @var \XMLWriter
@@ -29,17 +29,20 @@ class Coverage
*/
private $finalized = false;
public function __construct(\DOMElement $context, $line)
public function __construct(\DOMElement $context, string $line)
{
$this->contextNode = $context;
$this->writer = new \XMLWriter();
$this->writer->openMemory();
$this->writer->startElementNs(null, $context->nodeName, 'http://schema.phpunit.de/coverage/1.0');
$this->writer->startElementNS(null, $context->nodeName, 'https://schema.phpunit.de/coverage/1.0');
$this->writer->writeAttribute('nr', $line);
}
public function addTest($test)
/**
* @throws RuntimeException
*/
public function addTest(string $test): void
{
if ($this->finalized) {
throw new RuntimeException('Coverage Report already finalized');
@@ -50,7 +53,7 @@ class Coverage
$this->writer->endElement();
}
public function finalize()
public function finalize(): void
{
$this->writer->endElement();

View File

@@ -10,6 +10,6 @@
namespace SebastianBergmann\CodeCoverage\Report\Xml;
class Directory extends Node
final class Directory extends Node
{
}

View File

@@ -18,7 +18,7 @@ use SebastianBergmann\CodeCoverage\RuntimeException;
use SebastianBergmann\CodeCoverage\Version;
use SebastianBergmann\Environment\Runtime;
class Facade
final class Facade
{
/**
* @var string
@@ -35,23 +35,17 @@ class Facade
*/
private $phpUnitVersion;
/**
* @param string $version
*/
public function __construct($version)
public function __construct(string $version)
{
$this->phpUnitVersion = $version;
}
/**
* @param CodeCoverage $coverage
* @param string $target
*
* @throws RuntimeException
*/
public function process(CodeCoverage $coverage, $target)
public function process(CodeCoverage $coverage, string $target): void
{
if (\substr($target, -1, 1) != DIRECTORY_SEPARATOR) {
if (\substr($target, -1, 1) !== DIRECTORY_SEPARATOR) {
$target .= DIRECTORY_SEPARATOR;
}
@@ -71,7 +65,7 @@ class Facade
$this->saveDocument($this->project->asDom(), 'index');
}
private function setBuildInformation()
private function setBuildInformation(): void
{
$buildNode = $this->project->getBuildInformation();
$buildNode->setRuntimeInformation(new Runtime());
@@ -80,9 +74,9 @@ class Facade
}
/**
* @param string $directory
* @throws RuntimeException
*/
protected function initTargetDirectory($directory)
private function initTargetDirectory(string $directory): void
{
if (\file_exists($directory)) {
if (!\is_dir($directory)) {
@@ -96,33 +90,38 @@ class Facade
"'$directory' exists but is not writable."
);
}
} elseif (!@\mkdir($directory, 0777, true)) {
} elseif (!$this->createDirectory($directory)) {
throw new RuntimeException(
"'$directory' could not be created."
);
}
}
private function processDirectory(DirectoryNode $directory, Node $context)
private function processDirectory(DirectoryNode $directory, Node $context): void
{
$dirname = $directory->getName();
if ($this->project->getProjectSourceDirectory() === $dirname) {
$dirname = '/';
}
$dirObject = $context->addDirectory($dirname);
$directoryName = $directory->getName();
$this->setTotals($directory, $dirObject->getTotals());
if ($this->project->getProjectSourceDirectory() === $directoryName) {
$directoryName = '/';
}
$directoryObject = $context->addDirectory($directoryName);
$this->setTotals($directory, $directoryObject->getTotals());
foreach ($directory->getDirectories() as $node) {
$this->processDirectory($node, $dirObject);
$this->processDirectory($node, $directoryObject);
}
foreach ($directory->getFiles() as $node) {
$this->processFile($node, $dirObject);
$this->processFile($node, $directoryObject);
}
}
private function processFile(FileNode $file, Directory $context)
/**
* @throws RuntimeException
*/
private function processFile(FileNode $file, Directory $context): void
{
$fileObject = $context->addFile(
$file->getName(),
@@ -135,6 +134,7 @@ class Facade
$file->getPath(),
\strlen($this->project->getProjectSourceDirectory())
);
$fileReport = new Report($path);
$this->setTotals($file, $fileReport->getTotals());
@@ -168,7 +168,7 @@ class Facade
$this->saveDocument($fileReport->asDom(), $file->getId());
}
private function processUnit($unit, Report $report)
private function processUnit(array $unit, Report $report): void
{
if (isset($unit['className'])) {
$unitObject = $report->getClassObject($unit['className']);
@@ -206,7 +206,7 @@ class Facade
}
}
private function processFunction($function, Report $report)
private function processFunction(array $function, Report $report): void
{
$functionObject = $report->getFunctionObject($function['functionName']);
@@ -216,12 +216,12 @@ class Facade
$functionObject->setTotals($function['executableLines'], $function['executedLines'], $function['coverage']);
}
private function processTests(array $tests)
private function processTests(array $tests): void
{
$testsObject = $this->project->getTests();
foreach ($tests as $test => $result) {
if ($test == 'UNCOVERED_FILES_FROM_WHITELIST') {
if ($test === 'UNCOVERED_FILES_FROM_WHITELIST') {
continue;
}
@@ -229,7 +229,7 @@ class Facade
}
}
private function setTotals(AbstractNode $node, Totals $totals)
private function setTotals(AbstractNode $node, Totals $totals): void
{
$loc = $node->getLinesOfCode();
@@ -262,15 +262,15 @@ class Facade
);
}
/**
* @return string
*/
protected function getTargetDirectory()
private function getTargetDirectory(): string
{
return $this->target;
}
protected function saveDocument(\DOMDocument $document, $name)
/**
* @throws RuntimeException
*/
private function saveDocument(\DOMDocument $document, string $name): void
{
$filename = \sprintf('%s/%s.xml', $this->getTargetDirectory(), $name);
@@ -280,4 +280,9 @@ class Facade
$document->save($filename);
}
private function createDirectory(string $directory): bool
{
return !(!\is_dir($directory) && !@\mkdir($directory, 0777, true) && !\is_dir($directory));
}
}

View File

@@ -28,30 +28,14 @@ class File
$this->contextNode = $context;
}
/**
* @return \DOMElement
*/
protected function getContextNode()
{
return $this->contextNode;
}
/**
* @return \DOMDocument
*/
protected function getDomDocument()
{
return $this->dom;
}
public function getTotals()
public function getTotals(): Totals
{
$totalsContainer = $this->contextNode->firstChild;
if (!$totalsContainer) {
$totalsContainer = $this->contextNode->appendChild(
$this->dom->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'totals'
)
);
@@ -60,17 +44,17 @@ class File
return new Totals($totalsContainer);
}
public function getLineCoverage($line)
public function getLineCoverage(string $line): Coverage
{
$coverage = $this->contextNode->getElementsByTagNameNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'coverage'
)->item(0);
if (!$coverage) {
$coverage = $this->contextNode->appendChild(
$this->dom->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'coverage'
)
);
@@ -78,11 +62,21 @@ class File
$lineNode = $coverage->appendChild(
$this->dom->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'line'
)
);
return new Coverage($lineNode, $line);
}
protected function getContextNode(): \DOMElement
{
return $this->contextNode;
}
protected function getDomDocument(): \DOMDocument
{
return $this->dom;
}
}

View File

@@ -10,31 +10,26 @@
namespace SebastianBergmann\CodeCoverage\Report\Xml;
class Method
final class Method
{
/**
* @var \DOMElement
*/
private $contextNode;
public function __construct(\DOMElement $context, $name)
public function __construct(\DOMElement $context, string $name)
{
$this->contextNode = $context;
$this->setName($name);
}
private function setName($name)
{
$this->contextNode->setAttribute('name', $name);
}
public function setSignature($signature)
public function setSignature(string $signature): void
{
$this->contextNode->setAttribute('signature', $signature);
}
public function setLines($start, $end = null)
public function setLines(string $start, ?string $end = null): void
{
$this->contextNode->setAttribute('start', $start);
@@ -43,15 +38,20 @@ class Method
}
}
public function setTotals($executable, $executed, $coverage)
public function setTotals(string $executable, string $executed, string $coverage): void
{
$this->contextNode->setAttribute('executable', $executable);
$this->contextNode->setAttribute('executed', $executed);
$this->contextNode->setAttribute('coverage', $coverage);
}
public function setCrap($crap)
public function setCrap(string $crap): void
{
$this->contextNode->setAttribute('crap', $crap);
}
private function setName(string $name): void
{
$this->contextNode->setAttribute('name', $name);
}
}

View File

@@ -10,7 +10,7 @@
namespace SebastianBergmann\CodeCoverage\Report\Xml;
class Node
abstract class Node
{
/**
* @var \DOMDocument
@@ -27,30 +27,19 @@ class Node
$this->setContextNode($context);
}
protected function setContextNode(\DOMElement $context)
{
$this->dom = $context->ownerDocument;
$this->contextNode = $context;
}
public function getDom()
public function getDom(): \DOMDocument
{
return $this->dom;
}
protected function getContextNode()
{
return $this->contextNode;
}
public function getTotals()
public function getTotals(): Totals
{
$totalsContainer = $this->getContextNode()->firstChild;
if (!$totalsContainer) {
$totalsContainer = $this->getContextNode()->appendChild(
$this->dom->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'totals'
)
);
@@ -59,10 +48,10 @@ class Node
return new Totals($totalsContainer);
}
public function addDirectory($name)
public function addDirectory(string $name): Directory
{
$dirNode = $this->getDom()->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'directory'
);
@@ -72,10 +61,10 @@ class Node
return new Directory($dirNode);
}
public function addFile($name, $href)
public function addFile(string $name, string $href): File
{
$fileNode = $this->getDom()->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'file'
);
@@ -85,4 +74,15 @@ class Node
return new File($fileNode);
}
protected function setContextNode(\DOMElement $context): void
{
$this->dom = $context->ownerDocument;
$this->contextNode = $context;
}
protected function getContextNode(): \DOMElement
{
return $this->contextNode;
}
}

View File

@@ -10,57 +10,30 @@
namespace SebastianBergmann\CodeCoverage\Report\Xml;
class Project extends Node
final class Project extends Node
{
/**
* @param string $directory
*/
public function __construct($directory)
public function __construct(string $directory)
{
$this->init();
$this->setProjectSourceDirectory($directory);
}
private function init()
{
$dom = new \DOMDocument();
$dom->loadXML('<?xml version="1.0" ?><phpunit xmlns="http://schema.phpunit.de/coverage/1.0"><build/><project/></phpunit>');
$this->setContextNode(
$dom->getElementsByTagNameNS(
'http://schema.phpunit.de/coverage/1.0',
'project'
)->item(0)
);
}
private function setProjectSourceDirectory($name)
{
$this->getContextNode()->setAttribute('source', $name);
}
/**
* @return string
*/
public function getProjectSourceDirectory()
public function getProjectSourceDirectory(): string
{
return $this->getContextNode()->getAttribute('source');
}
/**
* @return BuildInformation
*/
public function getBuildInformation()
public function getBuildInformation(): BuildInformation
{
$buildNode = $this->getDom()->getElementsByTagNameNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'build'
)->item(0);
if (!$buildNode) {
$buildNode = $this->getDom()->documentElement->appendChild(
$this->getDom()->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'build'
)
);
@@ -69,17 +42,17 @@ class Project extends Node
return new BuildInformation($buildNode);
}
public function getTests()
public function getTests(): Tests
{
$testsNode = $this->getContextNode()->getElementsByTagNameNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'tests'
)->item(0);
if (!$testsNode) {
$testsNode = $this->getContextNode()->appendChild(
$this->getDom()->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'tests'
)
);
@@ -88,8 +61,26 @@ class Project extends Node
return new Tests($testsNode);
}
public function asDom()
public function asDom(): \DOMDocument
{
return $this->getDom();
}
private function init(): void
{
$dom = new \DOMDocument;
$dom->loadXML('<?xml version="1.0" ?><phpunit xmlns="https://schema.phpunit.de/coverage/1.0"><build/><project/></phpunit>');
$this->setContextNode(
$dom->getElementsByTagNameNS(
'https://schema.phpunit.de/coverage/1.0',
'project'
)->item(0)
);
}
private function setProjectSourceDirectory(string $name): void
{
$this->getContextNode()->setAttribute('source', $name);
}
}

View File

@@ -10,38 +10,33 @@
namespace SebastianBergmann\CodeCoverage\Report\Xml;
class Report extends File
final class Report extends File
{
public function __construct($name)
public function __construct(string $name)
{
$dom = new \DOMDocument();
$dom->loadXML('<?xml version="1.0" ?><phpunit xmlns="http://schema.phpunit.de/coverage/1.0"><file /></phpunit>');
$dom->loadXML('<?xml version="1.0" ?><phpunit xmlns="https://schema.phpunit.de/coverage/1.0"><file /></phpunit>');
$contextNode = $dom->getElementsByTagNameNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'file'
)->item(0);
parent::__construct($contextNode);
$this->setName($name);
}
private function setName($name)
{
$this->getContextNode()->setAttribute('name', \basename($name));
$this->getContextNode()->setAttribute('path', \dirname($name));
}
public function asDom()
public function asDom(): \DOMDocument
{
return $this->getDomDocument();
}
public function getFunctionObject($name)
public function getFunctionObject($name): Method
{
$node = $this->getContextNode()->appendChild(
$this->getDomDocument()->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'function'
)
);
@@ -49,39 +44,27 @@ class Report extends File
return new Method($node, $name);
}
public function getClassObject($name)
public function getClassObject($name): Unit
{
return $this->getUnitObject('class', $name);
}
public function getTraitObject($name)
public function getTraitObject($name): Unit
{
return $this->getUnitObject('trait', $name);
}
private function getUnitObject($tagName, $name)
{
$node = $this->getContextNode()->appendChild(
$this->getDomDocument()->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
$tagName
)
);
return new Unit($node, $name);
}
public function getSource()
public function getSource(): Source
{
$source = $this->getContextNode()->getElementsByTagNameNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'source'
)->item(0);
if (!$source) {
$source = $this->getContextNode()->appendChild(
$this->getDomDocument()->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'source'
)
);
@@ -89,4 +72,22 @@ class Report extends File
return new Source($source);
}
private function setName($name): void
{
$this->getContextNode()->setAttribute('name', \basename($name));
$this->getContextNode()->setAttribute('path', \dirname($name));
}
private function getUnitObject($tagName, $name): Unit
{
$node = $this->getContextNode()->appendChild(
$this->getDomDocument()->createElementNS(
'https://schema.phpunit.de/coverage/1.0',
$tagName
)
);
return new Unit($node, $name);
}
}

View File

@@ -14,7 +14,7 @@ use TheSeer\Tokenizer\NamespaceUri;
use TheSeer\Tokenizer\Tokenizer;
use TheSeer\Tokenizer\XMLSerializer;
class Source
final class Source
{
/** @var \DOMElement */
private $context;
@@ -27,10 +27,7 @@ class Source
$this->context = $context;
}
/**
* @param string $source
*/
public function setSourceCode(string $source)
public function setSourceCode(string $source): void
{
$context = $this->context;

View File

@@ -10,18 +10,19 @@
namespace SebastianBergmann\CodeCoverage\Report\Xml;
class Tests
final class Tests
{
private $contextNode;
private $codeMap = [
0 => 'PASSED', // PHPUnit_Runner_BaseTestRunner::STATUS_PASSED
1 => 'SKIPPED', // PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED
2 => 'INCOMPLETE', // PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE
3 => 'FAILURE', // PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE
4 => 'ERROR', // PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
5 => 'RISKY', // PHPUnit_Runner_BaseTestRunner::STATUS_RISKY
6 => 'WARNING' // PHPUnit_Runner_BaseTestRunner::STATUS_WARNING
-1 => 'UNKNOWN', // PHPUnit_Runner_BaseTestRunner::STATUS_UNKNOWN
0 => 'PASSED', // PHPUnit_Runner_BaseTestRunner::STATUS_PASSED
1 => 'SKIPPED', // PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED
2 => 'INCOMPLETE', // PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE
3 => 'FAILURE', // PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE
4 => 'ERROR', // PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
5 => 'RISKY', // PHPUnit_Runner_BaseTestRunner::STATUS_RISKY
6 => 'WARNING' // PHPUnit_Runner_BaseTestRunner::STATUS_WARNING
];
public function __construct(\DOMElement $context)
@@ -29,11 +30,11 @@ class Tests
$this->contextNode = $context;
}
public function addTest($test, array $result)
public function addTest(string $test, array $result): void
{
$node = $this->contextNode->appendChild(
$this->contextNode->ownerDocument->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'test'
)
);

View File

@@ -12,7 +12,7 @@ namespace SebastianBergmann\CodeCoverage\Report\Xml;
use SebastianBergmann\CodeCoverage\Util;
class Totals
final class Totals
{
/**
* @var \DOMNode
@@ -50,27 +50,27 @@ class Totals
$dom = $container->ownerDocument;
$this->linesNode = $dom->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'lines'
);
$this->methodsNode = $dom->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'methods'
);
$this->functionsNode = $dom->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'functions'
);
$this->classesNode = $dom->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'classes'
);
$this->traitsNode = $dom->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'traits'
);
@@ -81,12 +81,12 @@ class Totals
$container->appendChild($this->traitsNode);
}
public function getContainer()
public function getContainer(): \DOMNode
{
return $this->container;
}
public function setNumLines($loc, $cloc, $ncloc, $executable, $executed)
public function setNumLines(int $loc, int $cloc, int $ncloc, int $executable, int $executed): void
{
$this->linesNode->setAttribute('total', $loc);
$this->linesNode->setAttribute('comments', $cloc);
@@ -95,47 +95,47 @@ class Totals
$this->linesNode->setAttribute('executed', $executed);
$this->linesNode->setAttribute(
'percent',
$executable === 0 ? 0 : \sprintf('%01.2F', Util::percent($executed, $executable, false))
$executable === 0 ? 0 : \sprintf('%01.2F', Util::percent($executed, $executable))
);
}
public function setNumClasses($count, $tested)
public function setNumClasses(int $count, int $tested): void
{
$this->classesNode->setAttribute('count', $count);
$this->classesNode->setAttribute('tested', $tested);
$this->classesNode->setAttribute(
'percent',
$count === 0 ? 0 : \sprintf('%01.2F', Util::percent($tested, $count, false))
$count === 0 ? 0 : \sprintf('%01.2F', Util::percent($tested, $count))
);
}
public function setNumTraits($count, $tested)
public function setNumTraits(int $count, int $tested): void
{
$this->traitsNode->setAttribute('count', $count);
$this->traitsNode->setAttribute('tested', $tested);
$this->traitsNode->setAttribute(
'percent',
$count === 0 ? 0 : \sprintf('%01.2F', Util::percent($tested, $count, false))
$count === 0 ? 0 : \sprintf('%01.2F', Util::percent($tested, $count))
);
}
public function setNumMethods($count, $tested)
public function setNumMethods(int $count, int $tested): void
{
$this->methodsNode->setAttribute('count', $count);
$this->methodsNode->setAttribute('tested', $tested);
$this->methodsNode->setAttribute(
'percent',
$count === 0 ? 0 : \sprintf('%01.2F', Util::percent($tested, $count, false))
$count === 0 ? 0 : \sprintf('%01.2F', Util::percent($tested, $count))
);
}
public function setNumFunctions($count, $tested)
public function setNumFunctions(int $count, int $tested): void
{
$this->functionsNode->setAttribute('count', $count);
$this->functionsNode->setAttribute('tested', $tested);
$this->functionsNode->setAttribute(
'percent',
$count === 0 ? 0 : \sprintf('%01.2F', Util::percent($tested, $count, false))
$count === 0 ? 0 : \sprintf('%01.2F', Util::percent($tested, $count))
);
}
}

View File

@@ -10,48 +10,43 @@
namespace SebastianBergmann\CodeCoverage\Report\Xml;
class Unit
final class Unit
{
/**
* @var \DOMElement
*/
private $contextNode;
public function __construct(\DOMElement $context, $name)
public function __construct(\DOMElement $context, string $name)
{
$this->contextNode = $context;
$this->setName($name);
}
private function setName($name)
{
$this->contextNode->setAttribute('name', $name);
}
public function setLines($start, $executable, $executed)
public function setLines(int $start, int $executable, int $executed): void
{
$this->contextNode->setAttribute('start', $start);
$this->contextNode->setAttribute('executable', $executable);
$this->contextNode->setAttribute('executed', $executed);
}
public function setCrap($crap)
public function setCrap(float $crap): void
{
$this->contextNode->setAttribute('crap', $crap);
}
public function setPackage($full, $package, $sub, $category)
public function setPackage(string $full, string $package, string $sub, string $category): void
{
$node = $this->contextNode->getElementsByTagNameNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'package'
)->item(0);
if (!$node) {
$node = $this->contextNode->appendChild(
$this->contextNode->ownerDocument->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'package'
)
);
@@ -63,17 +58,17 @@ class Unit
$node->setAttribute('category', $category);
}
public function setNamespace($namespace)
public function setNamespace(string $namespace): void
{
$node = $this->contextNode->getElementsByTagNameNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'namespace'
)->item(0);
if (!$node) {
$node = $this->contextNode->appendChild(
$this->contextNode->ownerDocument->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'namespace'
)
);
@@ -82,15 +77,20 @@ class Unit
$node->setAttribute('name', $namespace);
}
public function addMethod($name)
public function addMethod(string $name): Method
{
$node = $this->contextNode->appendChild(
$this->contextNode->ownerDocument->createElementNS(
'http://schema.phpunit.de/coverage/1.0',
'https://schema.phpunit.de/coverage/1.0',
'method'
)
);
return new Method($node, $name);
}
private function setName(string $name): void
{
$this->contextNode->setAttribute('name', $name);
}
}