mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +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:
parent
a252fb84da
commit
1b0158ad72
@ -30,7 +30,10 @@
|
||||
"psr-4": {
|
||||
"Psalm\\Plugin\\": "src/Psalm/Plugin",
|
||||
"Psalm\\": "src/Psalm"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"src/functions.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
bootstrap="vendor/autoload.php"
|
||||
backupGlobals="false"
|
||||
beStrictAboutCoversAnnotation="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
|
@ -21,6 +21,8 @@ use Psalm\Progress\Progress;
|
||||
use Psalm\Progress\VoidProgress;
|
||||
use SimpleXMLElement;
|
||||
|
||||
use function isAbsolutePath;
|
||||
|
||||
class Config
|
||||
{
|
||||
const DEFAULT_FILE_NAME = 'psalm.xml';
|
||||
|
@ -222,32 +222,3 @@ function getPathsToCheck($f_paths)
|
||||
|
||||
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
29
src/functions.php
Normal 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;
|
||||
}
|
@ -13,8 +13,6 @@ class IsAbsolutePathTest extends TestCase
|
||||
*/
|
||||
public function testIsAbsolutePath($path, $expected)
|
||||
{
|
||||
require_once __DIR__.'/../src/command_functions.php';
|
||||
|
||||
self::assertSame($expected, isAbsolutePath($path));
|
||||
}
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once(__DIR__.'/../src/command_functions.php');
|
||||
|
||||
return require_once(__DIR__.'/../vendor/autoload.php');
|
Loading…
Reference in New Issue
Block a user