Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit 5693c0a

Browse files
committed
added a way to install extension with composer and as phar archive
1 parent b41482e commit 5693c0a

File tree

7 files changed

+132
-20
lines changed

7 files changed

+132
-20
lines changed

CliSummaryReport.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace Extension\Symfony2;
2+
namespace Extension\Symfony;
33

44
use Hal\Application\Extension\Reporter\Reporter;
55

HtmlSummaryReport.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace Extension\Symfony2;
2+
namespace Extension\Symfony;
33

44
use Hal\Application\Extension\Reporter\ReporterHtmlSummary;
55

@@ -21,18 +21,18 @@ public function __construct(\StdClass $datas)
2121

2222
public function renderJs()
2323
{
24-
return "document.getElementById('link-symfony2').onclick = function() { displayTab(this, 'symfony2')};";
24+
return "document.getElementById('link-symfony').onclick = function() { displayTab(this, 'symfony')};";
2525
}
2626

2727
public function renderHtml()
2828
{
2929
$html = <<<EOT
30-
<div class="tab" id="symfony2">
30+
<div class="tab" id="symfony">
3131
3232
<div class="row">
3333
<h3>Symfony</h3>
3434
<p>
35-
Version: {$this->datas->symfony2->version}
35+
Version: {$this->datas->symfony->version}
3636
</p>
3737
</div>
3838
@@ -157,7 +157,7 @@ public function renderHtml()
157157
public function getMenus()
158158
{
159159
return array(
160-
'symfony2' => 'Symfony2'
160+
'symfony' => 'Symfony'
161161
);
162162
}
163163
}

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
REPLACE=`semver tag`
2+
3+
# Build phar
4+
build: test
5+
@echo Copying sources
6+
@mkdir -p /tmp/phpmetrics-build
7+
@cp * -R /tmp/phpmetrics-build
8+
9+
@echo Building phar
10+
@cd /tmp/phpmetrics-build && php build.php
11+
@cp /tmp/phpmetrics-build/symfony-extension.phar symfony-extension.phar
12+
@rm -Rf /tmp/phpmetrics-build
13+
14+
# Run unit tests
15+
test:
16+
17+
18+
# Publish new release. Usage:
19+
# make tag VERSION=(major|minor|patch)
20+
# You need to install https://github.com/flazz/semver/ before
21+
tag:
22+
@semver inc $(VERSION)
23+
@echo "New release: `semver tag`"
24+
25+
26+
# Tag git with last release
27+
release: build
28+
git add .semver symfony-extension.phar
29+
git commit -m "releasing `semver tag`"
30+
git tag `semver tag`
31+
git push -u origin master
32+
git push origin `semver tag`

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
# PhpMetricsSymfony2Extension
1+
# PhpMetricsSymfonyExtension
22

