forked from smrealms/smr
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scrutinizer Auto-Fixes #2
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
hemberger
added a commit
that referenced
this pull request
Jun 14, 2021
We need to be able to get the session var before we process any pages, but it is during page processing where we set the session var. Thus, we need to initialize the session var to an empty Page (as a kind of bootstrapping strategy). This fixes the following error: > Error Message: ErrorException: Undefined array key "" in /smr/src/lib/Smr/Session.php:259 > Stack trace: > #0 /smr/src/lib/Smr/Session.php(259): exception_error_handler(2, 'Undefined array...', '/smr/src/lib/Sm...', 259) > #1 /smr/src/lib/Default/AbstractSmrPlayer.class.php(2169): Smr\Session->getCurrentVar() > #2 /smr/src/tools/npc/npc.php(140): AbstractSmrPlayer->removeUnderAttack() > #3 /smr/src/tools/npc/npc.php(91): NPCStuff() > #4 {main}
hemberger
added a commit
that referenced
this pull request
Jun 14, 2021
The shop_hardware_processing.php script forwards the current LocationID in the session var to the next page. This was not being set as part of the preparation in npc.php (because the LocationID is not needed by anything the NPC does, i.e. no subsequent display page). However, it is no significant burden to provide this, so we pass along the sector ID to the `doUNO` function. Fixes the following error: > Error Message: Exception: Could not find "LocationID" in var! in /smr/src/lib/Default/Page.class.php:166 > Stack trace: > #0 /smr/src/engine/Default/shop_hardware_processing.php(64): Page->addVar('LocationID') > #1 /smr/src/lib/Default/Page.class.php(231): require('/smr/src/engine...') > #2 /smr/src/lib/Default/smr.inc.php(372): Page->process() > #3 /smr/src/tools/npc/npc.php(352): do_voodoo() > #4 /smr/src/tools/npc/npc.php(176): processContainer(Object(Page)) > #5 /smr/src/tools/npc/npc.php(91): NPCStuff() > #6 {main}
hemberger
added a commit
that referenced
this pull request
Aug 20, 2021
Use `IFloor` instead of `floor` to compute the amount of each hardware to buy so that we have an int instead of a float. Fixes: > TypeError: doUNO(): Argument #2 ($amount) must be of type int, float given
hemberger
added a commit
that referenced
this pull request
Jul 5, 2022
> Parameter #2 $enable of function stream_set_blocking expects bool, int given. Pass bools instead of implicity converting ints to bools.
hemberger
added a commit
that referenced
this pull request
Aug 8, 2022
Use a more precise algorithm to randomize the output of this function. Previously, we could not guarantee that the sum of the "normalized" weights was an integer value, and so the range of the random number would not necessarily cover the sum of the weights. Now, we properly normalize between 0 and 1, and choose a random number between 0 and 1. Fixes PHPStan warning: > Parameter #2 $max of function rand expects int, float|int given.
hemberger
added a commit
that referenced
this pull request
Aug 8, 2022
By assigning to `$name` before qualifying the type of `$messagePlayer`, we have made it much harder for PHPStan to determine what type `$name` has. We can simply defer assigning to `$name`. No functionality changes. Fixes PHPStan warnings: > Parameter #2 $text of function create_link expects string, SmrPlayer|string given. > Anonymous function should return string but returns SmrPlayer|string.
hemberger
added a commit
that referenced
this pull request
Jan 8, 2023
Rather than tell PHPStan that elements 2 and 4 of a string like "b2b3" are numeric strings, we can explicitly validate to a more narrow type with `str2int`. This also means we don't need to rely on the behavior of string and integer arithmetic. Fixes PHPStan warnings: > Parameter #2 $y of method Smr\Chess\ChessGame::tryMove() expects int, float|int given. > Parameter #4 $toY of method Smr\Chess\ChessGame::tryMove() expects int, float|int given.
hemberger
added a commit
that referenced
this pull request
Jan 8, 2023
When remapping warps, we expect to find the old warp ID in the sector mapping. If it is not found, provide a helpful Exception message. Fixes PHPStan warning: > Parameter #2 $sectorID of static method SmrSector::getSector() expects int, int<1, max>|false given.
hemberger
added a commit
that referenced
this pull request
Jan 17, 2023
The return type of `getHotkeys` has a direct relationship to the value of the input `$hotkeyType` argument. Use PHPStan conditional return typehints to make that relationship explicit. Fixes PHPStan warnings: > Parameter #2 $array of function implode expects array<string>, array<array<string>|string> given.
hemberger
added a commit
that referenced
this pull request
Feb 9, 2023
The rest of this script assumes that `preg_replace` succeeds (i.e. does not return null). Therefore, guard against it with an Exception. Fixes many PHPStan warnings of the form: > Parameter #2 $rdata of function server_ping expects string, string|null given.
hemberger
added a commit
that referenced
this pull request
Feb 9, 2023
This allows the page to display even if there are no valid games for which NPCs can be created, since we expect the game ID to be an int, and there is never a real game ID of 0. Alternatively, we could have skipped a lot of the logic if the game ID was null, but that is a more involved refactor (which creates other problems with conditionally defined template variables). Fixes PHPStan warnings: > Parameter #1 $selectedGameID of class Smr\Pages\Admin\NpcManageAddAccountProcessor constructor expects int, int|null given. > Parameter $selectedGameID of class Smr\Pages\Admin\NpcManageProcessor constructor expects int, int|null given. > Parameter #2 $gameID of static method Smr\AbstractPlayer::getPlayer() expects int, int|null given.
hemberger
added a commit
that referenced
this pull request
Feb 9, 2023
This allows the page to display even if there are no valid games for which NPCs can be created, since we expect the game ID to be an int, and there is never a real game ID of 0. Alternatively, we could have skipped a lot of the logic if the game ID was null, but that is a more involved refactor (which creates other problems with conditionally defined template variables). Fixes PHPStan warnings: > Parameter #1 $selectedGameID of class Smr\Pages\Admin\NpcManageAddAccountProcessor constructor expects int, int|null given. > Parameter $selectedGameID of class Smr\Pages\Admin\NpcManageProcessor constructor expects int, int|null given. > Parameter #2 $gameID of static method Smr\AbstractPlayer::getPlayer() expects int, int|null given.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@hemberger requested this pull request.
It consists of patches automatically generated for this project on Scrutinizer:
https://scrutinizer-ci.com/g/smrealms/smr/