From 8db5732b44578a59c785e6e3c1d36c87c90ddeb4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 15 Oct 2021 17:15:46 +0100 Subject: [PATCH] Drop respect/validation it's not worth this turning into compatibility baggage just so that we can parse plugin_list.yml, especially when we have new ways to handle data parsing coming in the pipeline. For something as small as plugin_list.yml, it's easier (and in this case better too) to just validate it manually (respect/validation was anyway too strict considering it's YAML we're dealing with). --- composer.json | 1 - composer.lock | 206 +----------------- src/plugin/PluginGraylist.php | 42 ++-- .../check-explicit-mixed-baseline.neon | 5 - 4 files changed, 25 insertions(+), 229 deletions(-) diff --git a/composer.json b/composer.json index 05f575214..167149a72 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,6 @@ "pocketmine/snooze": "^0.3.0", "pocketmine/spl": "dev-master", "ramsey/uuid": "^4.1", - "respect/validation": "^2.0", "webmozart/path-util": "^2.3" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 4286906a6..fe195368c 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": "c7a00c5a35d43f307fdba7a588029131", + "content-hash": "39ec9b1c108888c32a660f3bc2c400c4", "packages": [ { "name": "adhocore/json-comment", @@ -1011,130 +1011,6 @@ ], "time": "2021-09-25T23:10:38+00:00" }, - { - "name": "respect/stringifier", - "version": "0.2.0", - "source": { - "type": "git", - "url": "https://github.com/Respect/Stringifier.git", - "reference": "e55af3c8aeaeaa2abb5fa47a58a8e9688cc23b59" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Respect/Stringifier/zipball/e55af3c8aeaeaa2abb5fa47a58a8e9688cc23b59", - "reference": "e55af3c8aeaeaa2abb5fa47a58a8e9688cc23b59", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^2.8", - "malukenho/docheader": "^0.1.7", - "phpunit/phpunit": "^6.4" - }, - "type": "library", - "autoload": { - "psr-4": { - "Respect\\Stringifier\\": "src/" - }, - "files": [ - "src/stringify.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Respect/Stringifier Contributors", - "homepage": "https://github.com/Respect/Stringifier/graphs/contributors" - } - ], - "description": "Converts any value to a string", - "homepage": "http://respect.github.io/Stringifier/", - "keywords": [ - "respect", - "stringifier", - "stringify" - ], - "support": { - "issues": "https://github.com/Respect/Stringifier/issues", - "source": "https://github.com/Respect/Stringifier/tree/0.2.0" - }, - "time": "2017-12-29T19:39:25+00:00" - }, - { - "name": "respect/validation", - "version": "2.2.3", - "source": { - "type": "git", - "url": "https://github.com/Respect/Validation.git", - "reference": "4c21a7ffc9a4915673cb2c2843963919e664e627" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Respect/Validation/zipball/4c21a7ffc9a4915673cb2c2843963919e664e627", - "reference": "4c21a7ffc9a4915673cb2c2843963919e664e627", - "shasum": "" - }, - "require": { - "php": "^7.3 || ^8.0", - "respect/stringifier": "^0.2.0", - "symfony/polyfill-mbstring": "^1.2" - }, - "require-dev": { - "egulias/email-validator": "^3.0", - "malukenho/docheader": "^0.1", - "mikey179/vfsstream": "^1.6", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-deprecation-rules": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^9.3", - "psr/http-message": "^1.0", - "respect/coding-standard": "^3.0", - "squizlabs/php_codesniffer": "^3.5", - "symfony/validator": "^3.0||^4.0", - "zendframework/zend-validator": "^2.1" - }, - "suggest": { - "egulias/email-validator": "Strict (RFC compliant) email validation", - "ext-bcmath": "Arbitrary Precision Mathematics", - "ext-fileinfo": "File Information", - "ext-mbstring": "Multibyte String Functions", - "symfony/validator": "Use Symfony validator through Respect\\Validation", - "zendframework/zend-validator": "Use Zend Framework validator through Respect\\Validation" - }, - "type": "library", - "autoload": { - "psr-4": { - "Respect\\Validation\\": "library/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Respect/Validation Contributors", - "homepage": "https://github.com/Respect/Validation/graphs/contributors" - } - ], - "description": "The most awesome validation engine ever created for PHP", - "homepage": "http://respect.github.io/Validation/", - "keywords": [ - "respect", - "validation", - "validator" - ], - "support": { - "issues": "https://github.com/Respect/Validation/issues", - "source": "https://github.com/Respect/Validation/tree/2.2.3" - }, - "time": "2021-03-19T14:12:45+00:00" - }, { "name": "symfony/polyfill-ctype", "version": "v1.23.0", @@ -1214,86 +1090,6 @@ ], "time": "2021-02-19T12:13:01+00:00" }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.23.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9174a3d80210dca8daa7f31fec659150bbeabfc6", - "reference": "9174a3d80210dca8daa7f31fec659150bbeabfc6", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "suggest": { - "ext-mbstring": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for the Mbstring extension", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.23.1" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-05-27T12:26:48+00:00" - }, { "name": "symfony/polyfill-php80", "version": "v1.23.1", diff --git a/src/plugin/PluginGraylist.php b/src/plugin/PluginGraylist.php index 34aad55f1..cd6287f82 100644 --- a/src/plugin/PluginGraylist.php +++ b/src/plugin/PluginGraylist.php @@ -23,15 +23,11 @@ declare(strict_types=1); namespace pocketmine\plugin; -use Respect\Validation\Exceptions\NestedValidationException; -use Respect\Validation\Rules\AllOf; -use Respect\Validation\Rules\ArrayType; -use Respect\Validation\Rules\Each; -use Respect\Validation\Rules\In; -use Respect\Validation\Rules\Key; -use Respect\Validation\Rules\StringType; -use Respect\Validation\Validator; use function array_flip; +use function is_array; +use function is_float; +use function is_int; +use function is_string; class PluginGraylist{ @@ -70,17 +66,27 @@ class PluginGraylist{ * @param mixed[] $array */ public static function fromArray(array $array) : PluginGraylist{ - $validator = new Validator( - new Key("mode", new In(['whitelist', 'blacklist'], true), true), - new Key("plugins", new AllOf(new ArrayType(), new Each(new StringType())), true) - ); - $validator->setName('plugin_list.yml'); - try{ - $validator->assert($array); - }catch(NestedValidationException $e){ - throw new \InvalidArgumentException($e->getFullMessage(), 0, $e); + if(!isset($array["mode"]) || ($array["mode"] !== "whitelist" && $array["mode"] !== "blacklist")){ + throw new \InvalidArgumentException("\"mode\" must be set"); } - return new PluginGraylist($array["plugins"], $array["mode"] === 'whitelist'); + $isWhitelist = match($array["mode"]){ + "whitelist" => true, + "blacklist" => false, + default => throw new \InvalidArgumentException("\"mode\" must be either \"whitelist\" or \"blacklist\"") + }; + $plugins = []; + if(isset($array["plugins"])){ + if(!is_array($array["plugins"])){ + throw new \InvalidArgumentException("\"plugins\" must be an array"); + } + foreach($array["plugins"] as $k => $v){ + if(!is_string($v) && !is_int($v) && !is_float($v)){ + throw new \InvalidArgumentException("\"plugins\" contains invalid element at position $k"); + } + $plugins[] = (string) $v; + } + } + return new PluginGraylist($plugins, $isWhitelist); } /** diff --git a/tests/phpstan/configs/check-explicit-mixed-baseline.neon b/tests/phpstan/configs/check-explicit-mixed-baseline.neon index 5591d54c8..d8bb79fb2 100644 --- a/tests/phpstan/configs/check-explicit-mixed-baseline.neon +++ b/tests/phpstan/configs/check-explicit-mixed-baseline.neon @@ -135,11 +135,6 @@ parameters: count: 1 path: ../../../src/plugin/PluginDescription.php - - - message: "#^Parameter \\#1 \\$plugins of class pocketmine\\\\plugin\\\\PluginGraylist constructor expects array\\, mixed given\\.$#" - count: 1 - path: ../../../src/plugin/PluginGraylist.php - - message: "#^Parameter \\#2 \\$code of class pocketmine\\\\resourcepacks\\\\ResourcePackException constructor expects int, mixed given\\.$#" count: 1