Updated version of PHP CodeSniffer; cleaned up some style issues and code smells
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Gregory Ballantine 2022-10-14 12:52:29 -04:00
parent 069a246db0
commit 9ecc458ea1
10 changed files with 219 additions and 82 deletions

3
.gitignore vendored
View File

@ -1,2 +1,5 @@
# Composer dependencies # Composer dependencies
vendor/ vendor/
# PHP CodeSniffer cache
.phpcs-cache

View File

@ -23,7 +23,7 @@
"imangazaliev/didom": "^1.13" "imangazaliev/didom": "^1.13"
}, },
"require-dev": { "require-dev": {
"squizlabs/php_codesniffer": "^2.2", "squizlabs/php_codesniffer": "^3.5",
"phpmd/phpmd": "^2.5" "phpmd/phpmd": "^2.5"
}, },
"scripts": { "scripts": {

261
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "268f4674e26f1fdbbd6c84dd4813720b", "content-hash": "ec2b655c95a557950e141e298d5f6a4c",
"packages": [ "packages": [
{ {
"name": "fig/http-message-util", "name": "fig/http-message-util",
@ -127,19 +127,21 @@
}, },
{ {
"name": "imangazaliev/didom", "name": "imangazaliev/didom",
"version": "1.13", "version": "1.18",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/Imangazaliev/DiDOM.git", "url": "https://github.com/Imangazaliev/DiDOM.git",
"reference": "10c4033d56e599f09183959ed90bf17519b9e38b" "reference": "346db1ea94a0f6ead225c2358af770bf33659cf7"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/Imangazaliev/DiDOM/zipball/10c4033d56e599f09183959ed90bf17519b9e38b", "url": "https://api.github.com/repos/Imangazaliev/DiDOM/zipball/346db1ea94a0f6ead225c2358af770bf33659cf7",
"reference": "10c4033d56e599f09183959ed90bf17519b9e38b", "reference": "346db1ea94a0f6ead225c2358af770bf33659cf7",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-dom": "*",
"ext-iconv": "*",
"php": ">=5.4" "php": ">=5.4"
}, },
"require-dev": { "require-dev": {
@ -171,9 +173,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/Imangazaliev/DiDOM/issues", "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", "name": "laravel/serializable-closure",
@ -1413,16 +1415,16 @@
}, },
{ {
"name": "twig/twig", "name": "twig/twig",
"version": "v3.4.2", "version": "v3.4.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/twigphp/Twig.git", "url": "https://github.com/twigphp/Twig.git",
"reference": "e07cdd3d430cd7e453c31b36eb5ad6c0c5e43077" "reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/e07cdd3d430cd7e453c31b36eb5ad6c0c5e43077", "url": "https://api.github.com/repos/twigphp/Twig/zipball/c38fd6b0b7f370c198db91ffd02e23b517426b58",
"reference": "e07cdd3d430cd7e453c31b36eb5ad6c0c5e43077", "reference": "c38fd6b0b7f370c198db91ffd02e23b517426b58",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1473,7 +1475,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/twigphp/Twig/issues", "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": [ "funding": [
{ {
@ -1485,10 +1487,147 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2022-08-12T06:47:24+00:00" "time": "2022-09-28T08:42:51+00:00"
} }
], ],
"packages-dev": [ "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", "name": "pdepend/pdepend",
"version": "2.12.1", "version": "2.12.1",
@ -1548,30 +1687,37 @@
}, },
{ {
"name": "phpmd/phpmd", "name": "phpmd/phpmd",
"version": "2.5.0", "version": "2.13.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpmd/phpmd.git", "url": "https://github.com/phpmd/phpmd.git",
"reference": "9298602a922cd8c46666df8d540a60bc5925ce55" "reference": "dad0228156856b3ad959992f9748514fa943f3e3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpmd/phpmd/zipball/9298602a922cd8c46666df8d540a60bc5925ce55", "url": "https://api.github.com/repos/phpmd/phpmd/zipball/dad0228156856b3ad959992f9748514fa943f3e3",
"reference": "9298602a922cd8c46666df8d540a60bc5925ce55", "reference": "dad0228156856b3ad959992f9748514fa943f3e3",
"shasum": "" "shasum": ""
}, },
"require": { "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" "php": ">=5.3.9"
}, },
"require-dev": { "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" "squizlabs/php_codesniffer": "^2.0"
}, },
"bin": [ "bin": [
"src/bin/phpmd" "src/bin/phpmd"
], ],
"type": "project", "type": "library",
"autoload": { "autoload": {
"psr-0": { "psr-0": {
"PHPMD\\": "src/main/php" "PHPMD\\": "src/main/php"
@ -1588,20 +1734,20 @@
"homepage": "https://github.com/manuelpichler", "homepage": "https://github.com/manuelpichler",
"role": "Project Founder" "role": "Project Founder"
}, },
{
"name": "Other contributors",
"homepage": "https://github.com/phpmd/phpmd/graphs/contributors",
"role": "Contributors"
},
{ {
"name": "Marc Würth", "name": "Marc Würth",
"email": "ravage@bluewin.ch", "email": "ravage@bluewin.ch",
"homepage": "https://github.com/ravage84", "homepage": "https://github.com/ravage84",
"role": "Project Maintainer" "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.", "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": [ "keywords": [
"mess detection", "mess detection",
"mess detector", "mess detector",
@ -1612,59 +1758,48 @@
"support": { "support": {
"irc": "irc://irc.freenode.org/phpmd", "irc": "irc://irc.freenode.org/phpmd",
"issues": "https://github.com/phpmd/phpmd/issues", "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", "name": "squizlabs/php_codesniffer",
"version": "2.2.0", "version": "3.7.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "b301c98f19414d836fdaa678648745fcca5aeb4f" "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/b301c98f19414d836fdaa678648745fcca5aeb4f", "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1359e176e9307e906dc3d890bcc9603ff6d90619",
"reference": "b301c98f19414d836fdaa678648745fcca5aeb4f", "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-simplexml": "*",
"ext-tokenizer": "*", "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": [ "bin": [
"scripts/phpcs", "bin/phpcs",
"scripts/phpcbf" "bin/phpcbf"
], ],
"type": "library", "type": "library",
"autoload": { "extra": {
"classmap": [ "branch-alias": {
"CodeSniffer.php", "dev-master": "3.x-dev"
"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/"
]
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
"license": [ "license": [
@ -1677,7 +1812,7 @@
} }
], ],
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", "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": [ "keywords": [
"phpcs", "phpcs",
"standards" "standards"
@ -1687,7 +1822,7 @@
"source": "https://github.com/squizlabs/PHP_CodeSniffer", "source": "https://github.com/squizlabs/PHP_CodeSniffer",
"wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" "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", "name": "symfony/config",

View File

@ -16,7 +16,9 @@
<!-- Our base rule: set to PSR12--> <!-- Our base rule: set to PSR12-->
<rule ref="PSR12"> <rule ref="PSR12">
<exclude name="PSR12.Classes.OpeningBraceSpace.Found" />
<exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" /> <exclude name="PSR2.Classes.ClassDeclaration.OpenBraceNewLine" />
<exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody" />
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" /> <exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine" />
</rule> </rule>

View File

@ -5,19 +5,18 @@ namespace BitGoblin\MCST\Controllers;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig; use Slim\Views\Twig;
use BitGoblin\MCST\Minecraft\Server; use BitGoblin\MCST\Minecraft\Server;
class HomeController extends Controller { 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'); $config = $this->get('config');
// find servers // find servers
$minecraftDir = $config->get('server_directory'); $minecraftDir = $config->get('server_directory');
$serverDirs = glob($minecraftDir . "/*", GLOB_ONLYDIR); $serverDirs = glob($minecraftDir . "/*", GLOB_ONLYDIR);
$minecraftServers = array(); $minecraftServers = array();
foreach ($serverDirs as $i => $m) { foreach ($serverDirs as $m) {
array_push($minecraftServers, new Server($m)); array_push($minecraftServers, new Server($m));
} }

View File

@ -6,19 +6,18 @@ use DiDom\Document;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig; use Slim\Views\Twig;
use BitGoblin\MCST\Minecraft\Server; use BitGoblin\MCST\Minecraft\Server;
class ServerController extends Controller { class ServerController extends Controller {
// GET create server route // 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); $view = Twig::fromRequest($request);
return $view->render($response, 'create.twig'); return $view->render($response, 'create.twig');
} }
// POST create server route // 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 // set up the POST parameters and grab our config
$params = (array)$request->getParsedBody(); $params = (array)$request->getParsedBody();
$config = $this->get('config'); $config = $this->get('config');

View File

@ -47,9 +47,9 @@ class Server {
// start the server // start the server
public function start(): void { 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); exec($command, $output);
// use lsof to // use lsof to find the PID of the server
$pidResult = exec('lsof ' . $this->rootDir . '/server*.jar | grep .jar'); $pidResult = exec('lsof ' . $this->rootDir . '/server*.jar | grep .jar');
$pid = preg_split('/\s+/', $pidResult, -1, PREG_SPLIT_NO_EMPTY)[1]; $pid = preg_split('/\s+/', $pidResult, -1, PREG_SPLIT_NO_EMPTY)[1];
@ -69,7 +69,7 @@ class Server {
exec('kill -15 ' . $pid); exec('kill -15 ' . $pid);
// set server state to false // set server state to false
$this->state = false; $this->state = false;
} }
} }
// get the server's PID // get the server's PID

View File

@ -14,9 +14,9 @@ class ServerConfig {
$this->config = array(); // initialize array $this->config = array(); // initialize array
// parse config file // parse config file
$fh = fopen($propertiesFile, 'r+'); $fileHandle = fopen($propertiesFile, 'r+');
while (!feof($fh)) { while (!feof($fileHandle)) {
$line = fgets($fh); $line = fgets($fileHandle);
$eqpos = strpos($line, '='); $eqpos = strpos($line, '=');
$parameterName = substr($line, 0, $eqpos); $parameterName = substr($line, 0, $eqpos);
$parameterValue = trim(substr($line, ($eqpos + 1))); $parameterValue = trim(substr($line, ($eqpos + 1)));
@ -36,9 +36,9 @@ class ServerConfig {
// update and save the server.properties file // update and save the server.properties file
$newFileContent = ''; $newFileContent = '';
$fh = fopen($this->propertiesFile, 'r+'); $fileHandle = fopen($this->propertiesFile, 'r+');
while (!feof($fh)) { while (!feof($fileHandle)) {
$line = fgets($fh); $line = fgets($fileHandle);
if (!str_starts_with($line, '#')) { if (!str_starts_with($line, '#')) {
$eqpos = strpos($line, '='); $eqpos = strpos($line, '=');
@ -58,7 +58,7 @@ class ServerConfig {
// save the new properties file // save the new properties file
file_put_contents($this->propertiesFile, $newFileContent); file_put_contents($this->propertiesFile, $newFileContent);
fclose($fh); fclose($fileHandle);
} }
} }

View File

@ -14,7 +14,7 @@ $config = Config::load(__DIR__ . '/../conf/defaults.json');
// Create new container object and add our config object to it // Create new container object and add our config object to it
$container = new Container(); $container = new Container();
$container->set('config', function() use ($config) { $container->set('config', function () use ($config) {
return $config; return $config;
}); });

View File

@ -3,7 +3,6 @@
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig; use Slim\Views\Twig;
use BitGoblin\MCST\Minecraft\Server; use BitGoblin\MCST\Minecraft\Server;
// index GET route - this page should welcome the user and direct them to the available actions // index GET route - this page should welcome the user and direct them to the available actions