1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Support absolute files

This commit is contained in:
Matthew Brown 2016-06-28 14:28:45 -04:00
parent 71eea36b9c
commit 5b182fecea
4 changed files with 34 additions and 37 deletions

View File

@ -41,10 +41,9 @@ class ProjectChecker
{
$file_extensions = $config->getFileExtensions();
$filetype_handlers = $config->getFiletypeHandlers();
$base_dir = $config->getBaseDir();
/** @var RecursiveDirectoryIterator */
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($base_dir . $dir_name));
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir_name));
$iterator->rewind();
$files = [];
@ -85,18 +84,16 @@ class ProjectChecker
self::$config = self::getConfigForPath($file_name);
}
$base_dir = self::$config->getBaseDir();
$extension = array_pop(explode('.', $file_name));
$filetype_handlers = self::$config->getFiletypeHandlers();
if (isset($filetype_handlers[$extension])) {
/** @var FileChecker */
$file_checker = new $filetype_handlers[$extension]($base_dir . $file_name);
$file_checker = new $filetype_handlers[$extension]($file_name);
}
else {
$file_checker = new FileChecker($base_dir . $file_name);
$file_checker = new FileChecker($file_name);
}
$file_checker->check(true);

View File

@ -170,6 +170,7 @@ class ScopeChecker
if ($stmt instanceof PhpParser\Node\Stmt\Switch_) {
$has_returned = false;
$has_default_terminator = false;
// iterate backwards in a case statement
for ($i = count($stmt->cases) - 1; $i >= 0; $i--) {

View File

@ -12,9 +12,9 @@ abstract class Type
/**
* Parses a string type representation
* @param string $string
* @return self
* @return Union
*/
public static function parseString($type_string, $enclose_with_union = true)
public static function parseString($type_string)
{
if (strpos($type_string, '[') !== false) {
$type_string = TypeChecker::convertSquareBrackets($type_string);
@ -30,13 +30,7 @@ abstract class Type
$type_tokens[0] = 'int';
}
$parsed_type = new Atomic($type_tokens[0]);
if ($enclose_with_union) {
$parsed_type = new Union([$parsed_type]);
}
return $parsed_type;
return new Union([new Atomic($type_tokens[0])]);
}
// We construct a parse tree corresponding to the type
@ -125,7 +119,7 @@ abstract class Type
$parsed_type = self::getTypeFromTree($parse_tree);
if ($enclose_with_union && !($parsed_type instanceof Union)) {
if (!($parsed_type instanceof Union)) {
$parsed_type = new Union([$parsed_type]);
}

View File

@ -16,13 +16,18 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
self::$_parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
}
private static function getAtomic($string)
{
return array_values(self::getAtomic($string)->types)[0];
}
public function testIntOrString()
{
$this->assertEquals(
'int|string',
(string) Type::combineTypes([
Type::parseString('int', false),
Type::parseString('string', false)
self::getAtomic('int'),
self::getAtomic('string')
])
);
}
@ -32,8 +37,8 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
'array<int|string>',
(string) Type::combineTypes([
Type::parseString('array<int>', false),
Type::parseString('array<string>', false)
self::getAtomic('array<int>'),
self::getAtomic('array<string>')
])
);
}
@ -43,8 +48,8 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
'array<int>|string',
(string) Type::combineTypes([
Type::parseString('array<int>', false),
Type::parseString('string', false)
self::getAtomic('array<int>'),
self::getAtomic('string')
])
);
}
@ -54,8 +59,8 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
'array<empty>',
(string) Type::combineTypes([
Type::parseString('array<empty>', false),
Type::parseString('array<empty>', false)
self::getAtomic('array<empty>'),
self::getAtomic('array<empty>')
])
);
}
@ -65,8 +70,8 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
'array<string>',
(string) Type::combineTypes([
Type::parseString('array<empty>', false),
Type::parseString('array<string>', false)
self::getAtomic('array<empty>'),
self::getAtomic('array<string>')
])
);
}
@ -76,8 +81,8 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
'array<mixed>',
(string) Type::combineTypes([
Type::parseString('array<mixed>', false),
Type::parseString('array<string>', false)
self::getAtomic('array<mixed>'),
self::getAtomic('array<string>')
])
);
}
@ -87,8 +92,8 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
'array<mixed>',
(string) Type::combineTypes([
Type::parseString('array<empty>', false),
Type::parseString('array<mixed>', false)
self::getAtomic('array<empty>'),
self::getAtomic('array<mixed>')
])
);
}
@ -98,8 +103,8 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
'array<int|float|string>',
(string) Type::combineTypes([
Type::parseString('array<int|float>', false),
Type::parseString('array<string>', false)
self::getAtomic('array<int|float>'),
self::getAtomic('array<string>')
])
);
}
@ -109,8 +114,8 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
'bool',
(string) Type::combineTypes([
Type::parseString('false', false),
Type::parseString('bool', false)
self::getAtomic('false'),
self::getAtomic('bool')
])
);
}
@ -120,7 +125,7 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
'bool',
(string) Type::combineTypes([
Type::parseString('false', false)
self::getAtomic('false')
])
);
}
@ -130,8 +135,8 @@ class TypeCombinationTest extends PHPUnit_Framework_TestCase
$this->assertEquals(
'bool',
(string) Type::combineTypes([
Type::parseString('false', false),
Type::parseString('false', false)
self::getAtomic('false'),
self::getAtomic('false')
])
);
}