This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComposerExtension.php
81 lines (71 loc) · 2.17 KB
/
ComposerExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace ComposerExtension;
use Hal\Application\Config\Configuration;
use Hal\Application\Extension\Extension;
use Hal\Application\Extension\Reporter;
use Hal\Application\Extension\ReporterHtmlSummary;
use Hal\Component\Bounds\Bounds;
use Hal\Component\File\Finder;
use Hal\Component\Result\ResultCollection;
require_once __DIR__.'/HtmlRenderer.php';
require_once __DIR__.'/Packagist.php';
class ComposerExtension implements Extension {
/**
* @var \StdClass
*/
private $datas;
/**
* @inheritdoc
*/
public function receive(Configuration $configuration, ResultCollection $collection, ResultCollection $aggregatedResults, Bounds $bounds)
{
$this->datas = new \StdClass;
// search compose.json files
$finder = new Finder('json', $configuration->getPath()->getExcludedDirs());
$files = $finder->find($configuration->getPath()->getBasePath());
foreach($files as $filename) {
if(!preg_match('/composer\.json|composer-dist\.json/', $filename)) {
continue;
}
$this->datas = (object) json_decode(file_get_contents($filename));
break;
}
// search infos about package on packagist
$packagist = new Packagist();
$reqs = $this->datas->require;
$this->datas->require = array();
foreach($reqs as $requirement => $version) {
$package = $packagist->get($requirement);
$this->datas->require[$requirement] = (object) array(
'name' => $requirement,
'required' => $version,
'latest' => $package->latest,
'license' => $package->license,
'homepage' => $package->homepage,
'zip' => $package->zip,
);
}
}
/**
* @inheritdoc
*/
public function getName()
{
return 'composer';
}
/**
* @inheritdoc
*/
public function getReporterHtmlSummary()
{
return new HtmlRenderer($this->datas);
}
/**
* @inheritdoc
*/
public function getReporterCliSummary()
{
return null;
}
}
return new ComposerExtension();