Skip to content

Update README.md - #78

Open
sebastianstucke87 wants to merge 1 commit into
php-fig:masterfrom
sebastianstucke87:master
Open

sebastianstucke87 wants to merge 1 commit into
php-fig:masterfrom
sebastianstucke87:master

Conversation

@sebastianstucke87

Copy link
Copy Markdown
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
Comment thread README.md
{
$this->logger = $logger;
}
$this->logger->info('Doing work');

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Copy link
Copy Markdown

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

5 participants