1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Fix mixed operand issues

This commit is contained in:
Matthew Brown 2016-12-24 11:03:55 +00:00
parent c51d8f5220
commit 1007d1682c
8 changed files with 45 additions and 7 deletions

View File

@ -30,6 +30,12 @@
</excludeFiles>
</MixedArgument>
<MixedOperand>
<excludeFiles>
<directory name="tests" />
</excludeFiles>
</MixedOperand>
<MixedPropertyFetch>
<excludeFiles>
<directory name="tests" />

View File

@ -1166,8 +1166,8 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
if ($reflection_method->class !== $class_name) {
MethodChecker::setDeclaringMethodId(
$class_name . '::' . strtolower((string)$reflection_method->name),
$reflection_method->class . '::' . strtolower((string)$reflection_method->name)
$class_name . '::' . strtolower($reflection_method->name),
$reflection_method->class . '::' . strtolower($reflection_method->name)
);
self::$public_class_methods[$class_name][strtolower((string)$reflection_method->name)] = true;
@ -1388,7 +1388,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
/**
* @param string $method_name
* @return mixed
* @return string
*/
protected function getMappedMethodName($method_name)
{

View File

@ -26,7 +26,7 @@ class MethodChecker extends FunctionLikeChecker
protected static $method_files = [];
/**
* @var array<string,array<\Psalm\FunctionLikeParameter>>
* @var array<string,array<int, \Psalm\FunctionLikeParameter>>
*/
protected static $method_params = [];
@ -117,7 +117,7 @@ class MethodChecker extends FunctionLikeChecker
/**
* @param string $method_id
* @return array<\Psalm\FunctionLikeParameter>|null
* @return array<int, \Psalm\FunctionLikeParameter>|null
*/
public static function getMethodParams($method_id)
{

View File

@ -160,6 +160,7 @@ class Config
* @psalm-suppress MixedPropertyFetch
* @psalm-suppress MixedMethodCall
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedOperand
*/
public static function loadFromXML($file_name)
{
@ -329,6 +330,7 @@ class Config
* @throws ConfigException If a Config file could not be found.
* @psalm-suppress MixedArrayAccess
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedOperand
*/
protected function loadFileExtensions($extensions)
{
@ -337,7 +339,7 @@ class Config
$this->file_extensions[] = $extension_name;
if (isset($extension['filetypeHandler'])) {
$path = $this->base_dir . $extension['filetypeHandler'];
$path = $this->base_dir . (string)$extension['filetypeHandler'];
if (!file_exists($path)) {
throw new Exception\ConfigException('Error parsing config: cannot find file ' . $path);

View File

@ -178,7 +178,7 @@ class IssueBuffer
Checker\FileChecker::updateReferenceCache();
if ($debug) {
echo('Checks took ' . (microtime(true) - self::$start_time));
echo('Checks took ' . ((float)microtime(true) - self::$start_time));
echo(' and used ' . memory_get_peak_usage() . PHP_EOL);
}

View File

@ -384,6 +384,16 @@ return [
'file' => 'string',
'line' => 'int'
],
'reflectionclass' => [
'name' => 'string'
],
'reflectionmethod' => [
'class' => 'string',
'name' => 'string'
],
'reflectionparameter' => [
'name' => 'string'
],
'phpparser\\node\\expr' => [
'inferredType' => 'Psalm\\Type\\Union|null'
],

View File

@ -37,6 +37,8 @@ class ObjectLike extends Atomic
', ',
array_map(
/**
* @param string $name
* @param string $type
* @return string
*/
function ($name, $type) {
@ -67,6 +69,8 @@ class ObjectLike extends Atomic
', ',
array_map(
/**
* @param string $name
* @param Union $type
* @return string
*/
function ($name, Union $type) use ($aliased_classes, $this_class, $use_phpdoc_format) {

View File

@ -383,4 +383,20 @@ class PropertyTypeTest extends PHPUnit_Framework_TestCase
$context = new Context('somefile.php');
$file_checker->check(true, true, $context);
}
public function testReflectionProperties()
{
$stmts = self::$parser->parse('<?php
class Foo {
}
$a = new \ReflectionMethod("Foo", "__construct");
echo $a->name . " - " . $a->class;
');
$file_checker = new FileChecker('somefile.php', $stmts);
$context = new Context('somefile.php');
$file_checker->check(true, true, $context);
}
}