• Stars
    star
    1,707
  • Rank 27,339 (Top 0.6 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 7 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📈 Get insights about your Laravel or Lumen Project

Laravel Stats

Buy us a tree

Get insights about your Laravel or Lumen Project.

Screenshot

Installing

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

composer require "wnx/laravel-stats" --dev

The package will automatically register itself.

If you're using Lumen you have to manually register the Service Provider in your bootstrap/app.php file:

$app->register(\Wnx\LaravelStats\StatsServiceProvider::class);

Optionally, you can publish the config file in your Laravel applications with the following command:

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

Usage

After installing you can generate the statistics by running the following Artisan Command.

php artisan stats

(Make sure you run php artisan config:clear before running the above command.)

The statistics are also available as JSON.

php artisan stats --json

If you want a more detailed report and see which classes have been grouped into which component, you can use the --verbose-option.

php artisan stats --verbose

The verbose option is available for the JSON format also.

php artisan stats --json --verbose

Note
If your project is using Pest PHP for writing tests, these files will automatically be excluded from the statistics. Due to how "laravel-stats" works internally, Pest PHP tests can't currently be detected. See #194 for more information.

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 to those classes to determine which Laravel Component the class represents.

Component Classification
Livewire Components Must extend Livewire\Component
Controller Must be registered with a Route & does not extend Livewire\Component
Model Must extend Illuminate\Database\Eloquent\Model
Command Must extend Illuminate\Console\Command
Rule Must extend Illuminate\Contracts\Validation\Rule
Policy The Policy must be registered in your AuthServiceProvider
Middleware The Middleware must be registered in your Http-Kernel
Event Must use Illuminate\Foundation\Events\Dispatchable-Trait
Event Listener Must be registered for an Event in EventServiceProvider
Mail Must extend Illuminate\Mail\Mailable
Notification Must extend Illuminate\Notifications\Notification
Nova Action Must extend Laravel\Nova\Actions\Action
Nova Dashboard Must extend Laravel\Nova\Dashboard
Nova Filter Must extend Laravel\Nova\Filters\Filter
Nova Lens Must extend Laravel\Nova\Lenses\Lens
Nova Resource Must extend Laravel\Nova\Resource
Job Must use Illuminate\Foundation\Bus\Dispatchable-Trait
Migration Must extend Illuminate\Database\Migrations\Migration
Request Must extend Illuminate\Foundation\Http\FormRequest
Resource Must extend Illuminate\Http\Resources\Json\JsonResource or Illuminate\Http\Resources\Json\ResourceCollection
Seeder Must extend Illuminate\Database\Seeder
ServiceProvider Must extend Illuminate\Support\ServiceProvider
Blade Components Must extend Illuminate\View\Component
Custom Casts Must implement Illuminate\Contracts\Database\Eloquent\CastsAttributes or Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes
Database Factory Must extend Illuminate\Database\Eloquent\Factory
Dusk Tests Must extend Laravel\Dusk\TestCase
BrowserKit Test Must extend Laravel\BrowserKitTesting\TestCase
PHPUnit Test Must extend PHPUnit\Framework\TestCase

Create your own Classifiers

If your application has it's own components you would like to see in laravel-stats you can create your own "Classifiers". Create your own Classifiers by implementing the Classifier-contract and adding the class to the stats.custom_component_classifier config array.

For example:

// app/Classifiers/RepositoryClassifier.php
<?php

namespace App\Classifiers;

use Wnx\LaravelStats\ReflectionClass;
use Wnx\LaravelStats\Contracts\Classifier;

class RepositoryClassifier implements Classifier
{
    public function name(): string
    {
        return 'Repositories';
    }

    public function satisfies(ReflectionClass $class): bool
    {
        return $class->isSubclassOf(\App\Repositories\BaseRepository::class);
    }

    public function countsTowardsApplicationCode(): bool
    {
        return true;
    }

    public function countsTowardsTests(): bool
    {
        return false;
    }
}
// config/stats.php
<?php
    ...
    'custom_component_classifier' => [
        \App\Classifiers\RepositoryClassifier::class
    ],
    ...

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.

It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you support this package and contribute to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees here offset.earth/treeware

Read more about Treeware at treeware.earth

Running the tests

The package has tests written in phpunit. You can run them with the following command.

./vendor/bin/phpunit

Running the command in a local test project

If you're working on the package locally and want to just run the command in a demo project you can use the composer path-repository format. Add the following snippet to the composer.json in your demo project.

{
    "repositories": [
        {
            "type": "path",
            "url": "/path/to/laravel-stats/",
            "options": {
                "symlink": true
            }
        }
    ],
}

And "install" the package with composer require wnx/laravel-stats. The package should now be symlinked in your demo project.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Credits

License

This project is licensed under the MIT License - see the LICENSE file for details.

More Repositories

1

git-auto-commit-action

Automatically commit and push changed files back to GitHub with this GitHub Action for the 80% use case.
Shell
1,970
star
2

screeenly

📸 Screenshot as a Service
PHP
493
star
3

sidecar-browsershot

A Sidecar function to run Browsershot on Lambda.
PHP
195
star
4

laravel-sends

A package to keep track of outgoing emails in your Laravel application.
PHP
175
star
5

laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.
PHP
162
star
6

changelog-updater-action

A GitHub Action to automatically update a "Keep a Changelog" CHANGELOG with the latest release notes.
Shell
122
star
7

diary-app

🔐An End-To-End Encrypted Diary Web App
PHP
93
star
8

laravel-github-actions-demo

A demo application to showcase useful GitHub Actions for PHP developers
PHP
30
star
9

kirby-json-feed

Kirby Plugin to serve a JSON Feed
PHP
26
star
10

reusable-workflows

A collection of reusable GitHub Actions workflows I use in my public and private projects.
26
star
11

dotfiles

🐼 My dotfiles
Shell
23
star
12

imgubox

[Deprecated] Store Imgur favorites in Dropbox
PHP
22
star
13

php-changelog-updater

PHP CLI to add latest release notes to a CHANGELOG
PHP
22
star
14

ScreeenlyClient

PHP API Wrapper for Screeenly
PHP
22
star
15

laravel-phpinsights-action

Run PHP Insights in Laravel in Github Actions
Dockerfile
21
star
16

php-swiss-cantons

🇨🇭 Find Swiss Canton by abbreviation, name or zipcode.
PHP
17
star
17

alfred-emoji-pack

PHP Script to generate Snippets for Alfred with all available Emojis.
PHP
14
star
18

commonmark-mark-extension

Render ==highlighted== texts as <mark> elements in league/commonmark
PHP
13
star
19

mp3-to-m4r-converter

Bulk-convert mp3 to m4r-files
Shell
13
star
20

deployer-on-github-actions-example

Example Repository showcasing how to run deployer on GitHub Actions
PHP
13
star
21

laravel-file-encryption-example

Example project to showcase backend file encryption
PHP
12
star
22

laravel-download-statistics-app

Aggregated download statistics for Laravel.
PHP
12
star
23

phpinsights-action

Run PHP Insights in Github Actions
Dockerfile
11
star
24

dropshare-landingpage

A minimal landingpage for Dropshare.app
HTML
7
star
25

uberspaceScripts

My personal collection of useful scripts, when hosting on uberspace.de
Shell
7
star
26

esbuild-mix-manifest-plugin

esbuild plugin to generate mix-manifest.json file compatible with Laravel Mix.
TypeScript
7
star
27

commonmark-markdown-renderer

Render a league/commonmark AST back to Markdown.
PHP
6
star
28

dirby

An opinionated Kirby theme for documentations
CSS
6
star
29

laravel-encryption-key-generator

A simple app to generate new Laravel encryption keys for you.
PHP
6
star
30

vue-tailwind-css-modules-demo

Demo application highlighting the use of Tailwind CSS in Vue Components
JavaScript
6
star
31

dropshare-tailwind-landingpage

Simple landingpage to use with Dropshare
JavaScript
5
star
32

js-swiss-cantons

🇨🇭 Find Swiss Canton by abbreviation or name
JavaScript
5
star
33

getting-started-with-bash-testing

Example Bash Project to get started with testing with Bats.
Shell
5
star
34

kirby-laravel-mix-helper

Helper to use Version Busting of Laravel Mix
PHP
5
star
35

icq-christmas-card

Revive one of the old ICQ Christmas Cards from 2002.
HTML
4
star
36

multi-photo-crop

🏙 A tool to crop and split photos from a single image
PHP
4
star
37

swiss-canton-iconfont

Serve the 26 Swiss Cantons in a simple icon font
CSS
3
star
38

example-advanced-eloquent-with-pivot

Example project mentioned in an article of mine.
PHP
3
star
39

asana-expander-extension

Browser Extension to automatically expand long comments in Asana
TypeScript
3
star
40

photon-the-archive-theme

A "The Archive" theme based on the PHPStorm Theme "Photon" by Brent Roose
3
star
41

alfred-emoji-pack-node

Emojis at your fingertips as Alfred Snippets
JavaScript
2
star
42

radio-srf-menubarapp

📻 A simple menubar application to play Radio SRF stations
Swift
2
star
43

faker-swiss-locations

Provider to generate valid Swiss location data for Faker PHP.
PHP
2
star
44

php-search-string-parser

[In Development] Use Search Input Strings similar to Github
PHP
2
star
45

git-auto-commit-action-demo-app

A demo application to test git-auto-commit Github Action
PHP
2
star
46

oh-dear-request-run-action

Trigger Oh Dear runs through GitHub Actions.
2
star
47

life-expectancy-visualisation

A small application to visualise the life expectancy of different people around the world.
TypeScript
2
star
48

scratchpad

Minimal Scratchpad
HTML
1
star
49

stefanzweifel

1
star
50

chrome-facebook-to-wikipedia-redirect

Read a Wikipedia Article instead of your Newsfeed
JavaScript
1
star
51

user-agent-analyzer

User Agent analysis as a Service.
PHP
1
star
52

git-auto-commit-demo-app

A demo application to test the git-auto-commit Action.
1
star
53

sidecar-browsershot-layer

AWS Lambda Layer containing puppeteer-core. Used by sidecar-browsershot
Shell
1
star