-
-
Notifications
You must be signed in to change notification settings - Fork 84
Share Feature and Shareable Metrics #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If cast to an array, a Metric should just be a key/value pair.
This Metric only yields result, if the relationship methods have a type hint with a Laravel Relationship. If no type hint is added, we can't detect if the method returns a relationship or not. (Or at least I need to dig deeper of what's possible with Reflection)
This reverts commit 6699144.
Codecov Report
@@ Coverage Diff @@
## master #178 +/- ##
============================================
- Coverage 96.35% 92.90% -3.45%
- Complexity 241 318 +77
============================================
Files 42 62 +20
Lines 685 987 +302
============================================
+ Hits 660 917 +257
- Misses 25 70 +45
Continue to review full report at Codecov.
|
This Class is mostly used for internal development purposes.
# Conflicts: # tests/ValueObjects/ClassifiedClassTest.php # tests/ValueObjects/ComponentTest.php
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This Pull Request adds a new feature to laravel-stats: a
--shareoption. In addition, this PR allows the package to be installed in Laravel 6 applications again.If you want to learn more about this branch and the added features, checkout these live streams:
If you want to test this branch in your project, you can install this "alpha" version by running.
As this PR is quite big, let's go through the changes one by one.
Add back support for Laravel 6.*
Back in March 2020, I've released v2.1.0 and with it removed support for Laravel 6. Due to the changes made to one of our core dependencies –
phploc/phploc- this was the straightforward solution.However, the newly added
--share-feature and its dashboard will benefit if Laravel 6 user can use it too. 6.0 is also an LTS, so a lot more people are on that version.To make this possible, I've forked the
phploc-package and made it compatible for both Laravel 6 and Laravel 7.The fork can be found here. I do not recommend installing this package in any of your projects as a direct dependency. When Laravel 6 download numbers fall, I will switch back to the "normal"
phploc/phploc-version.The
--shareoptionJason McCreary, the creator of Shift, and I had an idea 2 years ago after Jason gave his "Laravel by the Numbers" talk at Laracon US 2018: How can be safely collect project statistics, analyze them and present them to the community in an easy-to-read way?
This new option is part one of the solution we came up with. Part two will be a open source repository we're going to release soon. In there you can inspect the code and see, how the data is grouped and displayed.
Enough back story. Here's a quick overview how this feature has been implemented
StatsCommand
The
statsartisan command has been extended with several new options:--s|share: Indicate that you would like to share project statistics with the Laravel Community--name: Overrides the project name which the stats command would try to determine itself. (Useful if you want to use the--shareoption in a CI setting--payload: Passing this option will output the payload to the console, the command would send to the remote Share API.--dry-run: Passing this option prevents the command from actually making the request to the Share API.A note regarding the
--name-option: In order to make sure, that your project statistics are counted only once, the Share API needs to uniquely identify your project. We chose the simplest way of giving your project a name.If you run
php artisan stats --sharethe command will try to determine the project name based on the remote repository name stored in your local git configuration. The command will ask you to confirm or update the name.The name will be stored in a
.laravelstatsrc-file. If the file exists and has a name in it, the command won't ask you for the project name again.Shareable Metrics
The code for the new feature can be found in
src/ShareableMetrics. In there you will find a list of metrics the command will send to the Share API.In addition to the "core" metrics the stats command shows you in the console, we've written a few new ones which we think are interesting. Like:
models_mass_assignment: This metric determines if you're using morefillableorguardedin your Models.controllers_custom_inheritance: This metric determines if your controllers extend other controllers (for example: All your API controllers extends aBaseApiController).controllers_form_request_injection: This metrics determines, if your using Form Requests in your controllers.The code for these metrics might look intimidating. In their core, they are looping through a collection of classes in your project and use the PHP reflection API to determine if they conform to a given measured metric.
In the future, I would like to refactor the code for these metrics, to make them easier to understand for new comers to the package.
We hope that the community likes the idea we had too.
We hope that the anonymously shared data will help us build better and more robust applications.
TODOs
--share--shareon CI