-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first draft of "Utility methods" page
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Utility Methods | ||
## ensureNotEmpty | ||
The `ensureNotEmpty` method on the fixture helper checks that any given variable is not [empty](#todo). If it is, it will throw a `LogicException`. | ||
|
||
This method also includes the needed annotations, so that [PHPstan](#todo) and [Psalm](#todo) don't throw any errors afterwards: | ||
|
||
```php | ||
<?php | ||
|
||
class MyFixture extends Fixture { | ||
public function load(): void { | ||
$salesChannel = $this->helper->SalesChannel()->getStorefrontSalesChannel(); | ||
$this->helper->ensureNotEmpty($salesChannel); // [!code focus] | ||
|
||
// Static code analysis now knows that `$salesChannel` exists and is not empty/null. // [!code focus] | ||
$salesChannel->getId(); | ||
} | ||
} | ||
``` |