diff --git a/.gitignore b/.gitignore index ac28833..1c9d520 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ # Composer dependencies vendor/ + +# PHP CodeSniffer cache +.phpcs-cache diff --git a/composer.json b/composer.json index adba9b5..1c2ef39 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "imangazaliev/didom": "^1.13" }, "require-dev": { - "squizlabs/php_codesniffer": "^2.2", + "squizlabs/php_codesniffer": "^3.5", "phpmd/phpmd": "^2.5" }, "scripts": { diff --git a/composer.lock b/composer.lock index 2a24f7f..57e0a00 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "268f4674e26f1fdbbd6c84dd4813720b", + "content-hash": "ec2b655c95a557950e141e298d5f6a4c", "packages": [ { "name": "fig/http-message-util", @@ -127,19 +127,21 @@ }, { "name": "imangazaliev/didom", - "version": "1.13", + "version": "1.18", "source": { "type": "git", "url": "https://github.com/Imangazaliev/DiDOM.git", - "reference": "10c4033d56e599f09183959ed90bf17519b9e38b" + "reference": "346db1ea94a0f6ead225c2358af770bf33659cf7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Imangazaliev/DiDOM/zipball/10c4033d56e599f09183959ed90bf17519b9e38b", - "reference": "10c4033d56e599f09183959ed90bf17519b9e38b", + "url": "https://api.github.com/repos/Imangazaliev/DiDOM/zipball/346db1ea94a0f6ead225c2358af770bf33659cf7", + "reference": "346db1ea94a0f6ead225c2358af770bf33659cf7", "shasum": "" }, "require": { + "ext-dom": "*", + "ext-iconv": "*", "php": ">=5.4" }, "require-dev": { @@ -171,9 +173,9 @@ ], "support": { "issues": "https://github.com/Imangazaliev/DiDOM/issues", - "source": "https://github.com/Imangazaliev/DiDOM/tree/develop" + "source": "https://github.com/Imangazaliev/DiDOM/tree/1.18" }, - "time": "2017-12-08T15:20:07+00:00" + "time": "2021-07-27T18:50:53+00:00" }, { "name": "laravel/serializable-closure", @@ -1413,16 +1415,16 @@ }, { "name": "twig/twig", - "version": "v3.4.2", + "version": "v3.4.3", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "e07cdd3d430cd7e453c31b36eb5ad6c0c5e43077" + "reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/e07cdd3d430cd7e453c31b36eb5ad6c0c5e43077", - "reference": "e07cdd3d430cd7e453c31b36eb5ad6c0c5e43077", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/c38fd6b0b7f370c198db91ffd02e23b517426b58", + "reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58", "shasum": "" }, "require": { @@ -1473,7 +1475,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.4.2" + "source": "https://github.com/twigphp/Twig/tree/v3.4.3" }, "funding": [ { @@ -1485,10 +1487,147 @@ "type": "tidelift" } ], - "time": "2022-08-12T06:47:24+00:00" + "time": "2022-09-28T08:42:51+00:00" } ], "packages-dev": [ + { + "name": "composer/pcre", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/composer/pcre.git", + "reference": "e300eb6c535192decd27a85bc72a9290f0d6b3bd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/pcre/zipball/e300eb6c535192decd27a85bc72a9290f0d6b3bd", + "reference": "e300eb6c535192decd27a85bc72a9290f0d6b3bd", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.3", + "phpstan/phpstan-strict-rules": "^1.1", + "symfony/phpunit-bridge": "^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Pcre\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + } + ], + "description": "PCRE wrapping library that offers type-safe preg_* replacements.", + "keywords": [ + "PCRE", + "preg", + "regex", + "regular expression" + ], + "support": { + "issues": "https://github.com/composer/pcre/issues", + "source": "https://github.com/composer/pcre/tree/3.0.0" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2022-02-25T20:21:48+00:00" + }, + { + "name": "composer/xdebug-handler", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/composer/xdebug-handler.git", + "reference": "ced299686f41dce890debac69273b47ffe98a40c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ced299686f41dce890debac69273b47ffe98a40c", + "reference": "ced299686f41dce890debac69273b47ffe98a40c", + "shasum": "" + }, + "require": { + "composer/pcre": "^1 || ^2 || ^3", + "php": "^7.2.5 || ^8.0", + "psr/log": "^1 || ^2 || ^3" + }, + "require-dev": { + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-strict-rules": "^1.1", + "symfony/phpunit-bridge": "^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Composer\\XdebugHandler\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "John Stevenson", + "email": "john-stevenson@blueyonder.co.uk" + } + ], + "description": "Restarts a process without Xdebug.", + "keywords": [ + "Xdebug", + "performance" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/xdebug-handler/issues", + "source": "https://github.com/composer/xdebug-handler/tree/3.0.3" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2022-02-25T21:32:43+00:00" + }, { "name": "pdepend/pdepend", "version": "2.12.1", @@ -1548,30 +1687,37 @@ }, { "name": "phpmd/phpmd", - "version": "2.5.0", + "version": "2.13.0", "source": { "type": "git", "url": "https://github.com/phpmd/phpmd.git", - "reference": "9298602a922cd8c46666df8d540a60bc5925ce55" + "reference": "dad0228156856b3ad959992f9748514fa943f3e3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpmd/phpmd/zipball/9298602a922cd8c46666df8d540a60bc5925ce55", - "reference": "9298602a922cd8c46666df8d540a60bc5925ce55", + "url": "https://api.github.com/repos/phpmd/phpmd/zipball/dad0228156856b3ad959992f9748514fa943f3e3", + "reference": "dad0228156856b3ad959992f9748514fa943f3e3", "shasum": "" }, "require": { - "pdepend/pdepend": "^2.0.4", + "composer/xdebug-handler": "^1.0 || ^2.0 || ^3.0", + "ext-xml": "*", + "pdepend/pdepend": "^2.12.1", "php": ">=5.3.9" }, "require-dev": { - "phpunit/phpunit": "^4.0", + "easy-doc/easy-doc": "0.0.0 || ^1.3.2", + "ext-json": "*", + "ext-simplexml": "*", + "gregwar/rst": "^1.0", + "mikey179/vfsstream": "^1.6.8", + "phpunit/phpunit": "^4.8.36 || ^5.7.27", "squizlabs/php_codesniffer": "^2.0" }, "bin": [ "src/bin/phpmd" ], - "type": "project", + "type": "library", "autoload": { "psr-0": { "PHPMD\\": "src/main/php" @@ -1588,20 +1734,20 @@ "homepage": "https://github.com/manuelpichler", "role": "Project Founder" }, - { - "name": "Other contributors", - "homepage": "https://github.com/phpmd/phpmd/graphs/contributors", - "role": "Contributors" - }, { "name": "Marc Würth", "email": "ravage@bluewin.ch", "homepage": "https://github.com/ravage84", "role": "Project Maintainer" + }, + { + "name": "Other contributors", + "homepage": "https://github.com/phpmd/phpmd/graphs/contributors", + "role": "Contributors" } ], "description": "PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD.", - "homepage": "http://phpmd.org/", + "homepage": "https://phpmd.org/", "keywords": [ "mess detection", "mess detector", @@ -1612,59 +1758,48 @@ "support": { "irc": "irc://irc.freenode.org/phpmd", "issues": "https://github.com/phpmd/phpmd/issues", - "source": "https://github.com/phpmd/phpmd/tree/master" + "source": "https://github.com/phpmd/phpmd/tree/2.13.0" }, - "time": "2016-11-23T20:33:32+00:00" + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/phpmd/phpmd", + "type": "tidelift" + } + ], + "time": "2022-09-10T08:44:15+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "2.2.0", + "version": "3.7.1", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "b301c98f19414d836fdaa678648745fcca5aeb4f" + "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b301c98f19414d836fdaa678648745fcca5aeb4f", - "reference": "b301c98f19414d836fdaa678648745fcca5aeb4f", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1359e176e9307e906dc3d890bcc9603ff6d90619", + "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619", "shasum": "" }, "require": { + "ext-simplexml": "*", "ext-tokenizer": "*", - "php": ">=5.1.2" + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "bin": [ - "scripts/phpcs", - "scripts/phpcbf" + "bin/phpcs", + "bin/phpcbf" ], "type": "library", - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1677,7 +1812,7 @@ } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "http://www.squizlabs.com/php-codesniffer", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", "keywords": [ "phpcs", "standards" @@ -1687,7 +1822,7 @@ "source": "https://github.com/squizlabs/PHP_CodeSniffer", "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" }, - "time": "2015-01-21T22:44:05+00:00" + "time": "2022-06-18T07:21:10+00:00" }, { "name": "symfony/config", diff --git a/phpcs.xml b/phpcs.xml index 0ff746b..215b7c9 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -16,7 +16,9 @@ + + diff --git a/src/Controllers/HomeController.php b/src/Controllers/HomeController.php index 67b22c5..2bf85be 100644 --- a/src/Controllers/HomeController.php +++ b/src/Controllers/HomeController.php @@ -5,19 +5,18 @@ namespace BitGoblin\MCST\Controllers; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; - use BitGoblin\MCST\Minecraft\Server; class HomeController extends Controller { - public function getIndex(Request $request, Response $response, $args): Response { + public function getIndex(Request $request, Response $response): Response { $config = $this->get('config'); // find servers $minecraftDir = $config->get('server_directory'); $serverDirs = glob($minecraftDir . "/*", GLOB_ONLYDIR); $minecraftServers = array(); - foreach ($serverDirs as $i => $m) { + foreach ($serverDirs as $m) { array_push($minecraftServers, new Server($m)); } diff --git a/src/Controllers/ServerController.php b/src/Controllers/ServerController.php index c16827c..933de44 100644 --- a/src/Controllers/ServerController.php +++ b/src/Controllers/ServerController.php @@ -6,19 +6,18 @@ use DiDom\Document; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; - use BitGoblin\MCST\Minecraft\Server; class ServerController extends Controller { // GET create server route - public function getCreate(Request $request, Response $response, $args): Response { + public function getCreate(Request $request, Response $response): Response { $view = Twig::fromRequest($request); return $view->render($response, 'create.twig'); } // POST create server route - public function postCreate(Request $request, Response $response, $args): Response { + public function postCreate(Request $request, Response $response): Response { // set up the POST parameters and grab our config $params = (array)$request->getParsedBody(); $config = $this->get('config'); diff --git a/src/Minecraft/Server.php b/src/Minecraft/Server.php index a5f5632..71d1243 100644 --- a/src/Minecraft/Server.php +++ b/src/Minecraft/Server.php @@ -47,9 +47,9 @@ class Server { // start the server public function start(): void { - $command = $this->rootDir . '/start.sh > /dev/null 2>&1 & echo $!'; + $command = $this->rootDir . '/start.sh > /dev/null 2>&1 & echo $!'; exec($command, $output); - // use lsof to + // use lsof to find the PID of the server $pidResult = exec('lsof ' . $this->rootDir . '/server*.jar | grep .jar'); $pid = preg_split('/\s+/', $pidResult, -1, PREG_SPLIT_NO_EMPTY)[1]; @@ -69,7 +69,7 @@ class Server { exec('kill -15 ' . $pid); // set server state to false $this->state = false; - } + } } // get the server's PID diff --git a/src/Minecraft/ServerConfig.php b/src/Minecraft/ServerConfig.php index d1d89ac..5ae3b3c 100644 --- a/src/Minecraft/ServerConfig.php +++ b/src/Minecraft/ServerConfig.php @@ -14,9 +14,9 @@ class ServerConfig { $this->config = array(); // initialize array // parse config file - $fh = fopen($propertiesFile, 'r+'); - while (!feof($fh)) { - $line = fgets($fh); + $fileHandle = fopen($propertiesFile, 'r+'); + while (!feof($fileHandle)) { + $line = fgets($fileHandle); $eqpos = strpos($line, '='); $parameterName = substr($line, 0, $eqpos); $parameterValue = trim(substr($line, ($eqpos + 1))); @@ -36,9 +36,9 @@ class ServerConfig { // update and save the server.properties file $newFileContent = ''; - $fh = fopen($this->propertiesFile, 'r+'); - while (!feof($fh)) { - $line = fgets($fh); + $fileHandle = fopen($this->propertiesFile, 'r+'); + while (!feof($fileHandle)) { + $line = fgets($fileHandle); if (!str_starts_with($line, '#')) { $eqpos = strpos($line, '='); @@ -58,7 +58,7 @@ class ServerConfig { // save the new properties file file_put_contents($this->propertiesFile, $newFileContent); - fclose($fh); + fclose($fileHandle); } } diff --git a/src/app.php b/src/app.php index f4c110e..8af16c4 100644 --- a/src/app.php +++ b/src/app.php @@ -14,7 +14,7 @@ $config = Config::load(__DIR__ . '/../conf/defaults.json'); // Create new container object and add our config object to it $container = new Container(); -$container->set('config', function() use ($config) { +$container->set('config', function () use ($config) { return $config; }); diff --git a/src/routes.php b/src/routes.php index 5291ce3..ebed79d 100644 --- a/src/routes.php +++ b/src/routes.php @@ -3,7 +3,6 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; - use BitGoblin\MCST\Minecraft\Server; // index GET route - this page should welcome the user and direct them to the available actions