Skip to content
Permalink
Browse files

Fixed #1714 (#1715)

* Fixed #1714

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

/cc: @jwage

* Dropped redundant bootstrap
  • Loading branch information...
weirdan authored and muglug committed Jun 1, 2019
1 parent a252fb8 commit 1b0158ad725cb76c765d3d58a88fa03c9c82e50f
Showing with 36 additions and 38 deletions.
  1. +4 −1 composer.json
  2. +1 −1 phpunit.xml.dist
  3. +2 −0 src/Psalm/Config.php
  4. +0 −29 src/command_functions.php
  5. +29 −0 src/functions.php
  6. +0 −2 tests/IsAbsolutePathTest.php
  7. +0 −5 tests/bootstrap.php
@@ -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\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;
}
@@ -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));
}

This file was deleted.

0 comments on commit 1b0158a

Please sign in to comment.
You can’t perform that action at this time.