Skip to content

Commit

Permalink
Merge pull request #544 from orklah/psalm-bump
Browse files Browse the repository at this point in the history
bump psalm, fix errors, add usePhpDocPropertiesWithoutMagicCall
  • Loading branch information
Ocramius committed Feb 18, 2020
2 parents 3e26b82 + 478fc7f commit 8c6538a
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 36 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"doctrine/coding-standard": "^7.0.2",
"phpstan/phpstan": "^0.12.8",
"phpunit/phpunit": "^8.5.2",
"vimeo/psalm": "^3.8.3"
"vimeo/psalm": "3.9.2"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.8.3@389af1bfc739bfdff3f9e3dc7bd6499aee51a831">
<files psalm-version="3.9.2@87d8947ff36d8b71f54b7e46b93384cf010681a0">
<file src="src/BetterReflection.php">
<DocblockTypeContradiction occurrences="1">
<code>$this-&gt;sourceStubber</code>
</DocblockTypeContradiction>
</file>
<file src="src/Reflection/Adapter/ReflectionClass.php">
<InvalidReturnType occurrences="1">
<code>getProperties</code>
</InvalidReturnType>
<MethodSignatureMismatch occurrences="5">
<code>public function getName()</code>
<code>public function getTraitNames()</code>
Expand All @@ -19,12 +22,14 @@
<code>$interface</code>
<code>$realInterfaceName</code>
</PossiblyInvalidArgument>
<RedundantCondition occurrences="2">
<RedundantCondition occurrences="1">
<code>is_object($argument)</code>
<code>is_string($argument) || is_object($argument)</code>
</RedundantCondition>
</file>
<file src="src/Reflection/Adapter/ReflectionObject.php">
<InvalidReturnType occurrences="1">
<code>getProperties</code>
</InvalidReturnType>
<MethodSignatureMismatch occurrences="5">
<code>public function getName()</code>
<code>public function getTraitNames()</code>
Expand All @@ -43,6 +48,10 @@
<PossiblyInvalidCast occurrences="1">
<code>$returnType</code>
</PossiblyInvalidCast>
<PossiblyNullPropertyAssignmentValue occurrences="2">
<code>$functionNode-&gt;getStmts()</code>
<code>$this-&gt;loadStaticParser()-&gt;parse('&lt;?php ' . $newBody)</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="src/Reflection/ReflectionMethod.php">
<InvalidStringClass occurrences="1">
Expand Down
11 changes: 1 addition & 10 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
errorBaseline="psalm-baseline.xml"
useDocblockTypes="true"
totallyTyped="false"
usePhpDocPropertiesWithoutMagicCall="true"
allowPhpStormGenerics="true"
>
<projectFiles>
Expand Down Expand Up @@ -66,26 +67,16 @@

<UndefinedPropertyAssignment>
<errorLevel type="suppress">
<referencedProperty name="PhpParser\Node\Stmt\ClassLike::$namespacedName" />
<referencedProperty name="PhpParser\Node\Param::$isOptional" />
</errorLevel>
</UndefinedPropertyAssignment>

<UndefinedPropertyFetch>
<errorLevel type="suppress">
<referencedProperty name="PhpParser\Node\Stmt\ClassLike::$namespacedName" />
<referencedProperty name="PhpParser\Node\Param::$isOptional" />
</errorLevel>
</UndefinedPropertyFetch>

<PossiblyNullPropertyAssignmentValue>
<errorLevel type="suppress">
<referencedProperty name="PhpParser\Node\Expr\Closure::$stmts" />
<referencedProperty name="PhpParser\Node\Stmt\Function_::$stmts" />
<referencedProperty name="PhpParser\Node\Stmt\ClassMethod::$stmts" />
</errorLevel>
</PossiblyNullPropertyAssignmentValue>

