Skip to content
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 #3

Merged
merged 1 commit into from
Jan 8, 2020
Merged

Scrutinizer Auto-Fixes #3

merged 1 commit into from
Jan 8, 2020

Conversation

scrutinizer-auto-fixer
Copy link
Collaborator

@hemberger requested this pull request.

It consists of patches automatically generated for this project on Scrutinizer:
https://scrutinizer-ci.com/g/smrealms/smr/

This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
@hemberger hemberger merged commit cf9c96c into dangling-if Jan 8, 2020
@hemberger hemberger deleted the scrutinizer-patch-1 branch January 8, 2020 10:34
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 Jan 10, 2023
This was using the wrong interface to SmrSector::getSector, resulting
in forcing an update of the cache unexpectedly due to the implicit type
conversion from int to bool. This bug is as old as the repo.

Now that we are using strict types, this invalid call throws, and so we
fix it to prevent the erroneous forced update.

Fixes PHPStan warning:

> Parameter #3 $forceUpdate of static method SmrSector::getSector() expects bool, int given.
hemberger added a commit that referenced this pull request Jan 11, 2023
This was using the wrong interface to SmrSector::getSector, resulting
in forcing an update of the cache unexpectedly due to the implicit type
conversion from int to bool. This bug is as old as the repo.

Now that we are using strict types, this invalid call throws, and so we
fix it to prevent the erroneous forced update.

Fixes PHPStan warning:

> Parameter #3 $forceUpdate of static method SmrSector::getSector() expects bool, int given.
hemberger added a commit that referenced this pull request Feb 9, 2023
Use `str_ireplace` to perform word replacements instead of using
`preg_replace`. This has a bunch of benefits:

* The interface is much simpler, because arrays of search/replace terms
  can be input.

* The `str_ireplace` function cannot error, unlike `preg_replace`.

* In the live database, some of the search terms used regex characters,
  but were intended to be interpreted literally. With `str_ireplace`,
  all search terms are literals.

Fixes PHPStan warnings:

> Parameter #3 $subject of function preg_replace expects array|string, string|null given.
> Function word_filter() should return string but returns string|null.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants