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

Implement PHP 8.1 features 🚀 #1183

Open
2 of 4 tasks
hemberger opened this issue Dec 9, 2021 · 0 comments
Open
2 of 4 tasks

Implement PHP 8.1 features 🚀 #1183

hemberger opened this issue Dec 9, 2021 · 0 comments

Comments

@hemberger
Copy link
Member

hemberger commented Dec 9, 2021

  • Replace phpdoc @return never with native never return type
  • Replace integer/string enumerations with native enum classes
  • Use readonly properties in data storage classes with no setter methods
  • Use first-class callable syntax
hemberger added a commit to hemberger/smr that referenced this issue Dec 9, 2021
This replaces the `@return never` docstring used by some CI tools.

Related to smrealms#1183.
hemberger added a commit that referenced this issue Dec 9, 2021
This replaces the `@return never` docstring used by some CI tools.

Related to #1183.
hemberger added a commit to hemberger/smr that referenced this issue Jan 3, 2022
The input argument typehint for `htmlspecialchars` is `string`, but
in the past it implicitly converted null to an empty string. However,
in PHP 8.1, this behavior is deprecated, and in the future it will
throw if passed anything other than a `string`.

Related to smrealms#1183.
hemberger added a commit to hemberger/smr that referenced this issue May 28, 2022
Related to smrealms#1183.

The readonly keyword helps us to enforce that fundamental properties
of a class do not change (such as the ID of a player, sector, account,
etc.). Once they are defined, they cannot be defined again.

Readonly properties that are passed into the constructor should also
use constructor promotion to further simplify their definition.

Additional notes:

* For attributes that are objects, readonly does _not_ mean constant.
  That is, while the object cannot be overwritten, its internal state
  can still be modified.

* For readonly properties that have an associated getter function, we
  can (and should) remove the getter and simply make the property
  public. This is logically equivalent, but with less overhead. We do
  not do this here because it is a massive change.
hemberger added a commit that referenced this issue May 28, 2022
Related to #1183.

The readonly keyword helps us to enforce that fundamental properties
of a class do not change (such as the ID of a player, sector, account,
etc.). Once they are defined, they cannot be defined again.

Readonly properties that are passed into the constructor should also
use constructor promotion to further simplify their definition.

Additional notes:

* For attributes that are objects, readonly does _not_ mean constant.
  That is, while the object cannot be overwritten, its internal state
  can still be modified.

* For readonly properties that have an associated getter function, we
  can (and should) remove the getter and simply make the property
  public. This is logically equivalent, but with less overhead. We do
  not do this here because it is a massive change.
hemberger added a commit to hemberger/smr that referenced this issue Jul 5, 2022
> Parameter #1 $callback of function spl_autoload_register expects
> (callable(string): void)|null, Closure(string): bool given.

Two changes were needed to match the parameter type expected by
PHPStan:

1. Promote the 'get_class_loc' string to first-class callable syntax
   (see smrealms#1183).

2. Remove the boolean return value from `get_class_loc`. This was a
   "speculative" feature added in 3f6854f, but it doesn't conform to
   the expected interface nor is it needed for the autoloader to throw
   an Error if the class is not found.
hemberger added a commit to hemberger/smr that referenced this issue Feb 4, 2023
Promote all remaining string-based callables to first-class callable
syntax. See smrealms#1183.

This refactoring was performed with rector.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant