⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

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.

@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
/**
* Yield the query's results
*
* @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.

Instead of using the type \Generator add a use statement
so that docstrings and return types can be cleaned up.
Since the implementation will return at least an empty array
null can be removed from the type.
Since model is nullable in the constructor the getModel() return type
must allow null.
The removed test previously expected an InvalidArgumentException,
which became obsolete with the addition of typed parameters
so the test is no longer necessary.
All usages are compatible with the bool type,
so the parameter is typed as bool and the cast is removed.
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