-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncaught UnexpectedValueException: $storage should not be null #11280
Comments
Hey @gijs-blanken, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug. |
Please manually search the entire codebases for classes named Defuse in the App\Facades namespace; it is possible you have two or more copies (including in the vendor folder). If there is only one copy, please send the class here, removing private code as needed (reducing the code as long as the error is still longer reproducible) |
I searched for duplicates of the Defuse class in a App\Facades namespace. Unfortunately I didn't find any duplicates. I'll try and provide as much context now. This concerns a Laravel 11 project. In config/app.php I have a class aliases pointing to \App\Facades\Defuse.php 'aliases' => [
'Defuse' => \App\Facades\Defuse::class,
], That point to the following class <?php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
/**
* @method static encryptFile($path, $path1, $decryptAccountKey)
* @method static decrypt($value, ?\Defuse\Crypto\Key $key = null)
*/
class Defuse extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'DefuseEncryption';
}
} In my app\Providers\ServiceProvider.php $this->app->singleton('DefuseEncryption', function ($_app) {
return new EncryptionHelper();
}); I also have a DefuseEncryption.php trait class <?php
namespace App\Traits;
use App\Facades\Defuse;
use Defuse\Crypto\Key as DefuseKey;
use Exception;
use function in_array;
/**
* @psalm-require-extends \Illuminate\Database\Eloquent\Model
*/
trait DefuseEncryption
{
/**
* Attempt decryption of object
*/
public function decrypt(?DefuseKey $key = null): void
{
foreach ($this->encrypted_fields as $field) {
try {
$this->attributes[$field] = Defuse::decrypt($this->attributes[$field], $key);
} catch (Exception) {
}
}
}
/**
* Attempt encryption of object
*/
public function encrypt(?DefuseKey $_key = null): void
{
}
/**
* @psalm-assert-if-true value-of<self::$encrypted_fields> $fieldName
* @param non-empty-string $fieldName
*/
public function isEncryptedField(string $fieldName): bool
{
return in_array($fieldName, $this->encrypted_fields);
}
} And the use App\Facades\Defuse;
private function encryptCredentials(array $credentials): array
{
return array_map(Defuse::forceEncrypt(...), $credentials);
} Hopefully this helps pin-point this issue. I should mention that all of this code has been in the codebase for quite some time. Thanks in advance @danog |
I managed to solve the error by adding the following annotations the App\Facades\Defuse.php file: <?php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
/**
* @method static bool encryptFile(string $inputFilename, string $outputFilename, ?\Defuse\Crypto\Key $key = null)
* @method static bool decryptFile(string $inputFilename, string $outputFilename, ?\Defuse\Crypto\Key $key = null, ?int $accountId = null)
* @method static string forceEncrypt(?string $message = null, ?\Defuse\Crypto\Key $key = null)
* @method static string decrypt(?string $ciphertext, ?\Defuse\Crypto\Key $key = null)
* @method static \Defuse\Crypto\Key decryptAccountKey(\App\Account $account)
*/
class Defuse extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'DefuseEncryption';
}
} |
Reopening, will attempt to fix the exception directly |
Hi everyone,
I'm running Psalm 6.5.1 and I'm running into an issue that was not present on the 5.20.0 branch when we were on PHP 8.3 (we are now on 8.4). I noticed a commit which supposedly fixed this error (#11232). But unfortunately it persists for me. I also tested the analyses with threads=1 and scan-threads=1 but to no avail. I'm not quite sure what extra context to add, please let me know!
Thanks in advance 😅
The text was updated successfully, but these errors were encountered: