Skip to content

Commit

Permalink
Using a softer exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mamazu committed Mar 24, 2024
1 parent 836d962 commit f8c99ee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
@@ -1,4 +1,4 @@
<?php
<?phpclas

namespace Phpactor\WorseReflection\Bridge\TolerantParser\Reflection\TraitImport;

Expand All @@ -15,6 +15,7 @@
use Microsoft\PhpParser\Node\TraitUseClause;
use Microsoft\PhpParser\TokenKind;
use Phpactor\WorseReflection\Bridge\TolerantParser\Patch\TolerantQualifiedNameResolver;
use Phpactor\WorseReflection\Core\Exception\NotFound;
use Phpactor\WorseReflection\Core\Util\QualifiedNameListUtil;
use Phpactor\WorseReflection\Core\Visibility;
use RuntimeException;
Expand Down Expand Up @@ -107,7 +108,9 @@ private function __construct(array $declarations)

public static function forClassDeclaration(ClassDeclaration|ObjectCreationExpression $classDeclaration): self
{
assert($classDeclaration->classMembers instanceof ClassMembersNode, 'ObjectCreationExpression does not contain anonymous class');
if (!$classDeclaration->classMembers instanceof ClassMembersNode) {
throw new NotFound('ObjectCreationExpression does not contain anonymous class');
}

return new self($classDeclaration->classMembers->classMemberDeclarations);
}
Expand Down
Expand Up @@ -25,6 +25,7 @@
use Phpactor\WorseReflection\Bridge\TolerantParser\Reflection\ReflectionPromotedProperty;
use Phpactor\WorseReflection\Bridge\TolerantParser\Reflection\ReflectionProperty;
use Phpactor\WorseReflection\Core\ClassName;
use Phpactor\WorseReflection\Core\Exception\NotFound;
use Phpactor\WorseReflection\Core\Reflection\ReflectionClass;
use Phpactor\WorseReflection\Core\Reflection\ReflectionClassLike;
use Phpactor\WorseReflection\Core\Reflection\ReflectionConstant as PhpactorReflectionConstant;
Expand Down Expand Up @@ -73,7 +74,9 @@ public static function fromClassMemberDeclarations(
ClassDeclaration|ObjectCreationExpression $class,
ReflectionClass $reflectionClass
): self {
assert($class->classMembers instanceof ClassMembersNode, 'ObjectCreationExpression does not contain anonymous class');
if (!$class->classMembers instanceof ClassMembersNode) {
throw new NotFound('ObjectCreationExpression does not contain anonymous class');
}

return self::fromDeclarations(
$serviceLocator,
Expand Down
Expand Up @@ -23,7 +23,9 @@ public static function fromClassDeclaration(
ServiceLocator $serviceLocator,
ClassDeclaration|ObjectCreationExpression $class,
): self {
assert($class->classMembers instanceof ClassMembersNode, 'ObjectCreationExpression does not contain anonymous class');
if (!$class->classMembers instanceof ClassMembersNode) {
throw new NotFound('ObjectCreationExpression does not contain anonymous class');
}

$items = [];
foreach ($class->classMembers->classMemberDeclarations as $memberDeclaration) {
Expand Down

0 comments on commit f8c99ee

Please sign in to comment.