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

Update README.md #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sebastianstucke87
Copy link
Contributor

Updated code style:

  • strict_types
  • final readonly class
  • promoted properties
  • void return
  • NullLogger instead of dealing with null (thereby removing the null-pointer exception I added in 2019...)
  • handle \Throwable
  • short-array syntax

Updated code style:
- strict_types
- final readonly class
- promoted properties
- NullLogger instead of dealing with null (thereby removing the null-pointer exception I added in 2019...)
- handle \Throwable
- short-array syntax
{
$this->logger = $logger;
}
$this->logger->info('Doing work');
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want to do modern PHP, IMO it's best to leave $logger nullable and call it conditionally with:

Suggested change
$this->logger->info('Doing work');
$this->logger?->info('Doing work');

That avoids useless method calls and a useless NullLogger instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depends.

That means:

  • having your code riddled with "?->"
  • depending on a static code analysis tool (like PHPStan or Psalm) to prevent nullpointer exceptions

I think this is more a question of deprecating "NullLogger" or not (which is out of scope for this PR).

Personally, I like to keep it simple and stick to OOP with DI, since it is language agnostic.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why this package should deprecate NullLogger. Both NullLogger and the nullsafe operator are valid ways to solve the case of the optional logger in the constructor

Personally, I like to keep it simple and stick to OOP with DI, since it is language agnostic.

being language agnostic does not make sense when writing a code snippet for PHP.

And if you mean avoiding features that don't directly translate to other OOP languages, your argument is void IMO:

  • you are using constructor promoted properties, which have a direct equivalent in very few other languages
  • the nullsafe operator exists in most modern languages

Choose a reason for hiding this comment

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

Is it a recommended way to handle with no logs - pass a null , not NullLogger?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants