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

docs: replace types in Logger #6633

Closed
wants to merge 6 commits into from
Closed

docs: replace types in Logger #6633

wants to merge 6 commits into from

Conversation

ddevsr
Copy link
Collaborator

@ddevsr ddevsr commented Oct 6, 2022

Description
See #6310.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Comment on lines +70 to +73
if (! is_string($message)) {
$message = print_r($message, true);
}

Copy link
Member

Choose a reason for hiding this comment

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

This seems to be more of a feature enhancement rather than a simple docblock fix, so this is proper for 4.3.

However, I'm not convinced that we should allow array|int|object as additions to possible types for $message. If we are to look at the Psr\Log specification, the $message is only limited to string|\Stringable. Plus, I find it unsightly for an array-type message to be just a print_r() of itself rather than it being properly formatted into a string.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, we can accept array|int|object addition in function handle?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I disagree, changing to a PSR-3 compatible logger may break apps.

Copy link
Collaborator Author

@ddevsr ddevsr Oct 6, 2022

Choose a reason for hiding this comment

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

@kenjis I found this when git cherry-pick --continue

------ ---------------------------------------------------------------------------------------------------------------------
  Line   system\CLI\Console.php
 ------ ---------------------------------------------------------------------------------------------------------------------
         Ignored error pattern #^Strict comparison using === between array<mixed, mixed> and array{} will always evaluate to
         false\.$# in path D:\Project\laragon\www\ci4\system\CLI\Console.php was not matched in reported errors.
  71     Strict comparison using === between array and array{} will always evaluate to false.
 ------ ---------------------------------------------------------------------------------------------------------------------


 [ERROR] Found 2 errors

Fix the phpstan error(s) before commit.

I fix in phpstan-baseline.neon.dist #^Strict comparison using === between array<mixed, mixed> and array{} will always evaluate to false to #^Strict comparison using === between array and array{} will always evaluate to false

Copy link
Member

Choose a reason for hiding this comment

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

I've fixed the error.
See #6627

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

In Psr\Log\LoggerInterface still with string only (v1.1.4), I think we set now string only. \Stringable still under develop

Copy link
Member

Choose a reason for hiding this comment

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

Stringable can be used in PHP 8.0 or later.

Copy link
Member

Choose a reason for hiding this comment

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

This comment:

* The message MUST be a string or object implementing __toString().

@kenjis kenjis added the wrong branch PRs sent to wrong branch label Oct 6, 2022
@paulbalandan paulbalandan changed the base branch from develop to 4.3 October 6, 2022 08:49
@paulbalandan paulbalandan removed the wrong branch PRs sent to wrong branch label Oct 6, 2022
Comment on lines +70 to +72
if (! is_string($message)) {
$message = print_r($message, true);
}
Copy link
Member

Choose a reason for hiding this comment

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

This change is not acceptable.

* The message MUST be a string or object implementing __toString().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Still in 4.3 branch if remove this?

Copy link
Member

Choose a reason for hiding this comment

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

If we change, it would be incompatible with PSR-3.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, i will send PR another with develop branch. Many phpstan error in my branch

------ -------------------------------------------------------------------------------------------------------------------
  Line   system\Cache\Handlers\MemcachedHandler.php
 ------ -------------------------------------------------------------------------------------------------------------------
         Ignored error pattern #^Method MemcachePool\:\:decrement\(\) invoked with 4 parameters, 1\-2 required\.$# in path
         D:\Project\laragon\www\ci4\system\Cache\Handlers\MemcachedHandler.php was not matched in reported errors.
         Ignored error pattern #^Method MemcachePool\:\:increment\(\) invoked with 4 parameters, 1\-2 required\.$# in path
         D:\Project\laragon\www\ci4\system\Cache\Handlers\MemcachedHandler.php was not matched in reported errors.
 ------ -------------------------------------------------------------------------------------------------------------------

 ------ -------------------------------------------------------------------------------------------------
  Line   system\HTTP\URI.php
 ------ -------------------------------------------------------------------------------------------------
         Ignored error pattern #^Cannot unset offset 'path' on array{host: non-empty-string}\.$# in path
         D:\Project\laragon\www\ci4\system\HTTP\URI.php was not matched in reported errors.
 ------ -------------------------------------------------------------------------------------------------

 ------ -----------------------------------------------------------------------------------------------
  Line   system\Helpers\text_helper.php
 ------ -----------------------------------------------------------------------------------------------
         Ignored error pattern #^Variable \$pool might not be defined\.$# in path
         D:\Project\laragon\www\ci4\system\Helpers\text_helper.php was not matched in reported errors.
 ------ -----------------------------------------------------------------------------------------------

 ------ ------------------------------------------------------------------------------
  Line   system\Model.php
 ------ ------------------------------------------------------------------------------
  684    Offset 'data' on array on left side of ?? always exists and is not nullable.
  710    Offset 'data' on array on left side of ?? always exists and is not nullable.
 ------ ------------------------------------------------------------------------------

 [ERROR] Found 7 errors

Fix the phpstan error(s) before commit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kenjis I create new branch with uptodate remote branch develop. But have result phpstan error

------ ---------------------------------------------------------------------------- 
  Line   system\Helpers\array_helper.php
 ------ ----------------------------------------------------------------------------
  51     Result of && is always false.
  51     Strict comparison using !== between 0 and 0 will always evaluate to false.
 ------ ----------------------------------------------------------------------------


 [ERROR] Found 2 errors

Fix the phpstan error(s) before commit.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ohh mistake, 1 hour ago phpstan release 1.8.8 and in this PR using 1.8.7 @kenjis

Copy link
Member

@kenjis kenjis left a comment

Choose a reason for hiding this comment

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

I think $message should be strring or stringable.

@ddevsr
Copy link
Collaborator Author

ddevsr commented Oct 6, 2022

I think $message should be strring or stringable.

in handler function too?

@kenjis
Copy link
Member

kenjis commented Oct 6, 2022

in handler function too?

Yes. handler() gets $message from log_message().

@ddevsr ddevsr closed this Oct 6, 2022
@ddevsr ddevsr deleted the docs-logger branch October 6, 2022 14:48
@ddevsr ddevsr mentioned this pull request Oct 6, 2022
5 tasks
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.

3 participants