ajthinking / anything
Create code by imagining public apis
Requires
- php: ^8.1
- ajthinking/archetype: ^1.1
Requires (Dev)
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-11 08:01:57 UTC
README
Imagine public API:s and make it so - a TDD and sketch toy for Laravel projects 🤩
Getting started
Install and enable like so:
composer require ajthinking/anything --dev php artisan anything:on
Then, flesh out your idea and execute it in a console context. Lets say we want to build a git client:
// This class does not exist, yet App\Support\Git::client() ->pull() ->add('*') ->nah() ->wip() ->unwip() ->commit('message') ->push() ->build() // <-- creates the class!
The last method call ->build()
will create this class for you along with all the method stubs:
<?php namespace App\Support; class Git { public static function client() { return new static(); } public function pull() { return $this; } public function add() { return $this; } // ... }
When referenced statically like above the first call will typically spawn a static method. However, if the class name contains Facades\
lets say App\Facades\Zonda
we will instead make it an instance method and create a facade next to it:
<?php namespace App\Support\Facades; use Illuminate\Support\Facades\Facade; class Zonda extends Facade { protected static function getFacadeAccessor() { return 'App\\Zonda'; } }
Finally, make sure to clean up by discarding the change in bootstrap/app.php
with git, or by running
php artisan anything:off
Gotchas
This experiment comes with some limitations.
anything:on/off
commands it makes a little intrusion in yourbootstrap/app.php
to temporary swap out the console kernel. It assumes you have not made any major modifications to this file.- it will only work for classes in the
App
namespace - method arguments are currently ignored
- assumes everything returns
$this
- when using in tests, make sure your test case uses
CreatesApplication
. This might not always be the case for unit test setups
License
The MIT License (MIT). Please see License File for more information.