diff --git a/.travis.yml b/.travis.yml index ca1b4ec..caefbec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ install: - composer install script: + - vendor/bin/phpcs -n - vendor/bin/phpunit --coverage-clover=coverage.xml after_success: diff --git a/fixtures/format.php b/fixtures/format.php index f300b67..bd35640 100644 --- a/fixtures/format.php +++ b/fixtures/format.php @@ -13,7 +13,7 @@ class TestClass { $testVariable = 123; - if ( empty($testParameter)){ + if (empty($testParameter)){ echo 'Empty'; } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..e67104b --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,10 @@ + + + src + tests + + + + + + diff --git a/src/Formatter.php b/src/Formatter.php index 5f4744f..37e3f4c 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -4,8 +4,8 @@ declare(strict_types = 1); namespace LanguageServer; use LanguageServer\Protocol\ { - TextEdit, - Range, + TextEdit, + Range, Position }; use PHP_CodeSniffer; @@ -42,9 +42,9 @@ abstract class Formatter /** * Calculate position of last character. - * + * * @param string $content document as string - * + * * @return \LanguageServer\Protocol\Position */ private static function calculateEndPosition(string $content): Position @@ -54,10 +54,10 @@ abstract class Formatter } /** - * Search for PHP_CodeSniffer configuration file at given directory or its parents. - * If no configuration found then PSR2 standard is loaded by default. + * Search for PHP_CodeSniffer configuration file at given directory or its parents. + * If no configuration found then PSR2 standard is loaded by default. * - * @param string $path path to file or directory + * @param string $path path to file or directory * @return string[] */ private static function findConfiguration(string $path) @@ -85,5 +85,4 @@ abstract class Formatter $standard = PHP_CodeSniffer::getConfigData('default_standard') ?? 'PSR2'; return explode(',', $standard); } - } diff --git a/src/LanguageServer.php b/src/LanguageServer.php index 04d7c5e..cfc96b5 100644 --- a/src/LanguageServer.php +++ b/src/LanguageServer.php @@ -163,7 +163,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher $startTime = microtime(true); $fileNum = 0; - $processFile = function() use (&$fileList, &$fileNum, &$processFile, $numTotalFiles, $startTime) { + $processFile = function () use (&$fileList, &$fileNum, &$processFile, $numTotalFiles, $startTime) { if ($fileNum < $numTotalFiles) { $file = $fileList[$fileNum]; $uri = pathToUri($file); diff --git a/src/Project.php b/src/Project.php index 5e8a5f9..c347566 100644 --- a/src/Project.php +++ b/src/Project.php @@ -178,7 +178,8 @@ class Project * @param string $fqn The fully qualified name of the symbol * @return void */ - public function removeSymbol(string $fqn) { + public function removeSymbol(string $fqn) + { unset($this->symbols[$fqn]); unset($this->references[$fqn]); } @@ -207,7 +208,8 @@ class Project * @param string $uri The URI * @return void */ - public function removeReferenceUri(string $fqn, string $uri) { + public function removeReferenceUri(string $fqn, string $uri) + { if (!isset($this->references[$fqn])) { return; } diff --git a/src/Protocol/CompletionItemKind.php b/src/Protocol/CompletionItemKind.php index 9a2bd15..6ef5796 100644 --- a/src/Protocol/CompletionItemKind.php +++ b/src/Protocol/CompletionItemKind.php @@ -5,7 +5,8 @@ namespace LanguageServer\Protocol; /** * The kind of a completion entry. */ -abstract class CompletionItemKind { +abstract class CompletionItemKind +{ const TEXT = 1; const METHOD = 2; const FUNCTION = 3; diff --git a/src/Protocol/ReferenceContext.php b/src/Protocol/ReferenceContext.php index f0c3b12..bd546d5 100644 --- a/src/Protocol/ReferenceContext.php +++ b/src/Protocol/ReferenceContext.php @@ -4,10 +4,10 @@ namespace LanguageServer\Protocol; class ReferenceContext { - /** - * Include the declaration of the current symbol. + /** + * Include the declaration of the current symbol. * * @var bool - */ - public $includeDeclaration; + */ + public $includeDeclaration; } diff --git a/src/ProtocolStreamReader.php b/src/ProtocolStreamReader.php index 6551267..699fb3c 100644 --- a/src/ProtocolStreamReader.php +++ b/src/ProtocolStreamReader.php @@ -8,16 +8,13 @@ use AdvancedJsonRpc\Message as MessageBody; use Sabre\Event\Loop; use RuntimeException; -abstract class ParsingMode -{ - const HEADERS = 1; - const BODY = 2; -} - class ProtocolStreamReader implements ProtocolReader { + const PARSE_HEADERS = 1; + const PARSE_BODY = 2; + private $input; - private $parsingMode = ParsingMode::HEADERS; + private $parsingMode = self::PARSE_HEADERS; private $buffer = ''; private $headers = []; private $contentLength; @@ -29,7 +26,7 @@ class ProtocolStreamReader implements ProtocolReader public function __construct($input) { $this->input = $input; - Loop\addReadStream($this->input, function() { + Loop\addReadStream($this->input, function () { if (feof($this->input)) { throw new RuntimeException('Stream is closed'); } @@ -37,9 +34,9 @@ class ProtocolStreamReader implements ProtocolReader while (($c = fgetc($this->input)) !== false && $c !== '') { $this->buffer .= $c; switch ($this->parsingMode) { - case ParsingMode::HEADERS: + case self::PARSE_HEADERS: if ($this->buffer === "\r\n") { - $this->parsingMode = ParsingMode::BODY; + $this->parsingMode = self::PARSE_BODY; $this->contentLength = (int)$this->headers['Content-Length']; $this->buffer = ''; } else if (substr($this->buffer, -2) === "\r\n") { @@ -48,14 +45,14 @@ class ProtocolStreamReader implements ProtocolReader $this->buffer = ''; } break; - case ParsingMode::BODY: + case self::PARSE_BODY: if (strlen($this->buffer) === $this->contentLength) { if (isset($this->listener)) { $msg = new Message(MessageBody::parse($this->buffer), $this->headers); $listener = $this->listener; $listener($msg); } - $this->parsingMode = ParsingMode::HEADERS; + $this->parsingMode = self::PARSE_HEADERS; $this->headers = []; $this->buffer = ''; } diff --git a/src/utils.php b/src/utils.php index c89c2d3..810fbc1 100644 --- a/src/utils.php +++ b/src/utils.php @@ -12,7 +12,8 @@ use InvalidArgumentException; * @param string $pattern * @return array */ -function findFilesRecursive(string $path, string $pattern): array { +function findFilesRecursive(string $path, string $pattern): array +{ $dir = new \RecursiveDirectoryIterator($path); $ite = new \RecursiveIteratorIterator($dir); $files = new \RegexIterator($ite, $pattern, \RegexIterator::GET_MATCH); @@ -29,7 +30,8 @@ function findFilesRecursive(string $path, string $pattern): array { * @param string $filepath * @return string */ -function pathToUri(string $filepath): string { +function pathToUri(string $filepath): string +{ $filepath = trim(str_replace('\\', '/', $filepath), '/'); $parts = explode('/', $filepath); // Don't %-encode the colon after a Windows drive letter diff --git a/tests/MockProtocolStream.php b/tests/MockProtocolStream.php index ce2c361..a6cf1f4 100644 --- a/tests/MockProtocolStream.php +++ b/tests/MockProtocolStream.php @@ -36,4 +36,3 @@ class MockProtocolStream implements ProtocolReader, ProtocolWriter $this->listener = $listener; } } - diff --git a/tests/Server/ServerTestCase.php b/tests/Server/ServerTestCase.php index 6728a9f..0886655 100644 --- a/tests/Server/ServerTestCase.php +++ b/tests/Server/ServerTestCase.php @@ -59,6 +59,7 @@ abstract class ServerTestCase extends TestCase $this->project->loadDocument($globalReferencesUri); $this->project->loadDocument($useUri); + // @codingStandardsIgnoreStart $this->definitionLocations = [ // Global @@ -166,6 +167,7 @@ abstract class ServerTestCase extends TestCase 0 => new Location($globalReferencesUri, new Range(new Position(10, 0), new Position(10, 13))) ] ]; + // @codingStandardsIgnoreEnd } protected function getDefinitionLocation(string $fqn): Location diff --git a/tests/Server/TextDocument/Definition/GlobalTest.php b/tests/Server/TextDocument/Definition/GlobalTest.php index 9fd325e..f4a854d 100644 --- a/tests/Server/TextDocument/Definition/GlobalTest.php +++ b/tests/Server/TextDocument/Definition/GlobalTest.php @@ -9,13 +9,15 @@ use function LanguageServer\pathToUri; class GlobalTest extends ServerTestCase { - public function testDefinitionFileBeginning() { + public function testDefinitionFileBeginning() + { // |textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(0, 0)); $this->assertEquals([], $result); } - public function testDefinitionEmptyResult() { + public function testDefinitionEmptyResult() + { // namespace keyword $result = $this->textDocument->definition(new TextDocumentIdentifier(pathToUri(realpath(__DIR__ . '/../../../../fixtures/references.php'))), new Position(2, 4)); $this->assertEquals([], $result); diff --git a/tests/Server/TextDocument/DocumentSymbolTest.php b/tests/Server/TextDocument/DocumentSymbolTest.php index 803dcae..7b304d0 100644 --- a/tests/Server/TextDocument/DocumentSymbolTest.php +++ b/tests/Server/TextDocument/DocumentSymbolTest.php @@ -16,6 +16,7 @@ class DocumentSymbolTest extends ServerTestCase // Request symbols $uri = pathToUri(realpath(__DIR__ . '/../../../fixtures/symbols.php')); $result = $this->textDocument->documentSymbol(new TextDocumentIdentifier($uri)); + // @codingStandardsIgnoreStart $this->assertEquals([ new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'), new SymbolInformation('TestClass', SymbolKind::CLASS_, $this->getDefinitionLocation('TestNamespace\\TestClass'), 'TestNamespace'), @@ -28,5 +29,6 @@ class DocumentSymbolTest extends ServerTestCase new SymbolInformation('TestInterface', SymbolKind::INTERFACE, $this->getDefinitionLocation('TestNamespace\\TestInterface'), 'TestNamespace'), new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('TestNamespace\\test_function()'), 'TestNamespace'), ], $result); + // @codingStandardsIgnoreEnd } } diff --git a/tests/Server/TextDocument/ParseErrorsTest.php b/tests/Server/TextDocument/ParseErrorsTest.php index 37ce769..09efec7 100644 --- a/tests/Server/TextDocument/ParseErrorsTest.php +++ b/tests/Server/TextDocument/ParseErrorsTest.php @@ -36,7 +36,8 @@ class ParseErrorsTest extends TestCase $this->textDocument = new Server\TextDocument($project, $client); } - private function openFile($file) { + private function openFile($file) + { $textDocumentItem = new TextDocumentItem(); $textDocumentItem->uri = 'whatever'; $textDocumentItem->languageId = 'php'; diff --git a/tests/Server/Workspace/SymbolTest.php b/tests/Server/Workspace/SymbolTest.php index b029e77..7086942 100644 --- a/tests/Server/Workspace/SymbolTest.php +++ b/tests/Server/Workspace/SymbolTest.php @@ -16,6 +16,7 @@ class SymbolTest extends ServerTestCase { // Request symbols $result = $this->workspace->symbol(''); + // @codingStandardsIgnoreStart $this->assertEquals([ // Namespaced new SymbolInformation('TEST_CONST', SymbolKind::CONSTANT, $this->getDefinitionLocation('TestNamespace\\TEST_CONST'), 'TestNamespace'), @@ -42,17 +43,20 @@ class SymbolTest extends ServerTestCase new SymbolInformation('test_function', SymbolKind::FUNCTION, $this->getDefinitionLocation('test_function()'), ''), new SymbolInformation('whatever', SymbolKind::FUNCTION, $this->getDefinitionLocation('whatever()'), '') ], $result); + // @codingStandardsIgnoreEnd } public function testQueryFiltersResults() { // Request symbols $result = $this->workspace->symbol('testmethod'); + // @codingStandardsIgnoreStart $this->assertEquals([ new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::staticTestMethod()'), 'TestNamespace\\TestClass'), new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestNamespace\\TestClass::testMethod()'), 'TestNamespace\\TestClass'), new SymbolInformation('staticTestMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::staticTestMethod()'), 'TestClass'), new SymbolInformation('testMethod', SymbolKind::METHOD, $this->getDefinitionLocation('TestClass::testMethod()'), 'TestClass') ], $result); + // @codingStandardsIgnoreEnd } }