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 8e24b48
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Expand Up @@ -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
6 changes: 6 additions & 0 deletions lib/WorseReflection/Core/Reflector/CoreReflector.php
Expand Up @@ -5,6 +5,7 @@
use Amp\Promise;
use Generator;
use Microsoft\PhpParser\Node;
use Microsoft\PhpParser\Node\Expression\ObjectCreationExpression;
use Phpactor\TextDocument\ByteOffset;
use Phpactor\WorseReflection\Bridge\TolerantParser\Reflection\ReflectionNavigation;
use Phpactor\WorseReflection\Core\ClassName;
Expand Down Expand Up @@ -38,6 +39,11 @@ public function __construct(private SourceCodeReflector $sourceReflector, privat
{
}

public static function getAnonymousClassName(ObjectCreationExpression $class): string

Check failure on line 42 in lib/WorseReflection/Core/Reflector/CoreReflector.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1)

Method Phpactor\WorseReflection\Core\Reflector\CoreReflector::getAnonymousClassName() should return string but return statement is missing.
{

}

/**
* Reflect class.
*
Expand Down

0 comments on commit 8e24b48

Please sign in to comment.