Permalink
Browse files

added PHP 7.1 typehints

  • Loading branch information...
dg committed Mar 20, 2018
1 parent dda08f9 commit d6d36b900e41414c3bae0ac2c19f3975fc3db786
Showing with 262 additions and 464 deletions.
  1. +6 βˆ’14 src/CodeCoverage/Collector.php
  2. +6 βˆ’12 src/CodeCoverage/Generators/AbstractGenerator.php
  3. +6 βˆ’12 src/CodeCoverage/Generators/CloverXMLGenerator.php
  4. +4 βˆ’5 src/CodeCoverage/Generators/HtmlGenerator.php
  5. +2 βˆ’5 src/CodeCoverage/PhpParser.php
  6. +30 βˆ’62 src/Framework/Assert.php
  7. +2 βˆ’2 src/Framework/AssertException.php
  8. +4 βˆ’9 src/Framework/DataProvider.php
  9. +6 βˆ’14 src/Framework/DomQuery.php
  10. +9 βˆ’19 src/Framework/Dumper.php
  11. +14 βˆ’24 src/Framework/Environment.php
  12. +14 βˆ’14 src/Framework/FileMock.php
  13. +25 βˆ’24 src/Framework/FileMutator.php
  14. +4 βˆ’8 src/Framework/Helpers.php
  15. +6 βˆ’8 src/Framework/TestCase.php
  16. +10 βˆ’17 src/Runner/CliTester.php
  17. +5 βˆ’5 src/Runner/CommandLine.php
  18. +7 βˆ’22 src/Runner/Job.php
  19. +5 βˆ’5 src/Runner/Output/ConsolePrinter.php
  20. +5 βˆ’5 src/Runner/Output/JUnitPrinter.php
  21. +5 βˆ’5 src/Runner/Output/Logger.php
  22. +5 βˆ’5 src/Runner/Output/TapPrinter.php
  23. +4 βˆ’4 src/Runner/OutputHandler.php
  24. +9 βˆ’33 src/Runner/PhpInterpreter.php
  25. +15 βˆ’53 src/Runner/Runner.php
  26. +9 βˆ’28 src/Runner/Test.php
  27. +21 βˆ’24 src/Runner/TestHandler.php
  28. +1 βˆ’1 tests/Framework/Assert.match.phpt
  29. +2 βˆ’2 tests/Framework/Dumper.color.phpt
  30. +0 βˆ’1 tests/Framework/Helpers.escapeArg.phpt
  31. +4 βˆ’4 tests/Runner/Runner.annotations.phpt
  32. +4 βˆ’4 tests/Runner/Runner.edge.phpt
  33. +4 βˆ’4 tests/Runner/Runner.misc.phpt
  34. +4 βˆ’4 tests/Runner/Runner.multiple-fails.phpt
  35. +4 βˆ’4 tests/Runner/Runner.stop-on-fail.phpt
  36. +1 βˆ’2 tests/bootstrap.php
