php-ranker
, (*1)
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., (*2)
What metric do php-ranker use?
There are three dimensions php-ranker taken., (*3)
- 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., (*4)
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:, (*5)
| 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., (*6)
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), (*7)
| 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., (*8)
How php-ranker get total GPA
All GPAs are based on file size.
For example, php-ranker finds three files, (*9)
| 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., (*10)
And we can find a formula -> (4 x 100 + 4 x 200 + 0 x 1000) / (200 + 100 + 1000) = 0.93, (*11)
0.93 is the total GPA score for these files., (*12)
How to use php-ranker
Install
Composer
composer require michael34435/php-ranker
Phar
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
./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., (*13)