Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
5fd4688
Make DEFAULT_CLASSIFIER public
stefanzweifel Jun 14, 2020
49290b0
Add first collectable Metrics
stefanzweifel Jun 14, 2020
3b5dfcb
Add Scratch Class to demonstrate Metric collection
stefanzweifel Jun 14, 2020
ffb4b8e
Extend StatsListoCommand with --share Option
stefanzweifel Jun 14, 2020
075d805
Apply php-cs-fixer changes
stefanzweifel Jun 14, 2020
600764a
Move to different Namespace
stefanzweifel Jun 20, 2020
aab1c06
Update Confirm Question in Stats Command
stefanzweifel Jun 20, 2020
ab8d41b
Simplify toArray() method on Metric
stefanzweifel Jun 20, 2020
1f22923
Add createProjectFromClasses helper to TestCase
stefanzweifel Jun 20, 2020
d9ba234
WIP
stefanzweifel Jun 20, 2020
3f2901c
Add More Model Stubs
stefanzweifel Jun 20, 2020
45c1cc9
Add NumberOfRelationships Metric (WIP)
stefanzweifel Jun 20, 2020
c7864de
Backfill Tests
stefanzweifel Jun 20, 2020
7a3971f
Reorganize AggregateAndSendToShift
stefanzweifel Jun 20, 2020
cabaae8
Add ProjectId Class
stefanzweifel Jun 20, 2020
6d2ba2e
Remove type from CollectableMetric
stefanzweifel Jun 20, 2020
0fdfa28
WIP
stefanzweifel Jun 20, 2020
34dc731
Apply php-cs-fixer changes
stefanzweifel Jun 20, 2020
bc9f3b7
Merge branch 'master' into metrics
stefanzweifel Jun 23, 2020
1ca0927
Update Keys for classes and methods
stefanzweifel Jun 23, 2020
50f9375
Remove FrameworkVersion Metric
stefanzweifel Jun 23, 2020
c8b9bc5
Add NumberOfPackages
stefanzweifel Jun 23, 2020
9165285
Hardcode ProjectId for now
stefanzweifel Jun 23, 2020
ad80136
Apply php-cs-fixer changes
stefanzweifel Jun 23, 2020
fbcdbe7
Update some metric names
stefanzweifel Jun 24, 2020
1aaaaf9
WIP
stefanzweifel Jun 24, 2020
0f90f2d
Add MetricsCollection
stefanzweifel Jun 24, 2020
c0795ac
Display Collected Metrics in Console
stefanzweifel Jun 24, 2020
72eeb2f
Apply php-cs-fixer changes
stefanzweifel Jun 24, 2020
ad43a21
Update Tests
stefanzweifel Jun 27, 2020
0f8c6e7
Update MetricsCollection and CollectMetrics
stefanzweifel Jun 27, 2020
bcec766
Update how ProjectName is determined
stefanzweifel Jun 27, 2020
a21f08a
Install symfony/process
stefanzweifel Jun 27, 2020
d262877
Update Stats Command
stefanzweifel Jun 27, 2020
bd77303
WIP
stefanzweifel Jun 27, 2020
a98d050
Apply php-cs-fixer changes
stefanzweifel Jun 27, 2020
4a29076
Display which project name was used
stefanzweifel Jun 27, 2020
d414bc0
Add ext-json to composer
stefanzweifel Jun 29, 2020
e4c4376
Add ModelsUseGuardedOrFillable
stefanzweifel Jun 29, 2020
e11cb16
Update Tests
stefanzweifel Jun 29, 2020
04f557b
Add ControllerFormRequestInjection
stefanzweifel Jun 29, 2020
24f26ae
Update Tests
stefanzweifel Jun 29, 2020
ab00421
Cast booleans to strings in ASCII Table
stefanzweifel Jun 29, 2020
15d7f14
Use ControllerFormRequestInjection Metric
stefanzweifel Jun 29, 2020
0d6ee33
Apply php-cs-fixer changes
stefanzweifel Jun 29, 2020
8ea9945
Simplify ControllerFormRequestInjection
stefanzweifel Jun 29, 2020
3429c78
Apply php-cs-fixer changes
stefanzweifel Jun 30, 2020
70457d4
Add CodeTestRatio Metric
stefanzweifel Jul 7, 2020
7ae6677
Add ModelsFolder Metric
stefanzweifel Jul 7, 2020
9de7f25
Rename ControllersFormRequestInjection
stefanzweifel Jul 7, 2020
7a93a5e
Add ModelsExtendOtherModel
stefanzweifel Jul 7, 2020
1901db7
Apply php-cs-fixer changes
stefanzweifel Jul 7, 2020
322e71a
Add more Stubs Controllers
stefanzweifel Jul 10, 2020
4d78059
Add --name option
stefanzweifel Jul 10, 2020
7fd4796
Rename Metric
stefanzweifel Jul 10, 2020
0791eec
Allow stats command to make requests to shift
stefanzweifel Jul 10, 2020
4ca194b
Update ModelsCustomInheritance.php
stefanzweifel Jul 10, 2020
982b0f0
Apply php-cs-fixer changes
stefanzweifel Jul 10, 2020
1b263f0
Sort Metrics displayed in ASCII Table
stefanzweifel Jul 10, 2020
acc7fca
Merge branch 'master' into metrics
stefanzweifel Jul 11, 2020
f5fbc4d
Merge branch 'master' into metrics
stefanzweifel Jul 11, 2020
9c0d368
Add ScheduledTasks Metric
stefanzweifel Jul 11, 2020
c9f7e9c
Add ComposerPsr4Sources
stefanzweifel Jul 11, 2020
b234557
Add ControllersCustomInheritance
stefanzweifel Jul 11, 2020
2073363
Rename ModelRelationship Metric
stefanzweifel Jul 11, 2020
3ff721e
Sort Metrics
stefanzweifel Jul 11, 2020
477f418
Remove a Test
stefanzweifel Jul 11, 2020
76fa45b
Fixes in ControllersFormRequestInjection
stefanzweifel Jul 11, 2020
2955c6a
Apply php-cs-fixer changes
stefanzweifel Jul 11, 2020
e6b9b57
Tweak package name for testing
jasonmccreary Jul 14, 2020
370901d
Revert "Tweak package name for testing"
jasonmccreary Jul 14, 2020
6bafb2c
Lessen constraints to support Laravel 6
jasonmccreary Jul 14, 2020
36eedd2
Add a --no-send option
stefanzweifel Jul 14, 2020
bda6cc0
Fix the --json --share output
stefanzweifel Jul 14, 2020
8592edf
Reference fork of PHPLoC
jasonmccreary Jul 14, 2020
11edc76
Downgrade to Guzzle for Laravel 6
jasonmccreary Jul 15, 2020
8977878
Downgrade Str::of for Laravel 6
jasonmccreary Jul 15, 2020
64696a3
Drop return type
jasonmccreary Jul 15, 2020
71d74d6
Delete ModelRelationships
stefanzweifel Jul 15, 2020
a55c602
Do not render metrics as ASCII table
stefanzweifel Jul 15, 2020
f5c2106
Add --payload option
stefanzweifel Jul 15, 2020
0043976
Replace phploc/phploc with registered fork
stefanzweifel Jul 15, 2020
6699144
Run tests also against Laravel 6.*
stefanzweifel Jul 15, 2020
70ea91e
Revert "Run tests also against Laravel 6.*"
stefanzweifel Jul 15, 2020
72143a2
Make request to Shift with --payload option
stefanzweifel Jul 15, 2020
e400b37
Update README
stefanzweifel Jul 15, 2020
bb0c29e
Add --dry-run option
stefanzweifel Jul 21, 2020
1c81c5e
Remove ".git" from project names
stefanzweifel Jul 21, 2020
910a03f
Don't make Http Request in Test Suite
stefanzweifel Jul 21, 2020
8b94081
Add Tests
stefanzweifel Jul 21, 2020
c2af213
Fix Tests
stefanzweifel Jul 21, 2020
e614680
Merge branch 'master' into metrics
stefanzweifel Jul 29, 2020
38c6ae8
Update dependency constraints to work under Laravel 6
stefanzweifel Jul 29, 2020
97a461e
Make Tests Compatible with Laravel 6
stefanzweifel Jul 29, 2020
68a5a2b
Apply php-cs-fixer changes
stefanzweifel Jul 29, 2020
8dec7cb
Change default value for confirmation question
stefanzweifel Jul 29, 2020
e8e5a56
Increment Timeout to Share API
stefanzweifel Jul 29, 2020
826a478
Update Typo in config/stats.php
stefanzweifel Aug 3, 2020
cd2ea27
Update README
stefanzweifel Aug 3, 2020
d221281
Add ProjectLogicalLinesOfCodePerMethod
stefanzweifel Aug 6, 2020
7595d39
Add validation for project name
stefanzweifel Aug 10, 2020
a37f73b
Update GitHub Actions part in README
stefanzweifel Aug 10, 2020
96e6322
Improve wording when asking for project name
stefanzweifel Aug 10, 2020
d4aed44
Determine git binary path in ProjectName
stefanzweifel Aug 24, 2020
2c8a8de
Add PROJECT_METRICS Constant
stefanzweifel Aug 24, 2020
3eebc73
Add AllMetricPayloadKeys
stefanzweifel Aug 24, 2020
9fea647
Merge branch 'master' into metrics
stefanzweifel Sep 1, 2020
952540f
Apply php-cs-fixer changes
stefanzweifel Sep 1, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ jobs:
fail-fast: true
matrix:
php: [7.3, 7.4]
laravel: [7.*]
laravel: [6.*, 7.*]
dependency-version: [prefer-lowest, prefer-stable]
include:
- laravel: 6.*
testbench: 4.*
- laravel: 7.*
testbench: 5.*

