From f84b22e05d3f8866bba26b5953edf7503c912c82 Mon Sep 17 00:00:00 2001 From: Trevor Bortins Date: Mon, 6 Feb 2017 13:28:57 -0800 Subject: [PATCH] Clean up style --- src/LanguageServer.php | 10 ++-------- src/utils.php | 16 +++++++--------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/LanguageServer.php b/src/LanguageServer.php index 01f8d5c..7445e53 100644 --- a/src/LanguageServer.php +++ b/src/LanguageServer.php @@ -25,7 +25,6 @@ use Exception; use Throwable; use Webmozart\PathUtil\Path; use Sabre\Uri; -use function LanguageServer\sortByLeastSlashes; class LanguageServer extends AdvancedJsonRpc\Dispatcher { @@ -207,9 +206,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher // Find composer.json if ($this->composerJson === null) { $composerJsonFiles = yield $this->filesFinder->find(Path::makeAbsolute('**/composer.json', $rootPath)); - // If we sort our findings by number of slashes (least to greatest), - // the first entry will be the project's root composer.json. - usort($composerJsonFiles, 'LanguageServer\sortByLeastSlashes'); + sortUrisLevelOrder($composerJsonFiles); if (!empty($composerJsonFiles)) { $this->composerJson = json_decode(yield $this->contentRetriever->retrieve($composerJsonFiles[0])); @@ -219,10 +216,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher // Find composer.lock if ($this->composerLock === null) { $composerLockFiles = yield $this->filesFinder->find(Path::makeAbsolute('**/composer.lock', $rootPath)); - - // If we sort our findings by number of slashes (least to greatest), - // the first entry will be the project's root composer.lock. - usort($composerLockFiles, 'LanguageServer\sortByLeastSlashes'); + sortUrisLevelOrder($composerLockFiles); if (!empty($composerLockFiles)) { $this->composerLock = json_decode(yield $this->contentRetriever->retrieve($composerLockFiles[0])); diff --git a/src/utils.php b/src/utils.php index 071be13..c13f1be 100644 --- a/src/utils.php +++ b/src/utils.php @@ -7,7 +7,7 @@ use Throwable; use InvalidArgumentException; use PhpParser\Node; use Sabre\Event\{Loop, Promise, EmitterInterface}; -use function Sabre\Uri\parse; +use Sabre\Uri; /** * Transforms an absolute file path into a URI as used by the language server protocol. @@ -137,14 +137,12 @@ function stripStringOverlap(string $a, string $b): string * Use for sorting an array of URIs by number of segments * in ascending order. * - * Example: - * usort($uriList, 'LanguageServer\sortByLeastSlashes'); - * - * @param $a string - * @param $b string - * @return integer + * @param array + * @return array */ -function sortByLeastSlashes($a, $b) +function sortUrisLevelOrder(&$uriList) { - return substr_count(parse($a)['path'], '/') - substr_count(parse($b)['path'], '/'); + usort($uriList, function ($a, $b) { + return substr_count(Uri\parse($a)['path'], '/') - substr_count(Uri\parse($b)['path'], '/'); + }); }