Skip to content

Add strict type declarations and modernize codebase#63

Merged
lippserd merged 10 commits intomainfrom
modernize-code
Mar 24, 2026
Merged

Add strict type declarations and modernize codebase#63
lippserd merged 10 commits intomainfrom
modernize-code

Conversation

@sukhwinder33445
Copy link
Contributor

@sukhwinder33445 sukhwinder33445 commented Dec 9, 2025

Add strict type declarations to all method parameters, return types,
and properties throughout the codebase. Remove redundant runtime type
checks now enforced by the type system. Update PHPDoc to use nullable
shorthand, consistent union type ordering, and compact format.

Replace list() with array destructuring, switch/case with match
expressions, and self return types with static for better fluent
interface support.

Breaking changes — consumers of the following APIs require updates:

  • Translator (ipl-i18n: GettextTranslator, NoopTranslator)
  • Paginatable (ipl-sql: Cursor, LimitOffset)
  • Messages::addMessage() (ipl-html: Contract/FormElement)
  • Properties::getProperty() (ipl-orm: Common/PropertiesWithDefaults)
  • Raise the minimum PHP version to 8.2

Intentionally left without type declarations:

  • Validator interface: too many overrides in consumers
  • Events::on(): must match Evenement\EventEmitterInterface
  • Messages::getMessage(): must match Validator interface

closes #30

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.

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.

@lippserd lippserd force-pushed the modernize-code branch 3 times, most recently from 4a6fb1e to a5d07c8 Compare March 19, 2026 13:24
Jan-Schuppik and others added 8 commits March 19, 2026 14:46
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.
@lippserd lippserd added this to the v0.15.0 milestone Mar 19, 2026
@lippserd lippserd changed the title Modernize code Add strict type declarations and modernize codebase Mar 20, 2026
Copy link
Contributor

@jrauh01 jrauh01 left a comment

Choose a reason for hiding this comment

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

I have some change suggestions.

@lippserd
Copy link
Member

I have some change suggestions.

You can push your changes directly as a single commit, if you want.

- Replace `array_search() !== false` with `in_array()` in `Chain::has()`
- Replace null-check-and-assign with `??=` in `MetaData::metaData()`
- Replace if/else variable assignment with ternary in `Plugins::createLoader()`
- Replace `isset($a[$k]) ? $a[$k] : null` with `$a[$k] ?? null` in `Seq::findByKey()`
- Replace manual `substr()` prefix check with `str_starts_with()` in `Str::startsWith()`
- Collapse if/else around `explode()` into a single ternary in `Str::trimSplit()`
- Replace if/else with ternary in `get_php_type()`
- Drop unused loop key in `iterable_value_first()`
@lippserd lippserd changed the title Add strict type declarations and modernize codebase Add strict type declarations and modernize codebase Mar 24, 2026
@lippserd lippserd merged commit 5049aa2 into main Mar 24, 2026
13 checks passed
@lippserd lippserd deleted the modernize-code branch March 24, 2026 16:30
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.

5 participants