@@ -20,22 +20,17 @@ class Collector
private static $collector;
/**
* @return bool
*/
public static function isStarted()
public static function isStarted(): bool
{
return self::$file !== null;
}
/**
* Starts gathering the information for code coverage.
* @param string
* @return void
* @throws \LogicException
*/
public static function start($file)
public static function start(string $file): void
{
if (self::isStarted()) {
throw new \LogicException('Code coverage collector has been already started.');
@@ -63,7 +58,7 @@ public static function start($file)
/**
* Flushes all gathered information. Effective only with PHPDBG collector.
*/
public static function flush()
public static function flush(): void
{
if (self::isStarted() && self::$collector === 'collectPhpDbg') {
self::save();
@@ -73,10 +68,9 @@ public static function flush()
/**
* Saves information about code coverage. Can be called repeatedly to free memory.
* @return void
* @throws \LogicException
*/
public static function save()
public static function save(): void
{
if (!self::isStarted()) {
throw new \LogicException('Code coverage collector has not been started.');
@@ -99,9 +93,8 @@ public static function save()
/**
* Collects information about code coverage.
* @return array
*/
private static function collectXdebug()
private static function collectXdebug(): array
{
$positive = $negative = [];
@@ -125,9 +118,8 @@ private static function collectXdebug()
/**
* Collects information about code coverage.
* @return array
*/
private static function collectPhpDbg()
private static function collectPhpDbg(): array
{
$positive = phpdbg_end_oplog();
$negative = phpdbg_get_executable();
@@ -38,7 +38,7 @@ abstract class AbstractGenerator
* @param string path to coverage.dat file
* @param string path to covered source file or directory
*/
public function __construct($file, $source = null)
public function __construct(string $file, string $source = null)
{
if (!is_file($file)) {
throw new \Exception("File '$file' is missing.");
@@ -69,14 +69,14 @@ public function __construct($file, $source = null)
}
public function render($file = null)
public function render(string $file = null): void
{
$handle = $file ? @fopen($file, 'w') : STDOUT; // @ is escalated to exception
if (!$handle) {
throw new \Exception("Unable to write to file '$file'.");
}
ob_start(function ($buffer) use ($handle) { fwrite($handle, $buffer); }, 4096);
ob_start(function (string $buffer) use ($handle) { fwrite($handle, $buffer); }, 4096);
try {
$this->renderSelf();
} catch (\Exception $e) {
@@ -93,25 +93,19 @@ public function render($file = null)
}
/**
* @return float
*/
public function getCoveredPercent()
public function getCoveredPercent(): float
{
return $this->totalSum ? $this->coveredSum * 100 / $this->totalSum : 0;
}
/**
* @return \Iterator
*/
protected function getSourceIterator()
protected function getSourceIterator(): \Iterator
{
$iterator = is_dir($this->source)
? new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->source))
: new \ArrayIterator([new \SplFileInfo($this->source)]);
return new \CallbackFilterIterator($iterator, function (\SplFileInfo $file) {
return new \CallbackFilterIterator($iterator, function (\SplFileInfo $file): bool {
return $file->getBasename()[0] !== '.' // . or .. or .gitignore
&& in_array($file->getExtension(), $this->acceptFiles, true);
});
@@ -31,7 +31,7 @@ class CloverXMLGenerator extends AbstractGenerator
];
public function __construct($file, $source = null)
public function __construct(string $file, string $source = null)
{
if (!extension_loaded('dom')) {
throw new \LogicException('CloverXML generator requires DOM extension to be loaded.');
@@ -40,7 +40,7 @@ public function __construct($file, $source = null)
}
protected function renderSelf()
protected function renderSelf(): void
{
$time = (string) time();
$parser = new PhpParser;
@@ -147,10 +147,7 @@ protected function renderSelf()
}
/**
* @return \stdClass
*/
private function calculateClassMetrics(\stdClass $info, array $coverageData = null)
private function calculateClassMetrics(\stdClass $info, array $coverageData = null): \stdClass
{
$stats = (object) [
'methodCount' => count($info->methods),
@@ -181,10 +178,7 @@ private function calculateClassMetrics(\stdClass $info, array $coverageData = nu
}
/**
* @return array
*/
private static function analyzeMethod(\stdClass $info, array $coverageData = null)
private static function analyzeMethod(\stdClass $info, array $coverageData = null): array
{
$count = 0;
$coveredCount = 0;
@@ -206,15 +200,15 @@ private static function analyzeMethod(\stdClass $info, array $coverageData = nul
}
private static function appendMetrics(\stdClass $summary, \stdClass $add)
private static function appendMetrics(\stdClass $summary, \stdClass $add): void
{
foreach ($add as $name => $value) {
$summary->{$name} += $value;
}
}
private static function setMetricAttributes(DOMElement $element, \stdClass $metrics)
private static function setMetricAttributes(DOMElement $element, \stdClass $metrics): void
{
foreach ($metrics as $name => $value) {
$element->setAttribute(self::$metricAttributesMap[$name], (string) $value);
@@ -30,16 +30,15 @@ class HtmlGenerator extends AbstractGenerator
/**
* @param string path to coverage.dat file
* @param string path to source file/directory
* @param string
*/
public function __construct($file, $source = null, $title = null)
public function __construct(string $file, string $source = null, string $title = null)
{
parent::__construct($file, $source);
$this->title = $title;
}
protected function renderSelf()
protected function renderSelf(): void
{
$this->setupHighlight();
$this->parse();
@@ -53,7 +52,7 @@ protected function renderSelf()
}
private function setupHighlight()
private function setupHighlight(): void
{
ini_set('highlight.comment', 'hc');
ini_set('highlight.default', 'hd');
@@ -63,7 +62,7 @@ private function setupHighlight()
}
private function parse()
private function parse(): void
{
if (count($this->files) > 0) {
return;
@@ -19,9 +19,6 @@
class PhpParser
{
/**
* @param string PHP code to analyze
* @return \stdClass
*
* Returned structure is:
* stdClass {
* linesOfCode: int,
@@ -52,7 +49,7 @@ class PhpParser
* visibility: public|protected|private
* }
*/
public function parse($code)
public function parse(string $code): \stdClass
{
$tokens = @token_get_all($code); // @ - source code can be written in newer PHP
@@ -167,7 +164,7 @@ public function parse($code)
}
private static function fetch(&$tokens, $take)
private static function fetch(array &$tokens, $take): ?string
{
$res = null;
while ($token = current($tokens)) {
Oops, something went wrong.

0 comments on commit d6d36b9

Please sign in to comment.