MCMatters/laravel-helpers

View on GitHub
src/Macros/AbstractMacroable.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

declare(strict_types=1);

namespace McMatters\Helpers\Macros;

use Illuminate\Support\Str;
use ReflectionClass;

abstract class AbstractMacroable
{
    /**
     * Auto registration of macros.
     */
    public function register(): void
    {
        $reflection = new ReflectionClass(static::class);

        foreach ($reflection->getMethods() as $method) {
            $method = $method->getName();

            if ($method !== 'register' && Str::startsWith($method, 'register')) {
                $this->{$method}();
            }
        }
    }
}