Skip to content

Modernize code#155

Open
BastianLedererIcinga wants to merge 6 commits intomainfrom
modernize-code
Open

Modernize code#155
BastianLedererIcinga wants to merge 6 commits intomainfrom
modernize-code

Conversation

@BastianLedererIcinga
Copy link
Contributor

@BastianLedererIcinga BastianLedererIcinga commented Dec 9, 2025

  • Add property, parameter and return types.
  • Replace return type self with static.
  • Some InvalidArgumentExceptions became obsolete by the new parameter types, unit tests have been adjusted to expect a TypeError instead.

Code that requires compatibility changes in modules is not modernized by this PR.

@cla-bot cla-bot bot added the cla/signed label Dec 9, 2025
@BastianLedererIcinga BastianLedererIcinga changed the base branch from main to 8.4/8.5-compatibility December 9, 2025 13:28
@BastianLedererIcinga BastianLedererIcinga marked this pull request as ready for review December 9, 2025 13:30
Jan-Schuppik
Jan-Schuppik previously approved these changes Dec 10, 2025
@BastianLedererIcinga BastianLedererIcinga force-pushed the 8.4/8.5-compatibility branch 3 times, most recently from 40c7f0b to be36f28 Compare December 18, 2025 14:17
Base automatically changed from 8.4/8.5-compatibility to main January 7, 2026 12:55
@lippserd lippserd dismissed stale reviews from sukhwinder33445 and Jan-Schuppik January 7, 2026 12:55

The base branch was changed.

src/Query.php Outdated
* @return $this
*/
public function peekAhead($peekAhead = true)
public function peekAhead($peekAhead = true): static
Copy link
Member

Choose a reason for hiding this comment

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

Can this be bool $peekAhead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've checked out all usages, the only cases where this could end up not being a bool are in some controllers like this one:
https://github.com/Icinga/icingaweb2-module-x509/blob/81b7e5b6611e5a0c09bb19faca194583a79b462c/application/controllers/UsageController.php#L88
Where view->compact is passed, which could technically return null or some other type. The ActionController always initializes this property with a bool in the constructor and all reassignments also use bool values. When testing the affected controllers in the UI everything worked fine aswell, so I suppose we can type the parameter as bool.

src/Query.php Outdated
@@ -704,7 +700,7 @@ public function peekAhead($peekAhead = true)
*
* @return \Generator
Copy link
Member

Choose a reason for hiding this comment

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

You can simplify this to Generator.

src/Relation.php Outdated
* @return \Generator
*/
public function resolve()
public function resolve(): \Generator
Copy link
Member

Choose a reason for hiding this comment

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

Add use statement and simplify both PHPDoc and return type to Generator.

}

public function resolve()
public function resolve(): \Generator
Copy link
Member

Choose a reason for hiding this comment

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

Add use statement.

* @return ?Query[]
*/
public function getUnions()
public function getUnions(): ?array
Copy link
Member

Choose a reason for hiding this comment

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

This method does not return null, does it?

$this->assertSame($targetClass, $relation->getTargetClass());
}

public function testSetTargetClassThrowsInvalidArgumentExceptionIfNotString()
Copy link
Member

Choose a reason for hiding this comment

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

This test can be removed because we are no longer testing an implementation detail, but PHP itself.

/** @var Model The target model */
protected $model;
/** @var ?Model The target model */
protected ?Model $model;
Copy link
Member

Choose a reason for hiding this comment

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

I think it always makes sense to initialize nullable properties with null, as you do everywhere else. Even here, where the constructor sets the property.

Comment on lines +47 to +49
* @return Model
*/
public function getModel()
public function getModel(): Model
Copy link
Member

Choose a reason for hiding this comment

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

This method may return null.

Copy link
Contributor

@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.

  1. I think we can define return types for PersistBehavior|RetrieveBehavior interfaces, as they are not overridden by any other module.
  2. Please use [...] instead of list()
  3. Please import the class instead of using qualifier in PropertiesWithDefaults (line 10-11).
  4. Please remove the unused variable $err in MillisecondTimestamp.

Note for myself:
The following classes and interfaces have not yet been modernized, as they are overridden by some modules (TBD):
Classes:

  • PropertyBehavior
  • Binary|BoolCast|MillisecondTimestamp
  • Model
  • UnionModel
  • ResultSet
  • Relation (partially)
  • Query (Partially)

Interfaces:

  • QueryAwareBehavior
  • RewriteColumnBehavior
  • RewriteFilterBehavior

Copy link
Contributor

@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.
Please use backticks in the commits to highlight function, class, interface, etc. names.

@BastianLedererIcinga BastianLedererIcinga force-pushed the modernize-code branch 2 times, most recently from 28bd4f2 to 1a6a329 Compare March 3, 2026 13:46
BastianLedererIcinga added a commit to Icinga/icinga-notifications-web that referenced this pull request Mar 4, 2026
Add types and missing return statements for implementations of:
* `QueryAwarebehavior`
* `RewriteFilterbehavior`

To ensure compatibility with Icinga/ipl-orm#155.

Add types to `ContactForm::isValidEent()` as required by
Icinga/ipl-stdlib#68
@BastianLedererIcinga BastianLedererIcinga force-pushed the modernize-code branch 4 times, most recently from e1d1c36 to 9734f88 Compare March 4, 2026 12:42
Add strict type declarations to properties, function/method signatures, where
types are unambiguous and no inheritance  or interface contract is affected.
@BastianLedererIcinga BastianLedererIcinga force-pushed the modernize-code branch 2 times, most recently from 59f2fe9 to 9b944e8 Compare March 5, 2026 08:11
sukhwinder33445
sukhwinder33445 previously approved these changes Mar 5, 2026
Copy link
Contributor

@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, please take a look.

sukhwinder33445
sukhwinder33445 previously approved these changes Mar 5, 2026
Where functions are already adjusted and `throws` tags are missing
they are added
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.

4 participants