Skip to editor
Psalm
Docs
Playground
Plugins
Blog
Paid support
Share
Fix issues
Show original
PHP
Settings
<?php // Current state. We have to create temporary variables where it is not necessary $firstName = getParam('firstName'); $lastName = getParam('lastName'); notNull($firstName); notNull($lastName); createCustomer( $firstName, $lastName ); // Possible workaround. We can create helper method inside project createCustomer( notNullableString(getParam('firstName')), notNullableString(getParam('lastName')) ); // Desired approach. We would love to see that notNull() returns a validated value. createCustomer( notNull(getParam('firstName')), notNull(getParam('lastName')) ); /* * Helper methods */ function notNullableString(?string $value) : string { notNull($value); return $value; } /** * @psalm-pure * @psalm-assert !null $value * @template T * @psalm-param T|null $value * @psalm-return T * * @throws InvalidArgumentException */ function notNull($value) { if (null === $value) { throw new InvalidArgumentException(); } return $value; } function getParam(string $name) : ?string { $value = $_GET[$name] ?? null; if (is_string($value)) { return $value; } return null; } function createCustomer(string $firstName, string $lastName) : void { print("$firstName $lastName"); }
Issues
Types
idle
Saved Jan 16 2023 09:53 UTC
⌘/Ctrl+Enter
run
⌘/Ctrl+S
share
F8
/
⇧F8
next/prev issue