Giter VIP home page Giter VIP logo

laravel-stats's Introduction

Laravel Stats

Get insights about your Laravel or Lumen Project. (Inspired by rake stats)

Screenshot

Installing

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

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

The package will automatically register itself. However if you prefer to register Service Provider by yourself, update your config/app.php file:

'providers' => [
    \Wnx\LaravelStats\StatsServiceProvider
]

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 of this package with this command (Laravel only):

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

The following config file will be published in config/stats.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 `starts_with`-string helper, 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.

php artisan stats

The statistics are also available as JSON.

php artisan stats --format=json

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
Controller Must be registered with a Route
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
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\Resource
Seeder Must extend Illuminate\Database\Seeder
ServiceProvider Must extend Illuminate\Support\ServiceProvider
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 getName()
    {
        return 'Repository';
    }

    public function satisfies(ReflectionClass $class)
    {
        return $class->isSubclassOf(\App\Repositories\BaseRepository::class);
    }
}
// config/stats.php
<?php
    ...
    'custom_component_classifier' => [
        \App\Classifiers\RepositoryClassifier::class
    ],
    ...

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.

laravel-stats's People

Contributors

stefanzweifel avatar jerguslejko avatar krenor avatar thecrypticace avatar aiiro avatar dinhquochan avatar joaorobertopb avatar mannil avatar brandonsurowiec avatar dylan-dpc avatar devcircus avatar carusogabriel avatar mahdimajidzadeh avatar miclf avatar sebdesign avatar

Watchers

James Cloos avatar Kishore Chandra Sahoo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.