Skip to content

Commit 97e3b9a

Browse files
authored
Merge pull request #7 from cobenash/master
Upgrade corresponding library to make sure it is compatible with php 8.
2 parents 0c7c029 + 8a60635 commit 97e3b9a

File tree

4 files changed

+66
-51
lines changed

4 files changed

+66
-51
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ composer.phar
22
/vendor/
33

44
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
5-
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6-
# composer.lock
5+
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file

build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
cp vendor/drupal/coder/coder_sniffer/Drupal/ vendor/squizlabs/php_codesniffer/src/Standards/ -r
4-
cp vendor/drupal/coder/coder_sniffer/DrupalPractice/ vendor/squizlabs/php_codesniffer/src/Standards/ -r
3+
cp -R vendor/drupal/coder/coder_sniffer/Drupal vendor/squizlabs/php_codesniffer/src/Standards
4+
cp -R vendor/drupal/coder/coder_sniffer/DrupalPractice vendor/squizlabs/php_codesniffer/src/Standards
55
rm phpdebt.phar
6-
./vendor/bin/phar-composer build .
6+
./vendor/bin/phar-composer build .

composer.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,15 @@
1212
"repositories": [
1313
{
1414
"type": "vcs",
15-
"url": "https://github.com/smmccabe/phpmd.git"
16-
},
17-
{
18-
"type": "vcs",
19-
"url": "https://github.com/smmccabe/PHP_CodeSniffer.git"
15+
"url": "https://github.com/cobenash/PHP_CodeSniffer.git"
2016
}
2117
],
2218
"require": {
2319
"squizlabs/php_codesniffer": "dev-api-friendly as 3.x-dev",
24-
"drupal/coder": "^8.3",
25-
"phpmd/phpmd": "dev-api-friendly",
26-
"phploc/phploc": "^6.0"
20+
"drupal/coder": "8.3.13",
21+
"phpmd/phpmd": "^2.13",
22+
"phploc/phploc": "^7.0",
23+
"symfony/finder": "^6.2"
2724
},
2825
"require-dev": {
2926
"clue/phar-composer": "^1.1"

src/index.php

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
11
<?php
22

3+
/**
4+
* @file
5+
* PHP Technical Debt Calculator.
6+
*/
7+
38
require __DIR__ . '/../vendor/autoload.php';
49
require __DIR__ . '/../vendor/squizlabs/php_codesniffer/autoload.php';
510

611
use PHPMD\PHPMD;
12+
use PHPMD\Report;
713
use PHPMD\RuleSetFactory;
814

9-
use SebastianBergmann\FinderFacade\FinderFacade;
1015
use SebastianBergmann\PHPLOC\Analyser;
1116

1217
use PHP_CodeSniffer\Runner;
1318
use PHP_CodeSniffer\Config;
1419

20+
use Symfony\Component\Finder\Finder;
21+
1522
$code_faults = 0;
1623
$standards_faults = 0;
1724
$path = $argv[1];
1825

19-
function phpMD($path, $type) {
20-
$ruleSetFactory = new RuleSetFactory();
21-
$phpmd = new PHPMD();
22-
23-
$report = $phpmd->runReport(
26+
/**
27+
* Mess Detector function.
28+
*/
29+
function php_md($path, $type) {
30+
$ruleSetFactory = new RuleSetFactory();
31+
$phpmd = new PHPMD();
32+
$report = new Report();
33+
$phpmd->processFiles(
2434
$path,
2535
$type,
26-
$ruleSetFactory
36+
$render = [],
37+
$ruleSetFactory,
38+
$report,
2739
);
2840

29-
$faults = count($report->getRuleViolations());
41+
$faults = count($report->getRuleViolations());
3042

31-
print "phpmd " . $type . ": " . $faults . "\n";
43+
print "phpmd " . $type . ": " . $faults . "\n";
3244

33-
return count($report->getRuleViolations());
45+
return count($report->getRuleViolations());
3446
}
3547

36-
$code_faults += phpMD($path, 'cleancode');
37-
$code_faults += phpMD($path, 'codesize');
38-
$code_faults += phpMD($path, 'design');
39-
$code_faults += phpMD($path, 'naming');
40-
$code_faults += phpMD($path, 'unusedcode');
48+
$code_faults += php_md($path, 'cleancode');
49+
$code_faults += php_md($path, 'codesize');
50+
$code_faults += php_md($path, 'design');
51+
$code_faults += php_md($path, 'naming');
52+
$code_faults += php_md($path, 'unusedcode');
4153

4254

4355
$runner = new Runner();
@@ -46,16 +58,16 @@ function phpMD($path, $type) {
4658
$runner->config->files = [$path];
4759
$runner->config->standards = ['Drupal'];
4860
$runner->config->extensions = [
49-
'php' => 'PHP',
50-
'module' => 'PHP',
51-
'inc' => 'PHP',
52-
'install' => 'PHP',
53-
'test' => 'PHP',
54-
'profile' => 'PHP',
55-
'theme' => 'PHP',
56-
'css' => 'CSS',
57-
'info' => 'PHP',
58-
'js' => 'JS'
61+
'php' => 'PHP',
62+
'module' => 'PHP',
63+
'inc' => 'PHP',
64+
'install' => 'PHP',
65+
'test' => 'PHP',
66+
'profile' => 'PHP',
67+
'theme' => 'PHP',
68+
'css' => 'CSS',
69+
'info' => 'PHP',
70+
'js' => 'JS',
5971
];
6072
$runner->init();
6173

@@ -69,15 +81,22 @@ function phpMD($path, $type) {
6981
print "phpcs DrupalPractice: " . $faults . "\n";
7082
$standards_faults += $faults;
7183

72-
// Lines of Code
73-
$files = (new FinderFacade([$path], [], ['*.php', '*.module', '*.install', '*.inc', '*.js', '*.scss'], []))->findFiles();
74-
$count = (new Analyser)->countFiles($files, true);
84+
// Lines of code.
85+
$finder = Finder::create();
86+
$finder->files()->in($path)->filter(static function (SplFileInfo $file) {
87+
return $file->isDir() || \preg_match('/\.(php|module|install|inc|js|scss)$/', $file->getPathname());
88+
});
89+
$files = [];
90+
foreach ($finder as $file) {
91+
$files[] = $file->getRealPath();
92+
}
93+
$count = (new Analyser)->countFiles($files, TRUE);
7594
$total_lines = $count['ncloc'];
7695

7796
$faults = $code_faults + $standards_faults;
7897
$percent = ($faults / $total_lines) * 100;
7998

80-
// Summary
99+
// Summary.
81100
print "Total Faults: " . $faults . "\n";
82101
print "Total Lines: " . $total_lines . "\n";
83102
print "Quality Score: " . number_format($percent, 2) . " faults per 100 lines\n";
@@ -86,21 +105,21 @@ function phpMD($path, $type) {
86105
$base = ($total_lines / $ratio) * sqrt($percent);
87106

88107
if ($percent > 25) {
89-
$hours = ($total_lines / $ratio) * sqrt($percent - ($percent - 25));
90-
print "Estimate to get to 25: " . number_format($base - $hours, 2) . " hours\n";
108+
$hours = ($total_lines / $ratio) * sqrt($percent - ($percent - 25));
109+
print "Estimate to get to 25: " . number_format($base - $hours, 2) . " hours\n";
91110
}
92111

93112
if ($percent > 10) {
94-
$hours = ($total_lines / $ratio) * sqrt($percent - ($percent - 10));
95-
print "Estimate to get to 10: " . number_format($base - $hours, 2) . " hours\n";
113+
$hours = ($total_lines / $ratio) * sqrt($percent - ($percent - 10));
114+
print "Estimate to get to 10: " . number_format($base - $hours, 2) . " hours\n";
96115
}
97116

98117
if ($percent > 5) {
99-
$hours = ($total_lines / $ratio) * sqrt($percent - ($percent - 5));
100-
print "Estimate to get to 5: " . number_format($base - $hours, 2) . " hours\n";
118+
$hours = ($total_lines / $ratio) * sqrt($percent - ($percent - 5));
119+
print "Estimate to get to 5: " . number_format($base - $hours, 2) . " hours\n";
101120
}
102121

103122
if ($percent > 3) {
104-
$hours = ($total_lines / $ratio) * sqrt($percent - ($percent - 3));
105-
print "Estimate to get to 3: " . number_format($base - $hours, 2) . " hours\n";
106-
}
123+
$hours = ($total_lines / $ratio) * sqrt($percent - ($percent - 3));
124+
print "Estimate to get to 3: " . number_format($base - $hours, 2) . " hours\n";
125+
}

0 commit comments

Comments
 (0)