Expand Down
137 changes: 65 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@

### Installing

The easiest way to install the package is by using composer. The package requires PHP 7.3, Laravel 7.0 or higher or Lumen 7.0 or higher.

Due to version conflicts, `stats` can't be installed in Laravel 7 projects which are running with phpunit 8. **Phpunit 9 is required.**
The easiest way to install the package is by using composer. The package requires PHP 7.3, Laravel 6.0 or higher or Lumen 6.0 or higher.

```shell
composer require "wnx/laravel-stats" --dev
Expand All @@ -42,78 +40,12 @@ If you're using Lumen you have to manually register the Service Provider in your
$app->register(\Wnx\LaravelStats\StatsServiceProvider::class);
```

Optionally, you can publish the config file of this package with this command (Laravel only):
Optionally, you can publish the config file in your Laravel applications with the following command:

```shell
php artisan vendor:publish --provider="Wnx\LaravelStats\StatsServiceProvider"
```

The following config file will be published in `config/stats.php`

```php
<?php

return [

/*
* List of folders to be analyzed.
*/
'paths' => [
base_path('app'),
base_path('database'),
base_path('tests'),
],

/*
* List of files/folders to be excluded from analysis.
*/
'exclude' => [
// base_path('app/helpers.php'),
// base_path('app/Services'),
],

/*
* List of your custom Classifiers
*/
'custom_component_classifier' => [
// \App\Classifiers\CustomerExportClassifier::class
],

/*
* The Strategy used to reject Classes from the project statistics.
*
* By default all Classes located in
* the vendor directory are being rejected and don't
* count to the statistics.
*
* The package ships with 2 strategies:
* - \Wnx\LaravelStats\RejectionStrategies\RejectVendorClasses::class
* - \Wnx\LaravelStats\RejectionStrategies\RejectInternalClasses::class
*
* If none of the default strategies fit for your usecase, you can
* write your own class which implements the RejectionStrategy Contract.
*/
'rejection_strategy' => \Wnx\LaravelStats\RejectionStrategies\RejectVendorClasses::class,

/*
* Namespaces which should be ignored.
* Laravel Stats uses the `Str::startsWith()`class to
* check if a Namespace should be ignored.
*
* You can use `Illuminate` to ignore the entire `Illuminate`-namespace
* or `Illuminate\Support` to ignore a subset of the namespace.
*/
'ignored_namespaces' => [
'Wnx\LaravelStats',
'Illuminate',
'Symfony',
],

];

```


