bmitch / churn-php Goto Github PK
View Code? Open in Web Editor NEWDiscover files in need of refactoring.
License: MIT License
Discover files in need of refactoring.
License: MIT License
For example, when providing the path src
right now it displays the files like:
+------------------------------------------------------------------------------------------------+---------------+------------+-------+
| File | Times Changed | Complexity | Score |
+------------------------------------------------------------------------------------------------+---------------+------------+-------+
| /home/bmitch/Code/ChurnPhp/src/Assessors/CyclomaticComplexity/CyclomaticComplexityAssessor.php | 4 | 4 | 8 |
| /home/bmitch/Code/ChurnPhp/src/Assessors/GitCommitCount/GitCommitCountAssessor.php | 3 | 4 | 7 |
| /home/bmitch/Code/ChurnPhp/src/Commands/ChurnCommand.php | 3 | 2 | 5 |
| /home/bmitch/Code/ChurnPhp/src/Managers/FileManager.php | 1 | 3 | 4 |
| /home/bmitch/Code/ChurnPhp/src/Results/ResultsGenerator.php | 1 | 2 | 3 |
| /home/bmitch/Code/ChurnPhp/src/Services/CommandService.php | 2 | 1 | 3 |
| /home/bmitch/Code/ChurnPhp/src/Results/ResultCollection.php | 1 | 1 | 2 |
| /home/bmitch/Code/ChurnPhp/src/Results/Result.php | 1 | 1 | 2 |
+------------------------------------------------------------------------------------------------+---------------+------------+-------+
Would be nice if it was like this instead.
+-----------------------------------------------------------------+---------------+------------+-------+
| File | Times Changed | Complexity | Score |
+-----------------------------------------------------------------+---------------+------------+-------+
| Assessors/CyclomaticComplexity/CyclomaticComplexityAssessor.php | 4 | 4 | 8 |
| Assessors/GitCommitCount/GitCommitCountAssessor.php | 3 | 4 | 7 |
| Commands/ChurnCommand.php | 3 | 2 | 5 |
| Managers/FileManager.php | 1 | 3 | 4 |
| Results/ResultsGenerator.php | 1 | 2 | 3 |
| Services/CommandService.php | 2 | 1 | 3 |
| Results/ResultCollection.php | 1 | 1 | 2 |
| Results/Result.php | 1 | 1 | 2 |
+-----------------------------------------------------------------+---------------+------------+-------+
Because of this line:
https://github.com/bmitch/churn-php/blob/master/src/Factories/ProcessFactory.php#L35
Is there another command that will do the same thing that works in Windows and Unix?
FILE: /home/bmitch/Code/ChurnPhp/src/Managers/FileManager.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
35 | ERROR | 3 indentation levels found. Maximum of 2 indentation levels
| | allowed. (Codor.Files.IndentationLevel)
Could show:
I think if you try to make a regex pattern like *.php
to ignore files it won't give you the expected results.
I created this test:
$fileManager = new FileManager(['php', 'inc'], ['Assets2/*.php']);
$this->assertCount(1, $fileManager->getPhpFiles([__DIR__ . '/../Assets2']));
Which I would expect to pass but it fails.
Stems from #40
I am envisioning something like this:
vendor/bin/churn-php src
+--------------+---------------+---------------+---------------+
| File | Times Changed | CycComplexity | Score |
+--------------+---------------+---------------+---------------+
| src/Foo.php | 10 | 5 | 50 |
| src/Bar.php | 5 | 7 | 35 |
| src/Baz.php | 2 | 1 | 2 |
+--------------+---------------+---------------+---------------+
See #78 (comment)
This new feature allows you to ignore files using a regex.
The readme.md should be updated to reflect that.
This can be a value added to the yml config. For example, if you have a large git commit history you may only want to limit the changes within the last year:
$process = new Process(
'git -C ' . getcwd() . " log --since=\"1 year ago\" --name-only --pretty=format: " . $file->getFullPath(). " | sort | uniq -c | sort -nr"
);
For that for this feature I'd also want the user to be able to provide the paths via the churn.yml file if they like.
Possibly like:
folders:
- src
- tests
Stems from #40
A sniff to disallow the use of instanceof function would be good to have.
The use of it is a code smell and represents a flaw in the project Software Architecture.
I love this package that helps us to write more SOLID and Clean Code.
<HEADER GOES HERE>
+-----------------------------------------------------------+---------------+------------+-------+
| File | Times Changed | Complexity | Score |
+-----------------------------------------------------------+---------------+------------+-------+
...
See the original comment here:
Stems from #40
Cyc Complex * changes?
Should one of those scores weigh more than the other?
Here:
/**
* Config constructor.
* @param array $rawData Raw config data.
*/
public function __construct(array $rawData = [])
{
$this->filesToShow = $rawData['filesToShow'] ?? 10;
$this->parallelJobs = $rawData['parallelJobs'] ?? 10;
$this->commitsSince = $rawData['commitsSince'] ?? '10 years ago';
$this->filesToIgnore = $rawData['filesToIgnore'] ?? [];
}
Though git is the most popular, mercurial is heavily used as well and it would be interesting to put this to use.
Stems from #40
This is due to the command used in the process factory.
Perhaps there's another way of doing the same command that will work in windows + unix platforms.
Might look better with a screen shot that shows the colours.
Thanks for a nice tool!
The way I understand it (and the way it's described in this article: https://www.sandimetz.com/blog/2017/9/13/breaking-up-the-behemoth), we should consider to refactor classes that are high on high on both complexity and times changed. Otherwise, we would start refactoring complex classes that change almost never (which is a waste of effort) or we would start refactoring simple classes that change often (which also makes no sense, since it's very easy to make the change, so it doesn't cost us much).
What do you think?
With a large number of files the results take a while to come back. Need some way to run the files in parallel.
If we used something like the above then we'd need to probably create another command that simple takes the file path and returns the results.
Using set methods in a class is not advised, because:
I can continue with more cases why we should not use set methods, but I think the above 3 ones are strong enough to justify the sniff.
Thanks for your excellent work.
I'm open to reviews of the readme if anyone has any suggestions.
Still not entirely happy with the screenshot in the readme.md
CyclomaticComplexityAssessor.php
) in the results which forces the table to be very wide. If that file was ignored the table would be smaller in width which I think would improve the screenshot.In order to get the git commits we'll need to know the root folder so that we can run the git command.
We could also store other values in here:
Also need to make sure it works without a yml file present or some options not set.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.