Loading...
Loading...
Compare original and translation side by side
?stringstring|nullvoid?stringstring|nullvoidvoid?TypeType|null/** @return Collection<int, User> */
public function getUsers(): Collectionvoid?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
} */use \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();
}
}&&ifif// 正常路径后置
if (! $user) {
return null;
}
if (! $user->isActive()) {
return null;
}
// 处理活跃用户...
// 简短三元运算符
$name = $isFoo ? 'foo' : 'bar';
// 多行三元运算符
$result = $object instanceof Model ?
$object->name :
'A default value';
// 用三元运算符替代else
$condition
? $this->doSomething()
: $this->doSomethingElse();
// 不良写法:使用&&的复合条件
if ($user->isActive() && $user->hasPermission('edit')) {
$user->edit();
}
// 良好写法:嵌套if
if ($user->isActive()) {
if ($user->hasPermission('edit')) {
$user->edit();
}
}/open-source->name('openSource'){userId}[Controller::class, 'method']/open-source->name('openSource'){userId}[Controller::class, 'method']PostsControllerindexcreatestoreshoweditupdatedestroyPostsControllerindexcreatestoreshoweditupdatedestroypdf-generator.phpchrome_pathconfig/services.phpconfig()env()pdf-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.");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();// 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);
});public function rules() {
return [
'email' => ['required', 'email'],
];
}Validator::extend('organisation_type', function ($attribute, $value) {
return OrganisationType::isValid($value);
});@if($condition)
Something
@endif@if($condition)
Something
@endifGate::define('editPost', ...)viewshowGate::define('editPost', ...)viewshow__()@lang__()@lang/errors/error-occurrences/error-occurrences/1
/errors/1/occurrences/errors/error-occurrences/error-occurrences/1
/errors/1/occurrencesUserControllerOrderStatusgetUserName$firstName/open-source/user-profilepdf-generator.phpchrome_pathphp artisan delete-old-recordsUserControllerOrderStatusgetUserName$firstName/open-source/user-profilepdf-generator.phpchrome_pathphp artisan delete-old-recordsControllerPostsControlleropenSource.blade.phpCreateUserSendEmailNotificationUserRegisteringUserRegisteredListenerSendInvitationMailListenerCommandPublishScheduledPostsCommandMailAccountActivatedMailResourceTransformerUsersResourceOrderStatusBookingTypeControllerPostsControlleropenSource.blade.phpCreateUserSendEmailNotificationUserRegisteringUserRegisteredListenerSendInvitationMailListenerCommandPublishScheduledPostsCommandMailAccountActivatedMailResourceTransformerUsersResourceOrderStatusBookingTypeelseif&&ifuse\Exception\Illuminate\Support\Facades\Http$exception$e$request$r&&ififuse\Exception\Illuminate\Support\Facades\Http$exception$e$request$r