...
 
Commits (3)
......@@ -6,6 +6,10 @@ includes:
parameters:
ignoreErrors:
# We can fix this, but it's not our problem to fix and it's never called directly. We just want to just be
# able to use inheritDoc here.
- '#Method [A-Za-z\\]+::jsonSerialize\(\) return type has no value type specified in iterable type array.#'
-
message: '#Variable property access on#'
path: 'src/Analysis/Visiting/ScopeLimitingVisitor.php'
......@@ -35,14 +35,9 @@ final class ClasslikeConstantConverter
public function convertForClass(Structures\ClassConstant $constant, ArrayAccess $class): array
{
return array_merge($this->constantConverter->convert($constant), [
'isPublic' => $constant->getAccessModifier() !== null ?
$constant->getAccessModifier()->getName() === AccessModifierNameValue::PUBLIC_ : true,
'isProtected' => $constant->getAccessModifier() !== null ?
$constant->getAccessModifier()->getName() === AccessModifierNameValue::PROTECTED_ : false,
'isPrivate' => $constant->getAccessModifier() !== null ?
$constant->getAccessModifier()->getName() === AccessModifierNameValue::PRIVATE_ : false,
'isPublic' => $constant->getAccessModifier()->getName() === AccessModifierNameValue::PUBLIC_,
'isProtected' => $constant->getAccessModifier()->getName() === AccessModifierNameValue::PROTECTED_,
'isPrivate' => $constant->getAccessModifier()->getName() === AccessModifierNameValue::PRIVATE_,
'declaringClass' => [
'fqcn' => $class['fqcn'],
......
......@@ -2,7 +2,6 @@
namespace Serenata\Analysis\Node;
use LogicException;
use UnexpectedValueException;
use Serenata\Analysis\FunctionListProviderInterface;
......@@ -54,11 +53,7 @@ final class FunctionFunctionInfoRetriever
{
if ($node instanceof Node\Stmt\Function_) {
return $this->getFunctionInfo('\\' . $node->namespacedName->toString());
} elseif (!$node instanceof Node\Expr\FuncCall) {
throw new LogicException(
'Expected function definition node or function call node, got ' . get_class($node) . ' instead'
);
} elseif ($node->name instanceof Node\Expr) {
} elseif (/*$node instanceof Node\Expr\FuncCall && */$node->name instanceof Node\Expr) {
throw new UnexpectedValueException(
'Determining the info for dynamic function calls is currently not supported'
);
......
......@@ -2,7 +2,6 @@
namespace Serenata\Analysis\Node;
use LogicException;
use UnexpectedValueException;
use Serenata\Analysis\ClasslikeInfoBuilderInterface;
......@@ -57,12 +56,7 @@ final class MethodCallMethodInfoRetriever
*/
public function retrieve(Node\Expr $node, TextDocumentItem $textDocumentItem, Position $position): array
{
if (!$node instanceof Node\Expr\MethodCall &&
!$node instanceof Node\Expr\StaticCall &&
!$node instanceof Node\Expr\New_
) {
throw new LogicException('Expected method call node, got ' . get_class($node) . ' instead');
} elseif ($node instanceof Node\Expr\New_) {
if ($node instanceof Node\Expr\New_) {
if ($node->class instanceof Node\Expr) {
// Can't currently deduce type of an expression such as "$this->{$foo}()";
throw new UnexpectedValueException('Can\'t determine information of dynamic method call');
......
......@@ -2,7 +2,6 @@
namespace Serenata\Analysis\Node;
use LogicException;
use UnexpectedValueException;
use PhpParser\Node;
......@@ -58,8 +57,6 @@ final class PropertyFetchPropertyInfoRetriever
if ($node->name instanceof Node\Expr) {
// Can't currently deduce type of an expression such as "$this->{$foo}";
throw new UnexpectedValueException('Can\'t determine information of dynamic property fetch');
} elseif (!$node instanceof Node\Expr\PropertyFetch && !$node instanceof Node\Expr\StaticPropertyFetch) {
throw new LogicException('Expected property fetch node, got ' . get_class($node) . ' instead');
}
$objectNode = ($node instanceof Node\Expr\PropertyFetch) ? $node->var : $node->class;
......
......@@ -23,7 +23,7 @@ final class InheritanceResolver extends AbstractResolver
if ($class['longDescription'] === '' || $class['longDescription'] === null) {
$class['longDescription'] = $parent['longDescription'];
} elseif ($class['longDescription'] !== null && $parent['longDescription'] !== null) {
} elseif ($parent['longDescription'] !== null) {
$class['longDescription'] = $this->resolveInheritDoc($class['longDescription'], $parent['longDescription']);
}
......
......@@ -94,7 +94,7 @@ final class NameNodeTypeDeducer extends AbstractNodeTypeDeducer
$classInfo = $this->classlikeInfoBuilder->build($currentClassName);
if ($classInfo === null || count($classInfo['parents']) === 0) {
if (count($classInfo['parents']) === 0) {
return [];
}
......
......@@ -481,7 +481,7 @@ final class TypeQueryingVisitor extends NodeVisitorAbstract
{
$docblock = $node->getDocComment();
if ($docblock === null || $docblock === '') {
if ($docblock === null) {
return;
}
......
......@@ -53,13 +53,16 @@ final class NonStaticMethodAutocompletionApplicabilityChecker implements Autocom
in_array($node->class->toString(), ['self', 'parent'], true)
) {
return true;
} elseif ($node instanceof Node\Expr\StaticPropertyFetch &&
!$node->name instanceof Node\VarLikeIdentifier &&
!$node->name instanceof Node\Expr &&
$node->class instanceof Node\Name &&
in_array($node->class->toString(), ['self', 'parent'], true)
) {
return true;
} elseif ($node instanceof Node\Expr\StaticPropertyFetch) {
/** @var Node $name To fix PHPStan error, because this can also be an error node. */
$name = $node->name;
if (!$name instanceof Node\VarLikeIdentifier &&
!$name instanceof Node\Expr &&
$node->class instanceof Node\Name &&
in_array($node->class->toString(), ['self', 'parent'], true)) {
return true;
}
} elseif ($node instanceof Node\Expr\ClassConstFetch &&
$node->class instanceof Node\Name &&
in_array($node->class->toString(), ['self', 'parent'], true)
......
......@@ -51,11 +51,13 @@ final class StaticMethodAutocompletionApplicabilityChecker implements Autocomple
!$node->name instanceof Node\Expr
) {
return true;
} elseif ($node instanceof Node\Expr\StaticPropertyFetch &&
!$node->name instanceof Node\VarLikeIdentifier &&
!$node->name instanceof Node\Expr
) {
return true;
} elseif ($node instanceof Node\Expr\StaticPropertyFetch) {
/** @var Node $name To fix PHPStan error, because this can also be an error node. */
$name = $node->name;
if (!$name instanceof Node\VarLikeIdentifier && !$name instanceof Node\Expr) {
return true;
}
}
return
......
......@@ -90,9 +90,9 @@ final class LevenshteinApproximateStringMatcher implements ApproximateStringMatc
* @param string $approximation
* @param string $referenceText
*
* @return float|null
* @return int|null
*/
private function calculateFuzzyMatchScore(string $approximation, string $referenceText): ?float
private function calculateFuzzyMatchScore(string $approximation, string $referenceText): ?int
{
$score = @levenshtein(
$referenceText,
......
......@@ -24,7 +24,7 @@ error_reporting(E_ALL & ~E_DEPRECATED);
// This limit can pose a problem for NameResolver built-in to php-parser (it can go over a nesting level of 300 in e.g.
// a Symfony2 code base). Also, -1 as a value doesn't work in some setups, see also:
// https://github.com/Gert-dev/php-ide-serenata/issues/91
ini_set('xdebug.max_nesting_level', 10000);
ini_set('xdebug.max_nesting_level', '10000');
// Disable circular reference collection in the garbage collection. Note that this doesn't actually disable the entire
// garbage collector, but just the (automatic) circular reference collection.
......
......@@ -4,6 +4,8 @@ namespace Serenata\Indexing;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaTool;
use Serenata\Indexing\Structures\AccessModifierNameValue;
......@@ -43,6 +45,8 @@ final class SchemaInitializer
{
$entityManager = $this->managerRegistry->getManager();
assert($entityManager instanceof EntityManagerInterface);
$schemaTool = new SchemaTool($entityManager);
// $schemaTool->dropDatabase();
......
......@@ -2,8 +2,6 @@
namespace Serenata\Indexing\Structures;
use DomainException;
use Serenata\Common\Range;
use Doctrine\Common\Collections\ArrayCollection;
......@@ -144,10 +142,6 @@ class Trait_ extends Classlike
*/
public function addTraitUser(Classlike $classlike): void
{
if (!$classlike instanceof Class_ && !$classlike instanceof Trait_) {
throw new DomainException('Only classes and other traits can use traits');
}
if ($this->isAddingTraitUser) {
return; // Don't loop infinitely whilst maintaining bidirectional association.
}
......
......@@ -430,8 +430,12 @@ final class ClasslikeIndexingVisitor extends NodeVisitorAbstract
private function processClassLikeRelations(Node\Stmt\ClassLike $node, Structures\Classlike $classlike): void
{
if ($classlike instanceof Structures\Class_) {
assert($node instanceof Node\Stmt\Class_);
$this->processClassRelations($node, $classlike);
} elseif ($classlike instanceof Structures\Interface_) {
assert($node instanceof Node\Stmt\Interface_);
$this->processInterfaceRelations($node, $classlike);
} elseif ($classlike instanceof Structures\Trait_) {
// Traits can't have relations.
......@@ -563,7 +567,7 @@ final class ClasslikeIndexingVisitor extends NodeVisitorAbstract
$adaptation->method,
$adaptation->newName
);
} elseif ($classlike instanceof Structures\Trait_) {
} else /*if ($classlike instanceof Structures\Trait_)*/ {
$traitAlias = new Structures\TraitTraitAlias(
$classlike,
$traitFqcn,
......@@ -571,8 +575,6 @@ final class ClasslikeIndexingVisitor extends NodeVisitorAbstract
$adaptation->method,
$adaptation->newName
);
} else {
continue; // Can't add trait aliases in any other classlike type.
}
$this->storage->persist($traitAlias);
......@@ -586,14 +588,12 @@ final class ClasslikeIndexingVisitor extends NodeVisitorAbstract
$traitFqcn,
$adaptation->method
);
} elseif ($classlike instanceof Structures\Trait_) {
} else /*if ($classlike instanceof Structures\Trait_)*/ {
$traitPrecedence = new Structures\TraitTraitPrecedence(
$classlike,
$traitFqcn,
$adaptation->method
);
} else {
continue; // Can't add trait precedences in any other classlike type.
}
$this->storage->persist($traitPrecedence);
......@@ -677,7 +677,7 @@ final class ClasslikeIndexingVisitor extends NodeVisitorAbstract
if ($node->type instanceof Node\NullableType) {
$typeStringSpecification .= '|null';
}
} elseif ($property->default !== '' && $property->default !== null) {
} elseif ($property->default !== null) {
$typeList = $this->nodeTypeDeducer->deduce(new TypeDeductionContext(
$property->default,
$this->textDocumentItem
......@@ -777,7 +777,7 @@ final class ClasslikeIndexingVisitor extends NodeVisitorAbstract
$typeStringSpecification = null;
if ($documentation !== null && $documentation['return'] !== null && $documentation['return']['type'] !== null) {
if ($documentation['return'] !== null && $documentation['return']['type'] !== null) {
$typeStringSpecification = $documentation['return']['type'];
} elseif ($node->getReturnType() !== null) {
$nodeType = $node->getReturnType();
......@@ -1060,7 +1060,7 @@ final class ClasslikeIndexingVisitor extends NodeVisitorAbstract
$this->file,
$range,
$defaultValue,
$documentation['deprecated'] ? 1 : 0,
$documentation['deprecated'],
$docComment !== '' && $docComment !== null,
$shortDescription !== '' ? $shortDescription : null,
((bool) $documentation['descriptions']['long']) ? $documentation['descriptions']['long'] : null,
......
......@@ -169,7 +169,7 @@ final class FunctionIndexingVisitor extends NodeVisitorAbstract
$typeStringSpecification = null;
if ($documentation !== null && $documentation['return'] !== null && $documentation['return']['type'] !== null) {
if ($documentation['return'] !== null && $documentation['return']['type'] !== null) {
$typeStringSpecification = $documentation['return']['type'];
} elseif ($node->getReturnType() !== null) {
$nodeType = $node->getReturnType();
......
......@@ -558,9 +558,7 @@ final class DocblockParser
'description' => trim($varName . ' ' . $varDescription),
];
}
} elseif (($varName === null || $varName === '') &&
($varDescription === null || $varDescription === '')
) {
} elseif ($varDescription === null || $varDescription === '') {
// Example: "@var DateTime".
$vars['$' . $itemName] = [
'type' => $type,
......
......@@ -29,7 +29,7 @@ use Serenata\Parsing\Node\Keyword\Static_;
final class PartialParser implements Parser
{
/**
* @var Parser
* @var Parser|null
*/
private $strictParser;
......@@ -339,8 +339,6 @@ final class PartialParser implements Parser
} catch (Error $e) {
return null;
}
return null;
}
/**
......@@ -348,7 +346,7 @@ final class PartialParser implements Parser
*/
private function getStrictParser(): Parser
{
if (!$this->strictParser instanceof Parser) {
if ($this->strictParser === null) {
$this->strictParser = $this->parserFactory->create(ParserFactory::PREFER_PHP7, $this->lexer);
}
......
......@@ -294,7 +294,7 @@ final class JsonRpcConnectionHandler implements JsonRpcMessageSenderInterface
$contentLength = trim($contentLength);
if ($contentLength === null || $contentLength === '' || !is_numeric($contentLength)) {
if ($contentLength === '' || !is_numeric($contentLength)) {
throw new RequestParsingException('Content of the Content-Length header is not a valid number');
}
......
......@@ -48,7 +48,7 @@ final class DidChangeWatchedFilesJsonRpcQueueItemHandler extends AbstractJsonRpc
{
$parameters = $queueItem->getRequest()->getParams();
if ($parameters === null || $parameters === '') {
if ($parameters === null || $parameters === []) {
throw new InvalidArgumentsException('Missing parameters for didChangeWatchedFiles request');
}
......
......@@ -51,7 +51,7 @@ final class DidSaveJsonRpcQueueItemHandler extends AbstractJsonRpcQueueItemHandl
{
$parameters = $queueItem->getRequest()->getParams();
if ($parameters === null || $parameters === '') {
if ($parameters === null || $parameters === []) {
throw new InvalidArgumentsException('Missing parameters for didChangeWatchedFiles request');
}
......
......@@ -47,7 +47,7 @@ final class ServerCapabilities implements JsonSerializable
private $implementationProvider;
/**
* @var array|bool|null
* @var array<string,mixed>|bool|null
*/
private $referencesProvider;
......@@ -72,7 +72,7 @@ final class ServerCapabilities implements JsonSerializable
private $codeActionProvider;
/**
* @var array|null
* @var array<string,mixed>|null
*/
private $codeLensProvider;
......@@ -117,7 +117,7 @@ final class ServerCapabilities implements JsonSerializable
private $executeCommandProvider;
/**
* @var array|null
* @var array<string,mixed>|null
*/
private $workspace;
......@@ -134,12 +134,12 @@ final class ServerCapabilities implements JsonSerializable
* @param bool|null $definitionProvider
* @param bool|object|null $typeDefinitionProvider
* @param bool|object|null $implementationProvider
* @param array|bool|null $referencesProvider
* @param array<string,mixed>|bool|null $referencesProvider
* @param bool|null $documentHighlightProvider
* @param bool|null $documentSymbolProvider
* @param bool|null $workspaceSymbolProvider
* @param bool|object|null $codeActionProvider
* @param array|null $codeLensProvider
* @param array<string,mixed>|null $codeLensProvider
* @param bool|null $documentFormattingProvider
* @param bool|null $documentRangeFormattingProvider
* @param object|null $documentOnTypeFormattingProvider
......@@ -148,7 +148,7 @@ final class ServerCapabilities implements JsonSerializable
* @param bool|object|null $colorProvider
* @param bool|object|null $foldingRangeProvider
* @param object|null $executeCommandProvider
* @param array|null $workspace
* @param array<string,mixed>|null $workspace
* @param mixed|null $experimental
*/
public function __construct(
......@@ -258,7 +258,7 @@ final class ServerCapabilities implements JsonSerializable
}
/**
* @return array|bool|null
* @return array<string,mixed>|bool|null
*/
public function getReferencesProvider()
{
......@@ -298,7 +298,7 @@ final class ServerCapabilities implements JsonSerializable
}
/**
* @return array|null
* @return array<string,mixed>|null
*/
public function getCodeLensProvider(): ?array
{
......@@ -370,7 +370,7 @@ final class ServerCapabilities implements JsonSerializable
}
/**
* @return array|null
* @return array<string,mixed>|null
*/
public function getWorkspace(): ?array
{
......
......@@ -8,6 +8,8 @@ use Serenata\Utility\ImmutableSet;
* Represents a list of (parameter, property, constant) types.
*
* This is a value object and immutable.
*
* @extends ImmutableSet<Type>
*/
final class TypeList extends ImmutableSet
{
......
......@@ -26,6 +26,8 @@ final class WorkspaceConfigurationJsonParser implements WorkspaceConfigurationPa
}
/**
* @param array<string,mixed> $configuration
*
* @throws WorkspaceConfigurationParsingException
*/
private function validate(array $configuration): void
......@@ -36,8 +38,8 @@ final class WorkspaceConfigurationJsonParser implements WorkspaceConfigurationPa
}
/**
* @param array $data
* @param string $key
* @param array<string, mixed> $data
* @param string $key
*/
private function expectKey(array $data, string $key): void
{
......
......@@ -10,7 +10,7 @@ use Serenata\Workspace\Configuration\WorkspaceConfiguration;
interface WorkspaceConfigurationParserInterface
{
/**
* @param array $configuration
* @param array<string,mixed> $configuration
*
* @throws WorkspaceConfigurationParsingException
*
......