https://github.com/michael34435/php-ranker
Grab GPA from your project with phpcs/phpmd/phpcpd violation report 👏
https://github.com/michael34435/php-ranker
checkstyle code-quality duplication grades pmd score violation-report
Last synced: about 1 year ago
JSON representation
Grab GPA from your project with phpcs/phpmd/phpcpd violation report 👏
- Host: GitHub
- URL: https://github.com/michael34435/php-ranker
- Owner: michael34435
- License: mit
- Created: 2016-12-16T13:36:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-06T09:18:57.000Z (almost 9 years ago)
- Last Synced: 2025-03-29T15:21:05.711Z (about 1 year ago)
- Topics: checkstyle, code-quality, duplication, grades, pmd, score, violation-report
- Language: PHP
- Homepage:
- Size: 1.31 MB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# php-ranker
[](https://travis-ci.org/michael34435/php-ranker)
[](https://codeclimate.com/github/michael34435/php-ranker)
## What's php-ranker?
`php-ranker` is a command line based parser to parse `xml` format report file generated by `phpmd`, `phpcs` and `phpcpd`.
All scores calculated by `php-ranker` are based on `codeclimate` except duplication report from `phpcpd`, because `codeclimate` use their own analysis tool(`flay`) to identify the code block is identical or similar but `phpcpd` cannot do it.
## What metric do php-ranker use?
There are three dimensions `php-ranker` taken.
* Checkstyle
* All the things include `PSR-2` standard and more
* PMD
* Checkstyle, complexity and code size
* Dry
* Duplication code detected from `phpcpd` instead of `flay`
## How grades are calculated?
### What's GPA(Grade Point Average)?
All grades are following GPA(Grade Point Average) a concept to determine you is good or bad in average in U.S school, most of it are 4-point-rule.
### How to calculate it?
In general, GPA is **four-point**, it means the greatest student gets 4-point while the worst gets 0-point in this subject.
And we'll end up getting an average score from a person.
Like this chart:
|Grade|Point|
|---|---|
|A|4.0|
|B|3.0|
|C|2.0|
|D|1.0|
|F|0.0||
For example, there is a student who gets two A's(represents 4-point) and one B(represents 3-point) and we will get a formula -> *(2 x 4 + 3) / (2 + 1) = 3.67*
`3.67` is the final score for this student.
### How php-ranker get file score
You have to add a config file named `.php-ranker`(see `.php-ranker.example`) in your project and composer require `php-ranker`.
Then `php-ranker` will read your config file and glob them to compare violation report from `phpcs`, `phpmd` or `phpcpd`.
Finally, `php-ranker` gives each file a point below.(all rules are following `codeclimate`)
|Points|Rank|
|---|---|
|0-2M|A|
|>2M-4M|B|
|>4M-8M|C|
|>8M-16M|D|
|>16M|F||
So your file will get a total point and `php-ranker` converts it to alphabetic rank finally.
### How php-ranker get total GPA
All GPAs are based on file size.
For example, `php-ranker` finds three files
|Filename|Rank|Lines|
|---|---|---|
|Foo.php|A|100|
|FooBar.php|A|200|
|Bar.php|F|1000||
`Foo.php` A rank represent 4 point
`FooBar.php` A rank represent 4 point, too
But `Bar.php` is too bad to get score and get 0 point.
And we can find a formula -> *(4 x 100 + 4 x 200 + 0 x 1000) / (200 + 100 + 1000) = 0.93*
`0.93` is the total GPA score for these files.
## How to use php-ranker
### Install
#### Composer
```sh
composer require michael34435/php-ranker
```
#### Phar
```sh
curl -LOk https://github.com/michael34435/php-ranker/raw/master/build/php-ranker
chmod +x php-ranker
mv php-ranker /usr/bin/php-ranker
```
### Usage
```sh
./vendor/bin/php-ranker
```
* `--pmd-report` - `phpmd` violation report path(xml)
* `--dry-report` - `phpcpd` violation report path(xml)
* `--checkstyle-report` - `phpcs` violation report(xml)
* `--export-dir` - The path you want to store for the GPA report html
### Notice
Version `0.01` and `0.02` only support jenkins report, i would like to recommend you to upgrade to `1.0.0` or `dev-master` ASAP.