Skip to content

Commit 3cea876

Browse files
localheinzdblandin
authored andcommitted
Fix: Compose, do not extend JsonFile
1 parent 8d60fcc commit 3cea876

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/TestReporter/CoverageCollector.php

+2-9
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,8 @@ public function getCloverPaths()
6464
*/
6565
public function collectAsJson()
6666
{
67-
$cloverJsonFile = $this->api->collectCloverXml()->getJsonFile();
67+
$jsonFile = $this->api->collectCloverXml()->getJsonFile();
6868

69-
$jsonFile = new JsonFile();
70-
$jsonFile->setRunAt($cloverJsonFile->getRunAt());
71-
72-
foreach ($cloverJsonFile->getSourceFiles() as $sourceFile) {
73-
$jsonFile->addSourceFile($sourceFile);
74-
}
75-
76-
return $jsonFile;
69+
return new JsonFile($jsonFile);
7770
}
7871
}

src/TestReporter/Entity/JsonFile.php

+21-7
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33

44
use CodeClimate\PhpTestReporter\Constants\Version;
55
use CodeClimate\PhpTestReporter\System\Git\GitCommand;
6-
use Satooshi\Bundle\CoverallsV1Bundle\Entity\JsonFile as SatooshiJsonFile;
7-
use Satooshi\Bundle\CoverallsV1Bundle\Entity\SourceFile;
6+
use Satooshi\Bundle\CoverallsV1Bundle;
87

9-
class JsonFile extends SatooshiJsonFile
8+
class JsonFile
109
{
10+
/**
11+
* @var CoverallsV1Bundle\Entity\JsonFile
12+
*/
13+
private $jsonFile;
14+
15+
public function __construct(CoverallsV1Bundle\Entity\JsonFile $jsonFile)
16+
{
17+
$this->jsonFile = $jsonFile;
18+
}
19+
1120
public function toArray()
1221
{
1322
return array(
@@ -23,7 +32,7 @@ public function toArray()
2332

2433
public function getRunAt()
2534
{
26-
return strtotime(parent::getRunAt());
35+
return strtotime($this->jsonFile->getRunAt());
2736
}
2837

2938
public function getRepoToken()
@@ -69,7 +78,7 @@ protected function collectSourceFiles()
6978
{
7079
$data = array();
7180

72-
foreach ($this->getSourceFiles() as $sourceFile) {
81+
foreach ($this->jsonFile->getSourceFiles() as $sourceFile) {
7382
$data[] = array(
7483
"name" => $sourceFile->getName(),
7584
"coverage" => json_encode($sourceFile->getCoverage()),
@@ -81,14 +90,19 @@ protected function collectSourceFiles()
8190
}
8291

8392
/**
84-
* @param SourceFile $sourceFile
93+
* @param CoverallsV1Bundle\Entity\SourceFile $sourceFile
8594
* @return string
8695
*/
87-
protected function calculateBlobId(SourceFile $sourceFile)
96+
protected function calculateBlobId(CoverallsV1Bundle\Entity\SourceFile $sourceFile)
8897
{
8998
$content = file_get_contents($sourceFile->getPath());
9099
$header = "blob " . strlen($content) . "\0";
91100

92101
return sha1($header . $content);
93102
}
103+
104+
public function __toString()
105+
{
106+
return json_encode($this->toArray());
107+
}
94108
}

0 commit comments

Comments
 (0)