## Usage

After installing you can generate the statistics by running the following Artisan Command.
Expand All @@ -134,14 +66,13 @@ If you want a more detailed report and see which classes have been grouped into
php artisan stats --verbose
```

The verbose option is also available for the JSON format.
The verbose option is available for the JSON format also.

```
php artisan stats --json --verbose
```



## How does this package detect certain Laravel Components?

The package scans the files defined in the `paths`-array in the configuration file. It then applies [Classifiers](https://github.com/stefanzweifel/laravel-stats/tree/master/src/Classifiers) to those classes to determine which Laravel Component the class represents.
Expand Down Expand Up @@ -225,6 +156,68 @@ class RepositoryClassifier implements Classifier
...
```

## Share Metrics with the Laravel Community

You can optionally share your projects statistic by using the `--share` option.

```shell
php artisan stats --share
```

Your project statistics is shared anonymously with [stats.laravelshift.com](https://stats.laravelshift.com). In regular intervals the dashboard and charts on the site are updated with shared data from other Laravel projects.

To learn more about this feature, please check out PR [#178](https://github.com/stefanzweifel/laravel-stats/pull/178).

### Share statistic through CI

If you would like to share your project statistic in a CI environment you can use the `--no-interaction` and `--name`-options.

Use the following command in your CI script to share your project statistic automatically. (Update `org/repo` with the name of your application (eg. `acme/podcasting-app`))

```shell
php artisan stats --share --no-interaction --name=org/repo
```

If you're code is hosted on GitHub, you can integrate `stats` with [GitHub Actions](https://docs.github.com/en/actions).
Copy the following Workflow to `.github/workflows/laravel-stats.yml`. It will share data when a commit is pushed to the `master` branch. The Action automatically uses your GitHub repository name in the `--name`-option.

```yaml
name: stats

on:
push:
branches:
- master

jobs:
stats:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-suggest

- name: Share Stats
run: php artisan stats --share --name=$GITHUB_REPOSITORY --no-interaction
```

### Inspect Data shared with the Community

If you would like to inspect the payload the command is sending to the API you can use the `--dry-run` and `--payload` options.

```shell
php artisan stats --share --no-interaction --name="org/repo" --dry-run --payload
```

## Treeware

You're free to use this package, but if it makes it to your production environment you are required to buy the world a tree.
Expand Down
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
],
"require": {
"php": ">=7.3.0",
"illuminate/console": "^7.0",
"illuminate/support": "^7.0",
"phploc/phploc": "~6.0",
"symfony/finder": "~5.0"
"ext-json": "*",
"illuminate/console": "^6.0 || ^7.0",
"illuminate/support": "^6.0 || ^7.0",
"stefanzweifel/laravel-stats-phploc": "^6.1",
"symfony/finder": "^4.3 || ^5.0",
"symfony/process": "^4.3 || ^5.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.15",
"laravel/browser-kit-testing": "~6.0",
"laravel/browser-kit-testing": "~5.0 || ~6.0",
"laravel/dusk": "~5.0",
"mockery/mockery": "^1.1",
"orchestra/testbench": "^5.0",
"phpunit/phpunit": "9.*",
"orchestra/testbench": "^4.0 || ^5.0",
"phpunit/phpunit": "8.* || 9.*",
"psalm/plugin-laravel": "^1.3",
"vimeo/psalm": "^3.12"
},
Expand Down
2 changes: 1 addition & 1 deletion config/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

/*
* Namespaces which should be ignored.
* Laravel Stats uses the `Str::startsWith()`class to
* Laravel Stats uses the `Str::startsWith()` helper to
* check if a Namespace should be ignored.
*
* You can use `Illuminate` to ignore the entire `Illuminate`-namespace
Expand Down
2 changes: 1 addition & 1 deletion src/Classifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

class Classifier
{
private const DEFAULT_CLASSIFIER = [
public const DEFAULT_CLASSIFIER = [
ControllerClassifier::class,
ModelClassifier::class,
CommandClassifier::class,
Expand Down
4 changes: 4 additions & 0 deletions src/Classifiers/BladeComponentClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public function name(): string

public function satisfies(ReflectionClass $class): bool
{
if (! class_exists(Component::class)) {
return false;
}

return $class->isSubclassOf(Component::class);
}

Expand Down
4 changes: 4 additions & 0 deletions src/Classifiers/CustomCastClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public function name(): string

public function satisfies(ReflectionClass $class): bool
{
if ((float) app()->version() < 7) {
return false;
}

return $class->implementsInterface(CastsAttributes::class) ||
$class->implementsInterface(CastsInboundAttributes::class);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Classifiers/ObserverClassifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function satisfies(ReflectionClass $class): bool
{
return collect($this->getEvents())
->filter(function ($listeners, $event) {
return Str::of($event)->startsWith('eloquent.');
return Str::startsWith($event, 'eloquent.');
})
->map(function ($listeners) {
return collect($listeners)->map(function (Closure $closure) {
Expand All @@ -30,7 +30,7 @@ public function satisfies(ReflectionClass $class): bool
->collapse()
->unique()
->filter(function ($eventListenerSignature) use ($class) {
return Str::of($eventListenerSignature)->contains($class->getName());
return Str::contains($eventListenerSignature, $class->getName());
})
->count() > 0;
}
Expand Down
Loading