Skip to content

Modernize code#63

Open
sukhwinder33445 wants to merge 9 commits intomainfrom
modernize-code
Open

Modernize code#63
sukhwinder33445 wants to merge 9 commits intomainfrom
modernize-code

Conversation

@sukhwinder33445
Copy link
Contributor

@sukhwinder33445 sukhwinder33445 commented Dec 9, 2025

Add PHP 8.2+ type declarations across codebase

This PR adds comprehensive type declarations to the entire codebase, enabling modern PHP type system features and improving static analysis capabilities. It also modernizes the codebase to require PHP 8.2 or later.

Changes

Type System Improvements

  • Parameter type declarations: Added type hints to all method parameters matching PHPDoc annotations
  • Return type declarations: Added return types to all methods for better type safety
  • Property type declarations: Added typed properties throughout the codebase
  • Simplified union types: Replaced overly specific PHPDoc union types with mixed where appropriate (e.g., array<mixed>|bool|float|int|stringmixed)

Code Refactoring

  • Converted legacy switch/case statements to modern match expressions in Filter::performMatch()
  • Removed redundant runtime type validation that is now enforced by the type system
  • Replaced self return type with static for better fluent interface support
  • Updated nullable property declarations with proper initialization

Interface Updates

  • Added type declarations to all contract interfaces (Filterable, Paginatable, PluginLoader, Translator)
  • Standardized return types across interface implementations
  • Added ?string type hints for optional context parameters

Minimum Version Requirement

  • Updated composer.json to require PHP 8.2 or later
  • This enables use of typed properties, match expressions, and union types

Breaking Changes

Requires PHP 8.2+ - Projects using PHP 7.x will need to upgrade

The following classes and interfaces have not been modernized because they have dependencies

  • ipl\Stdlib\Contract\Validator
    (to many overrides)
  • ipl\Stdli\Events::on($event, callable $listener): static
    (parameter $event stays without type to match the definition of the interface Evenement\EventEmitterInterface)
  • ipl\Stdlib\Messages::getMessage()
    (without return type to match the definition of the interface ipl\Stdlib\Contract\Validator)

Copy link

@BastianLedererIcinga BastianLedererIcinga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type of BaseFilter::setBaseFilter can be changed to static.

@sukhwinder33445 sukhwinder33445 force-pushed the support-php-85 branch 2 times, most recently from 6408fa8 to d67ed2a Compare December 12, 2025 07:44
Base automatically changed from support-php-85 to main January 7, 2026 14:54
@lippserd lippserd dismissed BastianLedererIcinga’s stale review January 7, 2026 14:54

The base branch was changed.

@sukhwinder33445
Copy link
Contributor Author

Please rebase.

@sukhwinder33445
Copy link
Contributor Author

ipl\Stdlib\Messages::getMessage()
(without return type to match the definition of the interface ipl\Stdlib\Contract\Validator)

I assume you mean the getMessages() method. However, it already declares a return type in both the mentioned trait and the interface. Since both are part of ipl-stdlib, the return type can be added there.

Copy link
Contributor Author

@sukhwinder33445 sukhwinder33445 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything else looks good to me.

@sukhwinder33445
Copy link
Contributor Author

ipl\Stdlib\Messages::getMessage()
(without return type to match the definition of the interface ipl\Stdlib\Contract\Validator)

I assume you mean the getMessages() method. However, it already declares a return type in both the mentioned trait and the interface. Since both are part of ipl-stdlib, the return type can be added there.

Please ignore, we cannot add a return type to getMessages() as it would require changes in the imedge module, which we do not maintain.

Copy link
Contributor Author

@sukhwinder33445 sukhwinder33445 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Jan-Schuppik and others added 9 commits March 13, 2026 14:14
Add strict type declarations to properties, function/method signatures, where
types are unambiguous and no inheritance is affected. Remove any now
superfluous type checks.

PHPDoc adjusted: nullable shorthand, union type ordering, compact format.

Raise minimum PHP version to 8.0.

Co-authored-by: Eric Lippmann <eric.lippmann@icinga.com>
Raise minimum PHP version to 8.2.

Co-authored-by: Eric Lippmann <eric.lippmann@icinga.com>
This change requires adjustments to the following consumers:

ipl-html:
    - src/Contract/FormElement.php

PHPDoc adjusted: nullable shorthand, union type ordering, compact format.
This change requires adjustments to the following consumers:

ipl-orm:
    - src/Common/PropertiesWithDefaults.php
This change requires adjustments to the following consumers:

ipl-sql
    - src/Cursor.php
    - src/LimitOffset.php

PHPDoc adjusted: nullable shorthand, union type ordering, compact format.
This change requires adjustments to the following consumers:

ipl-i18n
    - src/GettextTranslator.php
    - src/NoopTranslator.php

PHPDoc adjusted: nullable shorthand, union type ordering, compact format.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants