first commit
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
## PHP 8.4
|
||||
|
||||
- PHP 8.4 has new array functions that will make code simpler whenever we don't use Laravel's collections:
|
||||
- `array_find(array $array, callable $callback): mixed` - Find first matching element.
|
||||
- `array_find_key(array $array, callable $callback): int|string|null` - Find first matching key.
|
||||
- `array_any(array $array, callable $callback): bool` - Check if any element satisfies a callback function.
|
||||
- `array_all(array $array, callable $callback): bool` - Check if all elements satisfy a callback function.
|
||||
|
||||
### Cleaner Chaining on New Instances
|
||||
- No extra parentheses are needed when chaining on new object instances:
|
||||
|
||||
<code-snippet name="New Object Chaining Example" lang="php">
|
||||
// Before PHP 8.4
|
||||
$response = (new JsonResponse(['data' => $data]))->setStatusCode(201);
|
||||
|
||||
// After PHP 8.4
|
||||
$response = new JsonResponse(['data' => $data])->setStatusCode(201);
|
||||
</code-snippet>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
## PHP 8.5
|
||||
|
||||
- PHP 8.5 has new array functions that will make code simpler whenever we don't use Laravel's collections:
|
||||
- `array_first(array $array): mixed` - Get first value (or `null` if empty).
|
||||
- `array_last(array $array): mixed` - Get last value (or `null` if empty).
|
||||
|
||||
- Use `clone($object, ['property' => $value])` to modify properties during cloning; this is ideal for readonly classes.
|
||||
|
||||
### Pipe Operator
|
||||
- The pipe operator (`|>`) chains function calls left-to-right, replacing nested calls:
|
||||
<code-snippet name="Pipe Operator Example" lang="php">
|
||||
// Before PHP 8.5
|
||||
$slug = strtolower(str_replace(' ', '-', trim($title)));
|
||||
|
||||
// After PHP 8.5
|
||||
$slug = $title |> trim(...) |> (fn($s) => str_replace(' ', '-', $s)) |> strtolower(...);
|
||||
</code-snippet>
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
## PHP
|
||||
|
||||
@php
|
||||
/** @var \Laravel\Boost\Install\GuidelineAssist $assist */
|
||||
@endphp
|
||||
@if($assist->shouldEnforceStrictTypes())
|
||||
- Always use strict typing at the head of a `.php` file: `declare(strict_types=1);`.
|
||||
@endif
|
||||
- Always use curly braces for control structures, even if it has one line.
|
||||
|
||||
### Constructors
|
||||
- Use PHP 8 constructor property promotion in `__construct()`.
|
||||
- <code-snippet>public function __construct(public GitHub $github) { }</code-snippet>
|
||||
- Do not allow empty `__construct()` methods with zero parameters unless the constructor is private.
|
||||
|
||||
### Type Declarations
|
||||
- Always use explicit return type declarations for methods and functions.
|
||||
- Use appropriate PHP type hints for method parameters.
|
||||
|
||||
<code-snippet name="Explicit Return Types and Method Params" lang="php">
|
||||
protected function isAccessible(User $user, ?string $path = null): bool
|
||||
{
|
||||
...
|
||||
}
|
||||
</code-snippet>
|
||||
|
||||
## Comments
|
||||
- Prefer PHPDoc blocks over inline comments. Never use comments within the code itself unless there is something very complex going on.
|
||||
|
||||
## PHPDoc Blocks
|
||||
- Add useful array shape type definitions for arrays when appropriate.
|
||||
|
||||
## Enums
|
||||
@if(empty($assist->enums()) || preg_match('/[A-Z]{3,8}/', $assist->enumContents()))
|
||||
- Typically, keys in an Enum should be TitleCase. For example: `FavoritePerson`, `BestLake`, `Monthly`.
|
||||
@else
|
||||
- That being said, keys in an Enum should follow existing application Enum conventions.
|
||||
@endif
|
||||
Reference in New Issue
Block a user