Skip to content

Commit

Permalink
Introduce new ClassStorageNotFoundException for missing class storages
Browse files Browse the repository at this point in the history
  • Loading branch information
ohader committed Feb 19, 2024
1 parent c022deb commit 3bd76e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/Psalm/Exception/ClassStorageNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Psalm\Exception;

use InvalidArgumentException;

/**
* To be thrown when a `\Psalm\Storage\ClassLikeStorage` for a given name could not be resolved.
*/
final class ClassStorageNotFoundException extends InvalidArgumentException
{
private ?string $name = null;

public function setName(string $name): self
{
$this->name = $name;
return $this;
}

public function getName(): ?string
{
return $this->name;
}
}
5 changes: 4 additions & 1 deletion src/Psalm/Internal/Provider/ClassLikeStorageProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use InvalidArgumentException;
use LogicException;
use Psalm\Exception\ClassStorageNotFoundException;
use Psalm\Storage\ClassLikeStorage;

use function strtolower;
Expand Down Expand Up @@ -40,7 +41,9 @@ public function get(string $fq_classlike_name): ClassLikeStorage
$fq_classlike_name_lc = strtolower($fq_classlike_name);
/** @psalm-suppress ImpureStaticProperty Used only for caching */
if (!isset(self::$storage[$fq_classlike_name_lc])) {
throw new InvalidArgumentException('Could not get class storage for ' . $fq_classlike_name_lc);
throw (new ClassStorageNotFoundException(
'Could not get class storage for ' . $fq_classlike_name_lc)
)->setName($fq_classlike_name_lc);
}

/** @psalm-suppress ImpureStaticProperty Used only for caching */
Expand Down

0 comments on commit 3bd76e3

Please sign in to comment.