1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

Fixed vimeo/psalm#1714 (#1715)

* Fixed vimeo/psalm#1714

Moved `isAbsolutePath()` into a functions file (`src/functions.php`)
that is now automatically loaded by composer autoload.

/cc: @jwage

* Dropped redundant bootstrap
This commit is contained in:
Bruce Weirdan 2019-06-01 15:26:22 +03:00 committed by Matthew Brown
parent a252fb84da
commit 1b0158ad72
7 changed files with 36 additions and 38 deletions

View File

@ -30,7 +30,10 @@
"psr-4": { "psr-4": {
"Psalm\\Plugin\\": "src/Psalm/Plugin", "Psalm\\Plugin\\": "src/Psalm/Plugin",
"Psalm\\": "src/Psalm" "Psalm\\": "src/Psalm"
} },
"files": [
"src/functions.php"
]
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
bootstrap="tests/bootstrap.php" bootstrap="vendor/autoload.php"
backupGlobals="false" backupGlobals="false"
beStrictAboutCoversAnnotation="true" beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true" beStrictAboutOutputDuringTests="true"

View File

@ -21,6 +21,8 @@ use Psalm\Progress\Progress;
use Psalm\Progress\VoidProgress; use Psalm\Progress\VoidProgress;
use SimpleXMLElement; use SimpleXMLElement;
use function isAbsolutePath;
class Config class Config
{ {
const DEFAULT_FILE_NAME = 'psalm.xml'; const DEFAULT_FILE_NAME = 'psalm.xml';

View File

@ -222,32 +222,3 @@ function getPathsToCheck($f_paths)
return $paths_to_check; return $paths_to_check;
} }
/**
* @param string $path
*
* @return bool
*/
function isAbsolutePath($path)
{
// Optional wrapper(s).
$regex = '%^(?<wrappers>(?:[[:print:]]{2,}://)*)';
// Optional root prefix.
$regex .= '(?<root>(?:[[:alpha:]]:/|/)?)';
// Actual path.
$regex .= '(?<path>(?:[[:print:]]*))$%';
$parts = [];
if (!preg_match($regex, $path, $parts)) {
throw new InvalidArgumentException(sprintf('Path is not valid, "%s" given.', $path));
}
if ('' !== $parts['root']) {
return true;
}
return false;
}

29
src/functions.php Normal file
View File

@ -0,0 +1,29 @@
<?php
/**
* @param string $path
*
* @return bool
*/
function isAbsolutePath($path)
{
// Optional wrapper(s).
$regex = '%^(?<wrappers>(?:[[:print:]]{2,}://)*)';
// Optional root prefix.
$regex .= '(?<root>(?:[[:alpha:]]:/|/)?)';
// Actual path.
$regex .= '(?<path>(?:[[:print:]]*))$%';
$parts = [];
if (!preg_match($regex, $path, $parts)) {
throw new InvalidArgumentException(sprintf('Path is not valid, "%s" given.', $path));
}
if ('' !== $parts['root']) {
return true;
}
return false;
}

View File

@ -13,8 +13,6 @@ class IsAbsolutePathTest extends TestCase
*/ */
public function testIsAbsolutePath($path, $expected) public function testIsAbsolutePath($path, $expected)
{ {
require_once __DIR__.'/../src/command_functions.php';
self::assertSame($expected, isAbsolutePath($path)); self::assertSame($expected, isAbsolutePath($path));
} }

View File

@ -1,5 +0,0 @@
<?php
require_once(__DIR__.'/../src/command_functions.php');
return require_once(__DIR__.'/../vendor/autoload.php');