...
 
Commits (3)
......@@ -65,7 +65,7 @@ test:run-phpstan:
script:
# TODO: Enable when all the existing errors have been fixed (https://gitlab.com/Serenata/Serenata/issues/277).
# - php -d memory_limit=2048M vendor/bin/phpstan analyse --level=max --no-interaction --no-progress --error-format junit src > ./phpstan-report.xml
- php -d memory_limit=2048M vendor/bin/phpstan analyse --level=1 --no-interaction --no-progress --error-format junit src > ./phpstan-report.xml
- php -d memory_limit=2048M vendor/bin/phpstan analyse --level=2 --no-interaction --no-progress --error-format junit src > ./phpstan-report.xml
artifacts:
when: always
expire_in: 1 hrs
......
......@@ -142,7 +142,7 @@ use Serenata\Indexing\StorageInterface;
{
$classlike = $this->storage->findStructureByFqcn($fqcn);
if (!$classlike) {
if ($classlike === null) {
throw new UnexpectedValueException('The structural element "' . $fqcn . '" was not found!');
}
......
......@@ -13,7 +13,7 @@ final class ConstantListRegistry implements ConstantListProviderInterface
private $delegate;
/**
* @var array
* @var array|null
*/
private $registry;
......
......@@ -35,13 +35,13 @@ final class ClasslikeConstantConverter
public function convertForClass(Structures\ClassConstant $constant, ArrayAccess $class): array
{
return array_merge($this->constantConverter->convert($constant), [
'isPublic' => $constant->getAccessModifier() ?
'isPublic' => $constant->getAccessModifier() !== null ?
$constant->getAccessModifier()->getName() === AccessModifierNameValue::PUBLIC_ : true,
'isProtected' => $constant->getAccessModifier() ?
'isProtected' => $constant->getAccessModifier() !== null ?
$constant->getAccessModifier()->getName() === AccessModifierNameValue::PROTECTED_ : false,
'isPrivate' => $constant->getAccessModifier() ?
'isPrivate' => $constant->getAccessModifier() !== null ?
$constant->getAccessModifier()->getName() === AccessModifierNameValue::PRIVATE_ : false,
'declaringClass' => [
......
......@@ -28,8 +28,8 @@ final class DoctrineClasslikeExistenceChecker implements ClasslikeExistenceCheck
*/
public function doesClassExist(string $fqcn): bool
{
return !!$this->managerRegistry->getRepository(Structures\Classlike::class)->findOneBy([
return $this->managerRegistry->getRepository(Structures\Classlike::class)->findOneBy([
'fqcn' => $fqcn,
]);
]) !== null;
}
}
......@@ -30,8 +30,8 @@ final class DoctrineGlobalConstantExistenceChecker implements ConstantPresenceIn
*/
public function isPresent(string $fullyQualifiedName): bool
{
return !!$this->managerRegistry->getRepository(Structures\Constant::class)->findOneBy([
return $this->managerRegistry->getRepository(Structures\Constant::class)->findOneBy([
'fqcn' => $fullyQualifiedName,
]);
]) !== null;
}
}
......@@ -30,8 +30,8 @@ final class DoctrineGlobalFunctionExistenceChecker implements FunctionPresenceIn
*/
public function isPresent(string $fullyQualifiedName): bool
{
return !!$this->managerRegistry->getRepository(Structures\Function_::class)->findOneBy([
return $this->managerRegistry->getRepository(Structures\Function_::class)->findOneBy([
'fqcn' => $fullyQualifiedName,
]);
]) !== null;
}
}
......@@ -13,7 +13,7 @@ final class FunctionListRegistry implements FunctionListProviderInterface
private $delegate;
/**
* @var array
* @var array|null
*/
private $registry;
......
......@@ -13,7 +13,7 @@ final class NamespaceListRegistry implements NamespaceListProviderInterface
private $delegate;
/**
* @var array
* @var array|null
*/
private $registry;
......
......@@ -39,7 +39,7 @@ final class TraitUsageResolver extends AbstractResolver
) {
$method['name'] = $traitAlias->getAlias() !== null ? $traitAlias->getAlias() : $method['name'];
if ($traitAlias->getAccessModifier()) {
if ($traitAlias->getAccessModifier() !== null) {
$method['isPublic'] =
($traitAlias->getAccessModifier()->getName() === AccessModifierNameValue::PUBLIC_);
......
......@@ -25,7 +25,7 @@ final class ConfigurableDelegatingNodeTypeDeducer extends AbstractNodeTypeDeduce
*/
public function deduce(TypeDeductionContext $context): array
{
if (!$this->nodeTypeDeducer) {
if ($this->nodeTypeDeducer === null) {
throw new TypeDeductionException('No node type deducer to delegate to configured!');
}
......
......@@ -79,7 +79,7 @@ final class ConstFetchNodeTypeDeducer extends AbstractNodeTypeDeducer
'fqcn' => $fqsen,
]);
if (!$globalConstant) {
if ($globalConstant === null) {
return [];
}
......
......@@ -153,6 +153,8 @@ final class ExpressionTypeDeducer
public function enterNode(Node $node)
{
$node->setAttribute('namespace', $this->namespaceNode);
return null;
}
});
......
......@@ -68,7 +68,7 @@ final class FuncCallNodeTypeDeducer extends AbstractNodeTypeDeducer
'fqcn' => $fqsen,
]);
if (!$globalFunction) {
if ($globalFunction === null) {
return [];
}
......
......@@ -59,7 +59,7 @@ final class FunctionLikeParameterTypeDeducer extends AbstractNodeTypeDeducer
$docBlock = $this->getFunctionDocblock();
if ($docBlock) {
if ($docBlock !== null && $docBlock !== '') {
// Analyze the docblock's @param tags.
$result = $this->docblockParser->parse($docBlock, [
DocblockParser::PARAM_TYPE,
......
......@@ -88,13 +88,13 @@ final class NameNodeTypeDeducer extends AbstractNodeTypeDeducer
$context->getPosition()
);
if (!$currentClassName) {
if ($currentClassName === null) {
return [];
}
$classInfo = $this->classlikeInfoBuilder->build($currentClassName);
if (!$classInfo || count($classInfo['parents']) === 0) {
if ($classInfo === null || count($classInfo['parents']) === 0) {
return [];
}
......
......@@ -64,7 +64,7 @@ final class TypeDeductionContext
*/
public function getPosition(): Position
{
if (!$this->position) {
if ($this->position === null) {
if ($this->getNode()->getAttribute('startFilePos') === null) {
throw new LogicException('No startFilePos attribute attached to node');
}
......
......@@ -71,7 +71,7 @@ final class TypeAnalyzer implements TypeNormalizerInterface
*/
public function getNormalizedFqcn(string $fqcn): string
{
if ($fqcn && $fqcn[0] !== '\\') {
if ($fqcn !== '' && $fqcn[0] !== '\\') {
return '\\' . $fqcn;
}
......
......@@ -86,6 +86,8 @@ final class VariableScanningVisitor extends NodeVisitorAbstract
} elseif ($node instanceof Node\Param) {
$this->parseParam($node);
}
return null;
}
/**
......
......@@ -36,12 +36,14 @@ final class FunctionLikeBodyOffsetAttachingVisitor extends NodeVisitorAbstract
if ($node instanceof Node\FunctionLike) {
if ($node->getStmts() === null) {
return; // Skip methods without a body (e.g. interface or abstract ones).
return null; // Skip methods without a body (e.g. interface or abstract ones).
}
$node->setAttribute('bodyStartFilePos', $this->locateBodyStartByteOffset($node));
$node->setAttribute('bodyEndFilePos', $this->locateBodyEndByteOffset($node));
}
return null;
}
/**
......
......@@ -29,5 +29,7 @@ final class NamespaceAttachingVisitor extends NameResolver
parent::enterNode($node);
$node->setAttribute('namespace', $this->nameContext->getNamespace());
return null;
}
}
......@@ -76,6 +76,8 @@ final class NodeFetchingVisitor extends NodeVisitorAbstract
if (!$node instanceof Node\Name && !$node instanceof Node\Identifier) {
$this->mostInterestingNode = $node;
}
return null;
}
/**
......
......@@ -35,6 +35,8 @@ final class ParentAttachingVisitor extends NodeVisitorAbstract
$node->setAttribute('parent', $this->stack->isEmpty() ? null : $this->stack->top());
$this->stack->push($node);
return null;
}
/**
......@@ -45,5 +47,7 @@ final class ParentAttachingVisitor extends NodeVisitorAbstract
parent::leaveNode($node);
$this->stack->pop();
return null;
}
}
......@@ -93,7 +93,7 @@ final class ScopeLimitingVisitor extends NodeVisitorAbstract
}
}
if ($node->else && $node->else->getAttribute('startFilePos') < $this->byteOffset) {
if ($node->else !== null && $node->else->getAttribute('startFilePos') < $this->byteOffset) {
$this->memorizeNodeProperties($node, ['stmts', 'elseifs', 'cond']);
$node->stmts = [];
......@@ -133,7 +133,7 @@ final class ScopeLimitingVisitor extends NodeVisitorAbstract
// Finally statements have no own node, so use the first statement as a reference point instead. This
// won't be entirely correct, but it's the best we can do. See also
// https://github.com/nikic/PHP-Parser/issues/254
if ($node->finally && $node->finally->getAttribute('startFilePos') < $this->byteOffset) {
if ($node->finally !== null && $node->finally->getAttribute('startFilePos') < $this->byteOffset) {
$this->memorizeNodeProperties($node, ['stmts', 'catches']);
$node->stmts = [];
......@@ -141,6 +141,8 @@ final class ScopeLimitingVisitor extends NodeVisitorAbstract
}
}
}
return null;
}
/**
......@@ -149,6 +151,8 @@ final class ScopeLimitingVisitor extends NodeVisitorAbstract
public function leaveNode(Node $node)
{
$this->restoreNodeProperties($node);
return null;
}
/**
......
......@@ -101,6 +101,8 @@ final class TypeQueryingVisitor extends NodeVisitorAbstract
}
$this->checkForScopeChange($node);
return null;
}
/**
......@@ -263,7 +265,7 @@ final class TypeQueryingVisitor extends NodeVisitorAbstract
/**
* @param Node\Expr\BinaryOp $node
* @param TypePossibilityMap[] &$types
* @param TypePossibilityMap[] $types
*
* @return void
*/
......@@ -287,7 +289,7 @@ final class TypeQueryingVisitor extends NodeVisitorAbstract
/**
* @param Node\Expr\BinaryOp\Equal|Node\Expr\BinaryOp\Identical $node
* @param TypePossibilityMap[] &$types
* @param TypePossibilityMap[] $types
*
* @return void
*/
......@@ -310,7 +312,7 @@ final class TypeQueryingVisitor extends NodeVisitorAbstract
/**
* @param Node\Expr\BinaryOp\NotEqual|Node\Expr\BinaryOp\NotIdentical $node
* @param TypePossibilityMap[] &$types
* @param TypePossibilityMap[] $types
*
* @return void
*/
......@@ -333,7 +335,7 @@ final class TypeQueryingVisitor extends NodeVisitorAbstract
/**
* @param Node\Expr $node
* @param TypePossibilityMap[] &$types
* @param TypePossibilityMap[] $types
*
* @return void
*/
......@@ -346,7 +348,7 @@ final class TypeQueryingVisitor extends NodeVisitorAbstract
/**
* @param Node\Expr\BooleanNot $node
* @param TypePossibilityMap[] &$types
* @param TypePossibilityMap[] $types
*
* @return void
*/
......@@ -378,7 +380,7 @@ final class TypeQueryingVisitor extends NodeVisitorAbstract
/**
* @param Node\Expr\Instanceof_ $node
* @param TypePossibilityMap[] &$types
* @param TypePossibilityMap[] $types
*
* @return void
*/
......@@ -403,7 +405,7 @@ final class TypeQueryingVisitor extends NodeVisitorAbstract
/**
* @param Node\Expr\FuncCall $node
* @param TypePossibilityMap[] &$types
* @param TypePossibilityMap[] $types
*
* @return void
*/
......@@ -450,7 +452,7 @@ final class TypeQueryingVisitor extends NodeVisitorAbstract
}
/**
* @param TypePossibilityMap[] &$types
* @param TypePossibilityMap[] $types
* @param string $expression
* @param string $type
* @param int $possibility
......@@ -479,7 +481,7 @@ final class TypeQueryingVisitor extends NodeVisitorAbstract
{
$docblock = $node->getDocComment();
if (!$docblock) {
if ($docblock === null || $docblock === '') {
return;
}
......
......@@ -70,6 +70,8 @@ final class UseStatementFetchingVisitor extends NodeVisitorAbstract
// $node->getAttribute('endLine') + 1
// );
// }
return null;
}
/**
......@@ -83,6 +85,8 @@ final class UseStatementFetchingVisitor extends NodeVisitorAbstract
new Position(mb_substr_count($this->code, "\n") + 1, 0)
);
}
return null;
}
/**
......@@ -106,7 +110,7 @@ final class UseStatementFetchingVisitor extends NodeVisitorAbstract
);
$this->namespaces[++$this->lastNamespaceIndex] = [
'name' => $node->name ? (string) $node->name : null,
'name' => $node->name !== null ? (string) $node->name : null,
'range' => new Range(
Position::createFromByteOffset(
$node->getAttribute('startFilePos'),
......
......@@ -2,23 +2,22 @@
namespace Serenata\Autocompletion\ApproximateStringMatching;
use ArrayAccess;
/**
* Interface for classes that perform string approximation on a list of items and return only the best result(s).
*/
interface BestStringApproximationDeterminerInterface
{
/**
* @param iterable $items Iterable of items (nested associative arrays or objects implementing ArrayAccess)
* @param iterable<T> $items Iterable of items (nested associative arrays or objects implementing ArrayAccess)
* that are to be evaluated.
* @param string $referenceText The text to determine the approximation to for each result.
* @param string $itemValueKey The key to search for in each item and to use for the approximation.
* @param int|null $limit The optional maximum amount of items to return. Lowering this value may improve
* performance.
*
* @return (array|ArrayAccess)[] The same list of items received as input, but filtered and sorted due to the
* approximation.
* @return T[] The same list of items received as input, but filtered and sorted due to the approximation.
*
* @template T
*/
public function determine(iterable $items, string $referenceText, string $itemValueKey, ?int $limit);
}
......@@ -20,8 +20,8 @@ final class CompletionItemDetailFormatter
{
return implode(' — ', array_filter([
$this->formatTypes($typeArrayList),
$accessModifierName ? $this->formatAccessModifier($accessModifierName) : null,
$declaringStructureFqcn ? $this->formatDeclaringStructure($declaringStructureFqcn) : null,
$accessModifierName !== null ? $this->formatAccessModifier($accessModifierName) : null,
$declaringStructureFqcn !== null ? $this->formatDeclaringStructure($declaringStructureFqcn) : null,
]));
}
......
......@@ -140,7 +140,7 @@ final class DefinitionLocator
$node = $result->getNode();
$nearestInterestingNode = $result->getNearestInterestingNode();
if (!$node) {
if ($node === null) {
throw new UnexpectedValueException(
'No node found at location ' . $position->getLine() . ':' . $position->getCharacter()
);
......
......@@ -61,18 +61,20 @@ final class DocumentHighlightsVisitor extends NodeVisitorAbstract
$nodeFqcn = $this->findFqcnForNode($node);
if ($nodeFqcn === null) {
return;
return null;
}
$referenceFqcn = $this->findFqcnForNode($this->referenceNode);
if ($referenceFqcn === null) {
return;
return null;
}
if ($nodeFqcn === $referenceFqcn) {
$this->pushHighlight($node);
}
return null;
}
/**
......
......@@ -32,7 +32,7 @@ final class ModificationTimeFilterIterator extends FilterIterator
/**
* @inheritDoc
*/
public function accept()
public function accept(): bool
{
/** @var SplFileInfo $value */
$value = $this->current();
......
......@@ -10,7 +10,7 @@ use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\EntityManager;
......@@ -38,12 +38,12 @@ final class ManagerRegistry extends AbstractManagerRegistry implements EventEmit
private $cache;
/**
* @var Connection
* @var Connection|null
*/
private $connection;
/**
* @var EntityManager
* @var EntityManager|null
*/
private $entityManager;
......@@ -81,7 +81,10 @@ final class ManagerRegistry extends AbstractManagerRegistry implements EventEmit
protected function getService($name)
{
if ($name === 'defaultConnection') {
return $this->getConnectionInstance();
/** @var EntityManager $connection Because overridden method docblock return type is incorrect. */
$connection = $this->getConnectionInstance();
return $connection;
} elseif ($name === 'defaultEntityManager') {
return $this->getEntityManagerInstance();
}
......
......@@ -2,6 +2,8 @@
namespace Serenata\Indexing\Structures;
use Doctrine\Common\Collections\ArrayCollection;
use Serenata\Common\Range;
use Serenata\DocblockTypeParser\DocblockType;
......@@ -67,7 +69,7 @@ abstract class FunctionLike
protected $throws;
/**
* @var FunctionLikeParameter[]
* @var ArrayCollection<int,FunctionLikeParameter>
*/
protected $parameters;
......
......@@ -34,7 +34,7 @@ class Function_ extends FunctionLike
* @param string|null $returnDescription
* @param string|null $returnTypeHint
* @param bool $hasDocblock
* @param array[] $throws
* @param ThrowsInfo[] $throws
* @param DocblockType $returnType
*/
public function __construct(
......
......@@ -61,7 +61,7 @@ class Method extends FunctionLike
* @param bool $isAbstract
* @param bool $isFinal
* @param bool $hasDocblock
* @param array[] $throws
* @param ThrowsInfo[] $throws
* @param DocblockType $returnType
*/
public function __construct(
......
......@@ -18,6 +18,7 @@ final class ClassLikeBodySkippingVisitor implements NodeVisitor
*/
public function beforeTraverse(array $nodes)
{
return null;
}
/**
......@@ -28,6 +29,8 @@ final class ClassLikeBodySkippingVisitor implements NodeVisitor
if ($node instanceof Node\Stmt\ClassLike) {
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
}
return null;
}
/**
......@@ -35,6 +38,7 @@ final class ClassLikeBodySkippingVisitor implements NodeVisitor
*/
public function leaveNode(Node $node)
{
return null;
}
/**
......@@ -42,5 +46,6 @@ final class ClassLikeBodySkippingVisitor implements NodeVisitor
*/
public function afterTraverse(array $nodes)
{
return null;
}
}
......@@ -102,6 +102,8 @@ final class ConstantIndexingVisitor extends NodeVisitorAbstract
$this->storage->delete($constant);
}
return null;
}
/**
......@@ -112,6 +114,8 @@ final class ConstantIndexingVisitor extends NodeVisitorAbstract
if ($node instanceof Node\Stmt\Const_) {
$this->parseConstantStatementNode($node);
}
return null;
}
/**
......@@ -134,7 +138,7 @@ final class ConstantIndexingVisitor extends NodeVisitorAbstract
*/
private function indexConstant(Node\Const_ $node, Node\Stmt\Const_ $const): void
{
$docComment = $const->getDocComment() ? $const->getDocComment()->getText() : null;
$docComment = $const->getDocComment() !== null ? $const->getDocComment()->getText() : null;
$documentation = $this->docblockParser->parse($docComment, [
DocblockParser::VAR_TYPE,
......
......@@ -97,6 +97,8 @@ final class DefineIndexingVisitor extends NodeVisitorAbstract
) {
$this->parseDefineNode($node);
}
return null;
}
/**
......
......@@ -105,6 +105,8 @@ final class FunctionIndexingVisitor extends NodeVisitorAbstract
$this->storage->delete($function);
}
return null;
}
/**
......@@ -115,6 +117,8 @@ final class FunctionIndexingVisitor extends NodeVisitorAbstract
if ($node instanceof Node\Stmt\Function_) {
$this->indexFunction($node);
}
return null;
}
/**
......@@ -124,7 +128,7 @@ final class FunctionIndexingVisitor extends NodeVisitorAbstract
*/
private function indexFunction(Node\Stmt\Function_ $node): void
{
$docComment = $node->getDocComment() ? $node->getDocComment()->getText() : null;
$docComment = $node->getDocComment() !== null ? $node->getDocComment()->getText() : null;
$returnTypeHint = null;
$nodeType = $node->getReturnType();
......@@ -165,9 +169,9 @@ final class FunctionIndexingVisitor extends NodeVisitorAbstract
$typeStringSpecification = null;
if ($documentation && $documentation['return'] !== null && $documentation['return']['type'] !== null) {
if ($documentation !== null && $documentation['return'] !== null && $documentation['return']['type'] !== null) {
$typeStringSpecification = $documentation['return']['type'];
} elseif ($node->getReturnType()) {
} elseif ($node->getReturnType() !== null) {
$nodeType = $node->getReturnType();
if ($nodeType instanceof Node\NullableType) {
......@@ -193,7 +197,7 @@ final class FunctionIndexingVisitor extends NodeVisitorAbstract
$docblockType = $this->docblockTypeParser->parse($typeStringSpecification);
$returnType = $this->typeResolvingDocblockTypeTransformer->resolve($docblockType, $filePosition);
} elseif ($docComment) {
} elseif ($docComment !== null) {
$returnType = new VoidDocblockType();
} else {
$returnType = new MixedDocblockType();
......@@ -254,7 +258,7 @@ final class FunctionIndexingVisitor extends NodeVisitorAbstract
($param->default instanceof Node\Expr\ConstFetch && $param->default->name->toString() === 'null')
);
$defaultValue = $param->default ?
$defaultValue = $param->default !== null ?
substr(
$this->textDocumentItem->getText(),
$param->default->getAttribute('startFilePos'),
......@@ -271,7 +275,7 @@ final class FunctionIndexingVisitor extends NodeVisitorAbstract
if ($parameterDoc) {
$typeStringSpecification = $parameterDoc['type'];
} elseif ($param->type) {
} elseif ($param->type !== null) {
$typeNode = $param->type;
if ($typeNode instanceof Node\NullableType) {
......@@ -322,7 +326,7 @@ final class FunctionIndexingVisitor extends NodeVisitorAbstract
$parameterDoc ? $parameterDoc['description'] : null,
$defaultValue,
$param->byRef,
!!$param->default,
$param->default !== null,
$param->variadic
);
......
......@@ -18,6 +18,7 @@ final class FunctionLikeBodySkippingVisitor implements NodeVisitor
*/
public function beforeTraverse(array $nodes)
{
return null;
}
/**
......@@ -28,6 +29,8 @@ final class FunctionLikeBodySkippingVisitor implements NodeVisitor
if ($node instanceof Node\FunctionLike) {
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
}
return null;
}
/**
......@@ -35,6 +38,7 @@ final class FunctionLikeBodySkippingVisitor implements NodeVisitor
*/
public function leaveNode(Node $node)
{
return null;
}
/**
......@@ -42,5 +46,6 @@ final class FunctionLikeBodySkippingVisitor implements NodeVisitor
*/
public function afterTraverse(array $nodes)
{
return null;
}
}
......@@ -49,6 +49,8 @@ final class MetaStaticMethodTypeIndexingVisitor extends NodeVisitorAbstract
$this->storage->delete($metaStaticMethodType);
}
return null;
}
/**
......@@ -59,7 +61,7 @@ final class MetaStaticMethodTypeIndexingVisitor extends NodeVisitorAbstract
$namespaceName = $node->getAttribute('namespace');
if (!$namespaceName instanceof Node\Name || $namespaceName->toString() !== 'PHPSTORM_META') {
return;
return null;
}
try {
......@@ -67,8 +69,10 @@ final class MetaStaticMethodTypeIndexingVisitor extends NodeVisitorAbstract
$this->enterAssignNode($node);
}
} catch (UnexpectedValueException $e) {
return;
return null;
}
return null;
}
/**
......
......@@ -55,6 +55,8 @@ final class UseStatementIndexingVisitor implements NodeVisitor
}
$this->useStatementFetchingVisitor->beforeTraverse($nodes);
return null;
}
/**
......@@ -63,6 +65,8 @@ final class UseStatementIndexingVisitor implements NodeVisitor
public function enterNode(Node $node)
{
$this->useStatementFetchingVisitor->enterNode($node);
return null;
}
/**
......@@ -71,6 +75,8 @@ final class UseStatementIndexingVisitor implements NodeVisitor
public function leaveNode(Node $node)
{
$this->useStatementFetchingVisitor->leaveNode($node);
return null;
}
/**
......@@ -83,6 +89,8 @@ final class UseStatementIndexingVisitor implements NodeVisitor
foreach ($this->useStatementFetchingVisitor->getNamespaces() as $namespace) {
$this->indexNamespace($namespace);
}
return null;
}
/**
......
......@@ -235,6 +235,8 @@ final class PartialParser implements Parser
$node->else = new Expr\Dummy();
}
}
return null;
}
});
......
......@@ -404,20 +404,25 @@ final class UseStatementInsertionCreator
): bool {
$useStatements = $this->retrieveRelevantUseStatements($textDocumentItem, $position);
/** @var Node\Stmt\Use_|Node\Stmt\GroupUse $useStatement */
return count(array_filter($useStatements, function (Node\Stmt $useStatement) use ($name, $kind): bool {
if ($this->getUseStatementNodeKind($useStatement) !== $kind) {
return false;
}
return count(array_filter(
$useStatements,
function (Node\Stmt $useStatement) use ($name, $kind): bool {
/** @var Node\Stmt\Use_|Node\Stmt\GroupUse $useStatement */
$useStatement = $useStatement;
foreach ($useStatement->uses as $useUseNode) {
if ($this->getFullNameFromUseUse($useStatement, $useUseNode) === $name) {
return true;
if ($this->getUseStatementNodeKind($useStatement) !== $kind) {
return false;
}
}
return false;
})) > 0;
foreach ($useStatement->uses as $useUseNode) {
if ($this->getFullNameFromUseUse($useStatement, $useUseNode) === $name) {
return true;
}
}
return false;
}
)) > 0;
}
/**
......
......@@ -294,10 +294,10 @@ final class JsonRpcConnectionHandler implements JsonRpcMessageSenderInterface
$contentLength = trim($contentLength);
if (!$contentLength || !is_numeric($contentLength)) {
if ($contentLength === null || $contentLength === '' || !is_numeric($contentLength)) {
throw new RequestParsingException('Content of the Content-Length header is not a valid number');
}
return $contentLength;
return (int) $contentLength;
}
}
......@@ -21,7 +21,7 @@ final class JsonRpcQueue
private $queue;
/**
* @var string[]
* @var array<string,bool>
*/
private $cancelledIds = [];
......
......@@ -146,7 +146,7 @@ final class TooltipProvider
$node = $result->getNode();
$nearestInterestingNode = $result->getNearestInterestingNode();
if (!$node) {
if ($node === null) {
throw new UnexpectedValueException(
'No node found at location ' . $position->getLine() . ':' . $position->getCharacter()
);
......
......@@ -154,7 +154,7 @@ final class JsonRpcApplication extends AbstractApplication implements JsonRpcReq
*/
private function uninstallPeriodicQueueProcessingTimer(): void
{
if ($this->periodicQueueProcessingTimer) {
if ($this->periodicQueueProcessingTimer !== null) {
/** @var LoopInterface $loop */
$loop = $this->getContainer()->get('eventLoop');
$loop->cancelTimer($this->periodicQueueProcessingTimer);
......
......@@ -43,7 +43,7 @@ final class DidChangeJsonRpcQueueItemHandler extends AbstractJsonRpcQueueItemHan
{
$parameters = $queueItem->getRequest()->getParams();
if (!$parameters) {
if ($parameters === null || $parameters === []) {
throw new InvalidArgumentsException('Missing parameters for didChangeWatchedFiles request');
}
......
......@@ -48,7 +48,7 @@ final class DidChangeWatchedFilesJsonRpcQueueItemHandler extends AbstractJsonRpc
{
$parameters = $queueItem->getRequest()->getParams();
if (!$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) {
if ($parameters === null || $parameters === '') {
throw new InvalidArgumentsException('Missing parameters for didChangeWatchedFiles request');
}
......
......@@ -43,7 +43,7 @@ namespace Serenata\Utility\Typing;
/**
* @param string $type
*
* @return static
* @return SpecialType|ClassType
*/
public static function createFromString(string $type)
{
......