3-
This plugin add Symfony2 support directly in your [PhpMetrics](https://github.com/phpmetrics/phpmetrics) reports.
3+
This plugin add Symfony support directly in your [PhpMetrics](https://github.com/phpmetrics/phpmetrics) reports.
44

5-
![Screenshot of PhpMetricsSymfony2Extension](https://cloud.githubusercontent.com/assets/1076296/13907012/9eebfd58-eee4-11e5-8fe0-6c3b5f6c81a1.png "Screenshot of PhpMetricsSymfony2Extension")
5+
![Screenshot of PhpMetricsSymfonyExtension](https://cloud.githubusercontent.com/assets/1076296/13907012/9eebfd58-eee4-11e5-8fe0-6c3b5f6c81a1.png "Screenshot of PhpMetricsSymfonyExtension")
66

77
## Installation
88

9-
Clone this repository anywhere
9+
**As phar archive**:
1010

11-
git clone https://github.com/phpmetrics/PhpMetricsSymfony2Extension.git <my-folder>
12-
13-
Then run PhpMetrics (>1.10) with the `--plugins` option:
11+
wget https://raw.githubusercontent.com/phpmetrics/SymfonyExtension/master/symfony-extension.phar
12+
phpmetrics --plugins=symfony-extension.phar --report-html=report.html <my-folder>
13+
14+
or **with Composer**:
15+
16+
composer require phpmetrics/phpmetrics phpmetrics/symfony-extension
17+
./vendor/bin/phpmetrics --plugins=./vendor/phpmetrics/symfony-extension/SymfonyExtension.php --report-html=report.html <my-folder>
1418

15-
phpmetrics --plugins="/<my-folder>/Symfony2Extension.php"
1619

1720
## License
1821

Symfony2Extension.php renamed to SymfonyExtension.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace Extension\Symfony2;
2+
namespace Extension\Symfony;
33

44
use Hal\Application\Config\Configuration;
55
use Hal\Component\Bounds\Bounds;
@@ -9,7 +9,7 @@
99
require_once __DIR__ . '/CliSummaryReport.php';
1010
require_once __DIR__ . '/HtmlSummaryReport.php';
1111

12-
class Symfony2Extension implements \Hal\Application\Extension\Extension {
12+
class SymfonyExtension implements \Hal\Application\Extension\Extension {
1313

1414
/**
1515
* @var array
@@ -27,7 +27,7 @@ public function receive(Configuration $config, ResultCollection $collection, Res
2727
{
2828

2929
$this->datas = (object) array(
30-
'symfony2' => (object) array(
30+
'symfony' => (object) array(
3131
'version' => '?'
3232
)
3333
,'controllers' => (object) array(
@@ -135,15 +135,15 @@ public function receive(Configuration $config, ResultCollection $collection, Res
135135
}
136136
}
137137

138-
// search Symfony2 version
138+
// search Symfony version
139139
$finder = new Finder('cache', $config->getPath()->getExcludedDirs());
140140
$files = $finder->find($config->getPath()->getBasePath());
141141
foreach($files as $filename) {
142142
if(preg_match('/bootstrap\.php\.cache/', $filename)) {
143143
$content = file_get_contents($filename);
144144
if(preg_match("/const VERSION ='(.*?)';/", $content, $matches)) {
145145
list(, $sfVersion) = $matches;
146-
$this->datas->symfony2->version = $sfVersion;
146+
$this->datas->symfony->version = $sfVersion;
147147
}
148148
break;
149149
}
@@ -186,4 +186,4 @@ public function getReporterCliSummary()
186186
}
187187

188188

189-
return new Symfony2Extension();
189+
return new SymfonyExtension();

build.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
chdir(__DIR__);
3+
4+
$filename = 'symfony-extension.phar';
5+
if (file_exists($filename)) {
6+
unlink($filename);
7+
}
8+
9+
$phar = new \Phar($filename, 0, 'symfony-extension.phar');
10+
$phar->setSignatureAlgorithm(\Phar::SHA1);
11+
$phar->startBuffering();
12+
13+
14+
$files = array_merge(rglob('*.php'));
15+
$exclude = '!(.git)|(.svn)|(bin)|(tests)|(Tests)|(phpmetrics)!';
16+
foreach($files as $file) {
17+
if(preg_match($exclude, $file)) continue;
18+
$path = str_replace(__DIR__.'/', '', $file);
19+
$phar->addFromString($path, file_get_contents($file));
20+
}
21+
22+
$phar->setStub(<<<STUB
23+
<?php
24+
25+
/*
26+
* This file is part of the PhpMetrics
27+
*
28+
* (c) Jean-François Lépine
29+
*
30+
* This source file is subject to the MIT license that is bundled
31+
* with this source code in the file LICENSE.
32+
*/
33+
34+
Phar::mapPhar('symfony-extension.phar');
35+
36+
return require_once 'phar://symfony-extension.phar/SymfonyExtension.php';
37+
__HALT_COMPILER();
38+
STUB
39+
);
40+
$phar->stopBuffering();
41+
42+
function rglob($pattern='*', $flags = 0, $path='')
43+
{
44+
$paths=glob($path.'*', GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT);
45+
$files=glob($path.$pattern, $flags);
46+
foreach ($paths as $path) { $files=array_merge($files,rglob($pattern, $flags, $path)); }
47+
return $files;
48+
}

composer.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "phpmetrics/symfony-extension",
3+
"description": "Integrates Symfony with PhpMetrics",
4+
"license": "MIT",
5+
"keywords": [
6+
"quality",
7+
"analysis",
8+
"testing",
9+
"qa",
10+
"symfony"
11+
],
12+
"authors": [
13+
{
14+
"name": "Jean-François Lépine",
15+
"email": "[email protected]",
16+
"homepage": "http://www.lepine.pro",
17+
"role": "Copyright Holder"
18+
}
19+
],
20+
"homepage": "http://www.phpmetrics.org",
21+
"support": {
22+
"issues": "https://github.com/PhpMetrics/SymfonyExtension/issues"
23+
},
24+
"require": {
25+
},
26+
"require-dev": {
27+
"phpunit/phpunit": "~4.1"
28+
}
29+
}

0 commit comments

Comments
 (0)