<InvalidScalarArgument>
<!-- Not actually an issue, we send scalar where the called method wait for bool|float|int|string. See vimeo/psalm/issues/2622 -->
<errorLevel type="suppress">
Expand Down
2 changes: 0 additions & 2 deletions src/NodeCompiler/Exception/UnableToCompileNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public static function becauseOfNotFoundConstantReference(
CompilerContext $fetchContext,
Node\Expr\ConstFetch $constantFetch
) : self {
assert($constantFetch->name instanceof Node\Name);

return new self(sprintf(
'Could not locate constant "%s" while evaluating expression in %s at line %s',
reset($constantFetch->name->parts),
Expand Down
3 changes: 2 additions & 1 deletion src/Reflection/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,6 @@ private function reflectClassForNamedNode(Node\Name $node) : self
// @TODO use actual `ClassReflector` or `FunctionReflector`?
if ($this->isAnonymous()) {
$class = (new BetterReflection())->classReflector()->reflect($node->toString());
assert($class instanceof self);
} else {
$class = $this->reflector->reflect($node->toString());
assert($class instanceof self);
Expand Down Expand Up @@ -1226,6 +1225,8 @@ private function getInheritanceClassHierarchy() : array
*
* @return ReflectionClass[] parent interfaces of this interface
*
* @psalm-return array<string, ReflectionClass>
*
* @throws NotAnInterfaceReflection
*/
private function getInterfacesHierarchy() : array
Expand Down
8 changes: 3 additions & 5 deletions src/Reflection/ReflectionFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ public function getClosure() : Closure
$this->assertFunctionExist($functionName);

return static function (...$args) use ($functionName) {
assert(is_callable($functionName));

return $functionName(...$args);
};
}
Expand Down Expand Up @@ -131,9 +129,7 @@ public function invokeArgs(array $args = [])
$functionName = $this->getName();

$this->assertFunctionExist($functionName);

assert(is_callable($functionName));


return $functionName(...$args);
}

Expand All @@ -149,6 +145,8 @@ private function assertIsNoClosure() : void

/**
* @throws FunctionDoesNotExist
*
* @psalm-assert callable-string $functionName
*/
private function assertFunctionExist(string $functionName) : void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Reflection/ReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public function getValue($object = null)

$instance = $this->assertObject($object);

return Closure::bind(function ($instance, string $propertyName) {
return Closure::bind(function (object $instance, string $propertyName) {
return $instance->{$propertyName};
}, $instance, $declaringClassName)->__invoke($instance, $this->getName());
}
Expand Down
1 change: 0 additions & 1 deletion src/Reflector/ClassReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function reflect(string $className) : Reflection
$identifier = new Identifier($className, new IdentifierType(IdentifierType::IDENTIFIER_CLASS));

$classInfo = $this->sourceLocator->locateIdentifier($this, $identifier);
assert($classInfo instanceof ReflectionClass || $classInfo === null);

if ($classInfo === null) {
throw Exception\IdentifierNotFound::fromIdentifier($identifier);
Expand Down
4 changes: 1 addition & 3 deletions src/TypesFinder/ResolveTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public function __invoke(array $stringTypes, Context $context) : array
$resolvedTypes = [];

foreach ($stringTypes as $stringType) {
$resolvedType = $this->typeResolver->resolve($stringType, $context);
assert($resolvedType instanceof Type);
$resolvedTypes[] = $resolvedType;
$resolvedTypes[] = $this->typeResolver->resolve($stringType, $context);
}

return $resolvedTypes;
Expand Down
6 changes: 5 additions & 1 deletion src/Util/GetFirstDocComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Comment\Doc;
use PhpParser\NodeAbstract;
use Webmozart\Assert\Assert;

/**
* @internal
Expand All @@ -16,7 +17,10 @@ public static function forNode(NodeAbstract $node) : string
{
foreach ($node->getComments() as $comment) {
if ($comment instanceof Doc) {
return $comment->getReformattedText();
$text = $comment->getReformattedText();
Assert::string($text);

return $text;
}
}

Expand Down

0 comments on commit 8c6538a

Please sign in to comment.