Loading...
Loading...
Describes PHP and Laravel guidelines provided by Spatie. These rules result in more maintainable, and readable code.
npx skill4agent add freekmurze/dotfiles php-guidelines-from-spatie?stringstring|nullvoidvoid?TypeType|null/** @return Collection<int, User> */
public function getUsers(): Collectionuse \Spatie\Url\Url;
/** @return Url *//** @var string *//** @var Collection|SomeWeirdVendor\Collection *//**
* @param array<int, MyObject> $myArray
* @param int $typedArgument
*/
function someFunction(array $myArray, int $typedArgument) {}/** @return array{
first: SomeClass,
second: SomeClass
} */if&&if// Happy path last
if (! $user) {
return null;
}
if (! $user->isActive()) {
return null;
}
// Process active user...
// Short ternary
$name = $isFoo ? 'foo' : 'bar';
// Multi-line ternary
$result = $object instanceof Model ?
$object->name :
'A default value';
// Ternary instead of else
$condition
? $this->doSomething()
: $this->doSomethingElse();
// Bad: compound condition with &&
if ($user->isActive() && $user->hasPermission('edit')) {
$user->edit();
}
// Good: nested ifs
if ($user->isActive()) {
if ($user->hasPermission('edit')) {
$user->edit();
}
}/open-source->name('openSource'){userId}[Controller::class, 'method']PostsControllerindexcreatestoreshoweditupdatedestroypdf-generator.phpchrome_pathconfig/services.phpconfig()env()delete-old-records$this->comment('All ok!')$items->each(function(Item $item) {
$this->info("Processing item id `{$item->id}`...");
$this->processItem($item);
});
$this->comment("Processed {$items->count()} items.");// Get the failed checks for this site
$checks = $site->checks()->where('status', 'failed')->get();$failedChecks = $site->checks()->where('status', 'failed')->get();{}public function rules() {
return [
'email' => ['required', 'email'],
];
}Validator::extend('organisation_type', function ($attribute, $value) {
return OrganisationType::isValid($value);
});@if($condition)
Something
@endifGate::define('editPost', ...)viewshow__()@lang/errors/error-occurrences/error-occurrences/1
/errors/1/occurrencesUserControllerOrderStatusgetUserName$firstName/open-source/user-profilepdf-generator.phpchrome_pathphp artisan delete-old-recordsControllerPostsControlleropenSource.blade.phpCreateUserSendEmailNotificationUserRegisteringUserRegisteredListenerSendInvitationMailListenerCommandPublishScheduledPostsCommandMailAccountActivatedMailResourceTransformerUsersResourceOrderStatusBookingTypeelseif&&ifuse\Exception\Illuminate\Support\Facades\Http$exception$e$request$r