diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..c7a20834 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,195 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + build-php: + name: Prepare PHP + runs-on: ${{ matrix.image }} + + strategy: + matrix: + image: [ubuntu-20.04] + php: [8.0.11] + + steps: + - name: Build and prepare PHP cache + uses: pmmp/setup-php-action@e232f72a4330a07aae8418e8aa56b64efcdda636 + with: + php-version: ${{ matrix.php }} + install-path: "./bin" + + phpstan: + name: PHPStan analysis + needs: build-php + runs-on: ${{ matrix.image }} + + strategy: + fail-fast: false + matrix: + image: [ubuntu-20.04] + php: [8.0.11] + + steps: + - name: Checkout PocketMine + uses: actions/checkout@v2 + with: + repository: pmmp/PocketMine-MP + submodules: true + ref: stable + path: "./" + + - name: Checkout Repo + uses: actions/checkout@v2 + with: + path: "./plugins/${{ github.event.repository.name }}" + + - name: Replace PocketMine Phpstan config + run: cp -f ./plugins/${{ github.event.repository.name }}/tests/phpstan.neon.dist phpstan.neon.dist + + - name: Delete poggit Phpstan config + run: rm -f ./plugins/${{ github.event.repository.name }}/phpstan.neon.dist + + - name: Setup PHP + uses: pmmp/setup-php-action@e232f72a4330a07aae8418e8aa56b64efcdda636 + with: + php-version: ${{ matrix.php }} + install-path: "./bin" + + - name: Install Composer + run: curl -sS https://getcomposer.org/installer | php + + - name: Restore Composer package cache + uses: actions/cache@v2 + with: + path: | + ~/.cache/composer/files + ~/.cache/composer/vcs + key: "composer-v2-cache-${{ matrix.php }}-${{ hashFiles('./composer.lock') }}" + restore-keys: | + composer-v2-cache- + + - name: Install Composer dependencies + run: php composer.phar install --prefer-dist --no-interaction + + - name: Run PHPStan + run: ./vendor/bin/phpstan analyze --no-progress --memory-limit=2G + +# phpunit: +# name: PHPUnit tests +# needs: build-php +# runs-on: ${{ matrix.image }} +# strategy: +# fail-fast: false +# matrix: +# image: [ubuntu-20.04] +# php: [8.0.11] +# +# steps: +# - name: Checkout PocketMine +# uses: actions/checkout@v2 +# with: +# repository: pmmp/PocketMine-MP +# submodules: true +# ref: stable +# path: "./" +# +# - name: Checkout Repo +# uses: actions/checkout@v2 +# with: +# path: "./plugins/${{ github.event.repository.name }}" +# +# - name: Setup PHP +# uses: pmmp/setup-php-action@e232f72a4330a07aae8418e8aa56b64efcdda636 +# with: +# php-version: ${{ matrix.php }} +# install-path: "./bin" +# +# - name: Install Composer +# run: curl -sS https://getcomposer.org/installer | php +# +# - name: Restore Composer package cache +# uses: actions/cache@v2 +# with: +# path: | +# ~/.cache/composer/files +# ~/.cache/composer/vcs +# key: "composer-v2-cache-${{ matrix.php }}-${{ hashFiles('./composer.lock') }}" +# restore-keys: | +# composer-v2-cache- +# +# - name: Install Composer dependencies +# run: php composer.phar install --prefer-dist --no-interaction +# +# - name: Run PHPUnit tests +# run: ./vendor/bin/phpunit --bootstrap vendor/autoload.php --fail-on-warning ./plugins/${{ github.event.repository.name }}/tests/phpunit + + integration: + name: Integration tests + needs: build-php + runs-on: ${{ matrix.image }} + strategy: + fail-fast: false + matrix: + image: [ubuntu-20.04] + php: [8.0.11] + + steps: + - name: Checkout PocketMine + uses: actions/checkout@v2 + with: + repository: pmmp/PocketMine-MP + submodules: true + ref: stable + path: "./" + + - name: Checkout Repo + uses: actions/checkout@v2 + with: + path: "./plugins/${{ github.event.repository.name }}" + + - name: Setup PHP + uses: pmmp/setup-php-action@e232f72a4330a07aae8418e8aa56b64efcdda636 + with: + php-version: ${{ matrix.php }} + install-path: "./bin" + + - name: Install Composer + run: curl -sS https://getcomposer.org/installer | php + + - name: Restore Composer package cache + uses: actions/cache@v2 + with: + path: | + ~/.cache/composer/files + ~/.cache/composer/vcs + key: "composer-v2-cache-${{ matrix.php }}-${{ hashFiles('./composer.lock') }}" + restore-keys: | + composer-v2-cache- + + - name: Install Composer dependencies + run: php composer.phar install --no-dev --prefer-dist --no-interaction + + - name: Run integration tests + run: chmod +x ./plugins/${{ github.event.repository.name }}/tests/integration-action.sh && ./plugins/${{ github.event.repository.name }}/tests/integration-action.sh -t4 + + codestyle: + name: Code Style checks + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP and tools + uses: shivammathur/setup-php@2.15.0 + with: + php-version: 8.0 + tools: php-cs-fixer:3.2 + + - name: Run PHP-CS-Fixer + run: php-cs-fixer fix --dry-run --diff diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 00000000..8eda195f --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,71 @@ +in(__DIR__ . '/src'); + +return (new PhpCsFixer\Config) + ->setRiskyAllowed(true) + ->setRules([ + 'align_multiline_comment' => [ + 'comment_type' => 'phpdocs_only' + ], + 'array_indentation' => true, + 'array_syntax' => [ + 'syntax' => 'short' + ], + 'blank_line_after_namespace' => true, + 'blank_line_after_opening_tag' => true, + 'blank_line_before_statement' => [ + 'statements' => [ + 'declare' + ] + ], + 'cast_spaces' => [ + 'space' => 'single' + ], + 'concat_space' => [ + 'spacing' => 'one' + ], + 'declare_strict_types' => true, + 'elseif' => true, + 'global_namespace_import' => [ + 'import_constants' => true, + 'import_functions' => true, + 'import_classes' => null, + ], + 'indentation_type' => true, + 'native_function_invocation' => [ + 'scope' => 'namespaced', + 'include' => ['@all'], + ], + 'no_closing_tag' => true, + 'no_empty_phpdoc' => true, + 'no_extra_blank_lines' => true, + 'no_superfluous_phpdoc_tags' => [ + 'allow_mixed' => true, + ], + 'no_trailing_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_whitespace_in_blank_line' => true, + 'no_unused_imports' => true, + 'ordered_imports' => [ + 'imports_order' => [ + 'class', + 'function', + 'const', + ], + 'sort_algorithm' => 'alpha' + ], + 'phpdoc_line_span' => [ + 'property' => 'single', + 'method' => null, + 'const' => null + ], + 'phpdoc_trim' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'single_import_per_statement' => true, + 'strict_param' => true, + ]) + ->setFinder($finder) + ->setIndent("\t") + ->setLineEnding("\n"); diff --git a/.travis.pmcommands.txt b/.travis.pmcommands.txt deleted file mode 100644 index 4251ecdc..00000000 --- a/.travis.pmcommands.txt +++ /dev/null @@ -1,5 +0,0 @@ -version -check-plugins -p help -p gen Plots -stop \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e74a75bc..00000000 --- a/.travis.yml +++ /dev/null @@ -1,44 +0,0 @@ -language: php -php: - - 7.3 -sudo: false - -before_script: - # - pecl install channel://pecl.php.net/pthreads-3.1.6 - - echo | pecl install channel://pecl.php.net/yaml-2.0.4 - - git clone https://github.com/pmmp/pthreads.git - - cd pthreads - - git checkout 1b7da492b944146fa9680f6399bd9c6c6c6095e0 - - phpize - - ./configure - - make - - make install - - cd .. - - echo "extension=pthreads.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - mkdir ${TRAVIS_BUILD_DIR}/../PocketMine - - cd ${TRAVIS_BUILD_DIR}/../PocketMine - - wget -O PocketMine-MP.phar "${1:-"https://jenkins.pmmp.io/job/PocketMine-MP/Stable/artifact/PocketMine-MP.phar"}" - - mkdir plugins - - cp ${TRAVIS_BUILD_DIR}/tests/PluginChecker.phar plugins/PluginChecker.phar - - mkdir unstaged - - php ${TRAVIS_BUILD_DIR}/tests/travisPluginTest.php unstaged - - cd ${TRAVIS_BUILD_DIR} - - chmod 777 ${TRAVIS_BUILD_DIR}/tests/travisScript.sh - - chmod 777 ${TRAVIS_BUILD_DIR}/tests/lint.sh - -script: - - ${TRAVIS_BUILD_DIR}/tests/lint.sh -p php -d ${TRAVIS_BUILD_DIR}/src/MyPlot - - cd ${TRAVIS_BUILD_DIR}/../PocketMine && ls - - ${TRAVIS_BUILD_DIR}/tests/travisScript.sh MyPlot MyPlot - - sed -i 's/world/Plots/' server.properties - - ${TRAVIS_BUILD_DIR}/tests/travisScript.sh MyPlot MyPlot - -deploy: - provider: releases - api_key: $GITHUB_TOKEN - file_glob: true - file: $TRAVIS_BUILD_DIR/../PocketMine/unstaged/MyPlot.phar - skip_cleanup: true - draft: true - on: - tags: true \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..0168a114 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,101 @@ +# MyPlot Contribution Guidelines + +MyPlot is an open source project, and contributions from the community are welcomed, as long as they comply with the quality standards and licensing. + +Code contributions must be submitted using [GitHub Pull Requests](https://github.com/jasonwynn10/MyPlot/pulls), where they will be reviewed by maintainers. + +Small contributions (e.g. minor bug fixes) can be submitted as pull requests directly. + +Larger contributions like feature additions should be preceded by a [Change Proposal](#rfcs--change-proposals) to allow maintainers and other people to discuss and decide if it's a good idea or not. + +## Useful documentation from github.com +- [About pull requests](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests) +- [About forks](https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/about-forks) +- [Creating a pull request from a fork](https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork) + +## Other things you'll need +- [git](https://git-scm.com/) + +## Making a pull request +The basic procedure to create a pull request is: +1. [Fork the repository on GitHub](https://github.com/jasonwynn10/MyPlot/fork). This gives you your own copy of the repository to make changes to. +2. Create a branch on your fork for your changes. +3. Make the changes you want to make on this branch. +4. You can then make a [pull request](https://github.com/jasonwynn10/MyPlot/pull/new) to the project. + +## Pull request reviews +Pull requests will be reviewed by maintainers when they are available. +Note that there might be a long wait time before a reviewer looks at your PR. + +Depending on the changes, maintainers might ask you to make changes to the PR to fix problems or to improve the code. +**Do not delete your fork** while your pull request remains open, otherwise you won't be able to make any requested changes and the PR will end up being declined. + +### Requirements +The following are required as a minimum for pull requests. PRs that don't meet these requirements will be declined unless updated to meet them. + +#### Licensing +MyPlot is licensed under [MIT license](LICENSE). +By proposing a pull request, you agree to your code being distributed within MyPlot under the same license. +If you take code from other projects, that code MUST be licensed under an MIT-compatible license. + +#### PRs should be about exactly ONE thing +If you want to make multiple changes, those changes should each be contributed as separate pull requests. **DO NOT** mix unrelated changes. + +#### PRs must not include unnecessary/unrelated changes +Do not include changes which aren't strictly necessary. This makes it harder to review a PR, because the code diff becomes larger and harder to review. +This means: +- don't reformat or rearrange existing code +- don't change things that aren't related to the PR's objective +- don't rewrite existing code just to make it "look nicer" +- don't change PhpDocs to native types in code you didn't write + +#### Tests must be provided +Where possible, PHPUnit tests should be written for new or changed code. +If that's not possible (e.g. for in-game functionality), the code must be tested manually and details of the tests done must be provided. +**Simply saying "Tested" is not acceptable** and will lead to your PR being declined. + +#### Comments and documentation must be written in American English +English is the shared languages of all current maintainers. + +#### Code must be in the MyPlot style +It's your responsibility to ensure your code matches the formatting and styling of the rest of the code. +If you use PhpStorm, a `Project` code style is provided, which you can use to automatically format new code. +You can also use [`php-cs-fixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer) to format your code. + +### Recommendations + +- **Do not edit code directly on github.com.** I recommend learning how to use [`git`](https://git-scm.com). `git` allows you to "clone" a repository onto your computer, so that you can make changes using an IDE. +- **Use an IDE, not a text editor.** I recommend PhpStorm or VSCode. +- **Create a new branch on your fork for each pull request.** This allows you to use the same fork to make multiple pull requests at the same time. +- **Use descriptive commit titles.** You can see an example [here](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). +- **Do not include multiple unrelated changes in one commit.** An atomic style for commits is preferred - this means that changes included in a commit should be part of a single distinct change set. See [this link](https://www.freshconsulting.com/atomic-commits/) for more information on atomic commits. See the [documentation on `git add`](https://git-scm.com/docs/git-add) for information on how to isolate local changes for committing. +- **Your pull request will be checked and discussed in due time.** Since the team is scattered all around the world, your PR may not receive any attention for some time. +- **Do not make large pull requests without an RFC.** Large changes should be discussed beforehand using the [RFC / Change Proposal](#rfcs--change-proposals) process. Large changes are much harder to review and are more likely to be declined if maintainers don't have a good idea what you're trying to do in advance. +- **Do not copy-paste code**. There are potential license issues implicit with copy-pasting, and copy-paste usually indicates a lack of understanding of the actual code. Copy-pasted code is obvious a mile off and **any PR like this is likely to be closed**. If you want to use somebody else's code from a Git repository, **use [GIT's cherry-pick feature](https://git-scm.com/docs/git-cherry-pick)** to cherry-pick the commit. + + +**Thanks for contributing to MyPlot!** + +## RFCs / Change Proposals +Change Proposals are issues or discussions which describe a new feature proposal or behavioural change. +They are used to get feedback from maintainers and the community about an idea for a change, to decide whether or not it's a good idea. + +### Submitting an RFC +RFCs should be submitted using Issues or Discussions. +RFCs _can_ be submitted as pull requests if you've already written the code, but this is not recommended, since it's not guaranteed that an RFC will pass, in which case your effort would be wasted. + +RFCs should include the following: +- A summary of what you want to change +- Why you want to change it (e.g. what problems it solves) +- Alternative methods you've considered to solve the problem. This should include any possible ways that what you want can be done without the change. + +### Voting on RFCs +Community members can vote on RFCs. This gives maintainers an idea of how popular the idea is. +Votes can be cast using :+1: and :-1: reactions. + +**Please don't downvote without providing a reason why!** + +### Implementing RFCs +Anyone can write the code to implement an RFC, and submit a pull request for it. It doesn't have to be the RFC author. + +Implementations should be submitted as pull requests. The pull request description must include a link to the RFC. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..3177ebc5 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,25 @@ +# Security Policy + +## Reporting a Vulnerability + +**DO NOT report vulnerabilities on the GitHub issue tracker.** +GitHub is public and anyone can see the issues you post on the issue tracker, including people who would exploit vulnerabilities for their own gain. + +**WARNING: You may put live servers at risk by reporting a vulnerability on the GitHub issue tracker.** + +**Contact me** by sending an email to [**jasonwynn10@me.com**](mailto:jasonwynn10@me.com?subject=Security%20Vulnerability%20in%20MyPlot). Include the following information: + +- Version of MyPlot +- Detailed description of the vulnerability (e.g. how to exploit it, what the effects are) + +Please note that I can't guarantee a reply to every email. + +## FAQ +### Do you offer a bug bounty? +No. + +### How soon can I expect a fix for a vulnerability I've reported? +This depends on the nature of the problem. I can't provide any general ETA (nor would it be wise to provide one). +In general, it depends on when I have time to look into the problem, how complex the problem is to fix, and how many users it impacts. + +When a fix for a severe vulnerability is pushed, a patch release for the target version will usually be released within 24 hours so that users can update. diff --git a/phpstan.neon.dist b/phpstan.neon.dist deleted file mode 100644 index d9d523da..00000000 --- a/phpstan.neon.dist +++ /dev/null @@ -1,9 +0,0 @@ -parameters: - level: 7 - paths: - - /source/src - scanDirectories: - - /source/src - - /deps - bootstrapFiles: - - phar:///pocketmine/PocketMine-MP.phar/vendor/autoload.php \ No newline at end of file diff --git a/tests/PluginChecker.phar b/tests/PluginChecker.phar deleted file mode 100644 index 0f2f39c8..00000000 Binary files a/tests/PluginChecker.phar and /dev/null differ diff --git a/tests/integration-action.sh b/tests/integration-action.sh new file mode 100644 index 00000000..e16a2833 --- /dev/null +++ b/tests/integration-action.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +PM_WORKERS="auto" + +while getopts "t:" OPTION 2> /dev/null; do + case ${OPTION} in + t) + PM_WORKERS="$OPTARG" + ;; + esac +done + +#Run-the-server tests +DATA_DIR="$(pwd)/test_data" +PLUGINS_DIR="$DATA_DIR/plugins" + +rm -rf "$DATA_DIR" +rm PocketMine-MP.phar 2> /dev/null +mkdir "$DATA_DIR" +mkdir "$PLUGINS_DIR" + +cd tests/plugins/DevTools +php -dphar.readonly=0 ./src/DevTools/ConsoleScript.php --make ./ --relative ./ --out "$PLUGINS_DIR/DevTools.phar" +cd ../../.. +composer make-server + +if [ -f PocketMine-MP.phar ]; then + echo Server phar created successfully. +else + echo Server phar was not created! + exit 1 +fi + +cp -r tests/plugins/TesterPlugin "$PLUGINS_DIR" +echo -e "stop\n" | php PocketMine-MP.phar --no-wizard --disable-ansi --disable-readline --debug.level=2 --data="$DATA_DIR" --plugins="$PLUGINS_DIR" --anonymous-statistics.enabled=0 --settings.async-workers="$PM_WORKERS" --settings.enable-dev-builds=1 + +output=$(grep '\[TesterPlugin\]' "$DATA_DIR/server.log") +if [ "$output" == "" ]; then + echo TesterPlugin failed to run tests, check the logs + exit 1 +fi + +result=$(echo "$output" | grep 'Finished' | grep -v 'PASS') +if [ "$result" != "" ]; then + echo "$result" + echo Some tests did not complete successfully, changing build status to failed + exit 1 +elif [ $(grep -c "ERROR\|CRITICAL\|EMERGENCY" "$DATA_DIR/server.log") -ne 0 ]; then + echo Server log contains error messages, changing build status to failed + exit 1 +else + echo All tests passed +fi diff --git a/tests/lint.sh b/tests/lint.sh deleted file mode 100644 index 6e5547f8..00000000 --- a/tests/lint.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -PHP_BINARY="php" -DIR="" -FIND="find" - -while getopts "p:d:f:" OPTION 2> /dev/null; do - case ${OPTION} in - p) - PHP_BINARY="$OPTARG" - ;; - d) - DIR="$OPTARG" - ;; - f) - FIND="$OPTARG" - ;; - esac -done - -if [ "$DIR" == "" ]; then - echo No directory specified - exit 1 -fi - -echo Running PHP lint scans on \"$DIR\"... - -OUTPUT=`$FIND "$DIR" -name "*.php" -print0 | xargs -0 -n1 -P4 "$PHP_BINARY" -l` - -if [ $? -ne 0 ]; then - echo $OUTPUT | grep -v "No syntax errors" - exit 1 -fi - -echo Lint scan completed successfully. diff --git a/tests/phpstan-baseline.neon b/tests/phpstan-baseline.neon new file mode 100644 index 00000000..91d532bf --- /dev/null +++ b/tests/phpstan-baseline.neon @@ -0,0 +1,167 @@ +parameters: + ignoreErrors: + - + message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/MyPlot.php + + - + message: "#^For loop initial assignment overwrites variable \\$X\\.$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/MyPlotGenerator.php + + - + message: "#^For loop initial assignment overwrites variable \\$x\\.$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/MyPlotGenerator.php + + - + message: "#^For loop initial assignment overwrites variable \\$z\\.$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/MyPlotGenerator.php + + - + message: "#^Method MyPlot\\\\forms\\\\ComplexMyPlotForm\\:\\:__construct\\(\\) has parameter \\$onSubmit with no signature specified for Closure\\.$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/forms/ComplexMyPlotForm.php + + - + message: "#^Method MyPlot\\\\forms\\\\SimpleMyPlotForm\\:\\:__construct\\(\\) has parameter \\$onClose with no signature specified for Closure\\.$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/forms/SimpleMyPlotForm.php + + - + message: "#^Method MyPlot\\\\forms\\\\SimpleMyPlotForm\\:\\:__construct\\(\\) has parameter \\$onSubmit with no signature specified for Closure\\.$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/forms/SimpleMyPlotForm.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\AddHelperSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/AddHelperSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\AutoSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/AutoSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\BiomeSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/BiomeSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\BuySubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/BuySubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\ClaimSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/ClaimSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\ClearSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/ClearSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\CloneSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/CloneSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\DenyPlayerSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/DenyPlayerSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\DisposeSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/DisposeSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\FillSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/FillSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\GiveSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/GiveSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\HomeSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/HomeSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\HomesSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/HomesSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\InfoSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/InfoSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\KickSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/KickSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\ListSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/ListSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\MergeSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/MergeSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\MiddleSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/MiddleSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\NameSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/NameSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\PvpSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/PvpSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\RemoveHelperSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/RemoveHelperSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\ResetSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/ResetSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\SellSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/SellSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\SetOwnerSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/SetOwnerSubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\UnDenySubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/UnDenySubCommand.php + + - + message: "#^Parameter \\#1 \\$sender \\(pocketmine\\\\Player\\) of method MyPlot\\\\subcommand\\\\WarpSubCommand\\:\\:execute\\(\\) should be contravariant with parameter \\$sender \\(pocketmine\\\\command\\\\CommandSender\\) of method MyPlot\\\\subcommand\\\\SubCommand\\:\\:execute\\(\\)$#" + count: 1 + path: plugins/MyPlot/src/MyPlot/subcommand/WarpSubCommand.php + diff --git a/tests/phpstan.neon.dist b/tests/phpstan.neon.dist new file mode 100644 index 00000000..7b5eaf9e --- /dev/null +++ b/tests/phpstan.neon.dist @@ -0,0 +1,40 @@ +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon + - vendor/phpstan/phpstan-strict-rules/rules.neon + - plugins/MyPlot/tests/phpstan-baseline.neon + +parameters: + level: 7 + checkMissingCallableSignature: true + treatPhpDocTypesAsCertain: false + bootstrapFiles: + - tests/phpstan/bootstrap.php + scanDirectories: + - src + - plugins + paths: + - plugins/MyPlot/src + dynamicConstantNames: + - pocketmine\DEBUG + - pocketmine\IS_DEVELOPMENT_BUILD + stubFiles: + - tests/phpstan/stubs/chunkutils.stub + - tests/phpstan/stubs/leveldb.stub + - tests/phpstan/stubs/pthreads.stub + reportUnmatchedIgnoredErrors: false #no other way to silence platform-specific non-warnings + staticReflectionClassNamePatterns: + - "#^COM$#" + typeAliases: + #variadics don't work for this - mixed probably shouldn't work either, but for now it does + #what we actually need is something that accepts an infinite number of parameters, but in the absence of that, + #we'll just fill it with 10 - it's very unlikely to encounter a callable with 10 parameters anyway. + anyCallable: 'callable(never, never, never, never, never, never, never, never, never, never) : mixed' + anyClosure: '\Closure(never, never, never, never, never, never, never, never, never, never) : mixed' + ignoreErrors: + - '*CustomForm*' + - '*MenuForm*' + - '*pmforms*' + - '*economyapi*' + - '*worldstyler*' + - '*EasyCommandAutofill*' \ No newline at end of file diff --git a/tests/travisPluginTest.php b/tests/travisPluginTest.php deleted file mode 100644 index 75ac185b..00000000 --- a/tests/travisPluginTest.php +++ /dev/null @@ -1,69 +0,0 @@ -\n"; -} -list($owner, $repo) = explode("/", getenv("TRAVIS_REPO_SLUG"), 2); -$sha = getenv("TRAVIS_COMMIT"); -$lastBuild = microtime(true); -for($i = 1; true; $i++) { - echo "Attempting to download CI build from Poggit (trial #$i)\n"; - $json = shell_exec("curl " . escapeshellarg("https://poggit.pmmp.io/ci.info?owner=$owner&repo=$repo&sha=$sha")); - $data = json_decode($json); - if($data === null) { - var_dump($json); - exit(1); - } - if(count($data) === 0) { - if(microtime(true) - $lastBuild > 120) { - if(isset($moreBuilds)) { - echo "[!] No new builds downloaded in two minutes! Supposedly, there should be $moreBuilds more builds to download. Poggit probably encountered build errors.\n"; - echo "[!] Prematurely stopped waiting for further Poggit builds. Progressing to testing...\n"; - exit(0); - } else { - echo "[!] No builds downloaded in two minutes! There is either no builds in this commit, or Poggit had build errors.\n"; - echo "[!] Prematurely stopped waiting for further Poggit builds. Nothing to test in this Travis build...\n"; - exit(1); - } - } - sleep(5); - echo "[*] Waiting for Poggit builds...\n"; - continue; - } - $moreBuilds = PHP_INT_MAX; - foreach($data as $datum) { - shell_exec("wget -O " . escapeshellarg($name = $target . $datum->projectName . ".phar") . " " . - escapeshellarg("https://poggit.pmmp.io/r/" . $datum->resourceId)); - echo "[*] Downloaded Poggit build for project: $name\n"; - $moreBuilds = min($moreBuilds, $datum->buildsAfterThis); - } - if($moreBuilds > 0) { - echo "[*] $moreBuilds more builds to download...\n"; - $lastBuild = microtime(true); - continue; - } else { - exit(0); - } -} diff --git a/tests/travisScript.sh b/tests/travisScript.sh deleted file mode 100644 index 2d12f70e..00000000 --- a/tests/travisScript.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -if [ "$1" == "" ]; then - echo Usage: travisScript.sh ' ' - exit 2 -fi -PLUGIN_NAME="$1" -cd "$TRAVIS_BUILD_DIR"/../PocketMine - -if [ "$2" == "" ]; then - PROJECT_NAME="$1" -else - PROJECT_NAME="$2" -fi - -echo Staging "$PROJECT_NAME".phar -cp unstaged/"$PROJECT_NAME".phar plugins/"$PROJECT_NAME".phar || (echo "Project $PROJECT_NAME is not built in this commit" && exit 0) - -echo Loading .travis.pmcommands.txt -pmcommands_file="$TRAVIS_BUILD_DIR"/.travis.pmcommands.txt -if [ ! -f "$pmcommands_file" ]; then - echo version >> "$pmcommands_file" - echo check-plugins >> "$pmcommands_file" -fi -egrep "^stop\$" "$pmcommands_file" || (echo stop >> "$pmcommands_file" && echo >> "$pmcommands_file") - -cmds_to_run="$(cat "$pmcommands_file")" -echo Running the following commands: -echo === -echo "$cmds_to_run" -echo === - -echo Server plugins directory: -ls plugins/*.phar -php PocketMine-MP.phar --no-wizard --enable-ansi --settings.asyncworker=2 --debug.level=2 --debug.commands=true --disable-readline --settings.enable-dev-builds=1 --pluginchecker.target="$PLUGIN_NAME" < "$pmcommands_file" | tee stdout.log - -rm plugins/"$PROJECT_NAME".phar - -if grep "PluginChecker passed" stdout.log >/dev/null; then - if grep "PluginChecker disabled fluently" stdout.log >/dev/null; then - echo Test passed - exit 0 - else - echo Server did not shutdown normally - exit 1 - fi -else - echo Plugin could not be loaded - exit 1 -fi