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

FEATURE: Add fromClassAndMethodName() to LogEnvironment #3419

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

Conversation

kdambekalns
Copy link
Member

This does some code cleanup and adds a new method fromClassAndMethodName($className, $methodName) to the LogEnvironment.

It be used like this:

LogEnvironment::fromClassAndMethodName(__CLASS__, __METHOD__)

and will return useful data – as opposed to LogEnvironment::fromMethodName(__METHOD__), which only works for static methods (SomeClass::someMethod or closures).

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

This does some code cleanup and adds a new method `fromClassAndMethodName($className, $methodName)` to the `LogEnvironment`.

It be used like this:

    LogEnvironment::fromClassAndMethodName(__CLASS__, __METHOD__)

and will return useful data – as opposed to `LogEnvironment::fromMethodName(__METHOD__)`, which only works for static methods (`SomeClass::someMethod` or closures).
*/
public static function fromClassAndMethodName(string $className, string $methodName): array
Copy link
Member

Choose a reason for hiding this comment

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

What if we also allow passing an object instead of the class name? That way you could just pass $this in most cases.

public static function fromClassAndMethodName(string|object $class, string $methodName): array
{
    $className = is_object($class) ? get_class($object) : $className;
...

Copy link
Member Author

Choose a reason for hiding this comment

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

Does that make it easier to use? You can even use $this::class if you like…

@robertlemke
Copy link
Member

Why is this a task and not a new (tiny) feature?

@kdambekalns
Copy link
Member Author

Why is this a task and not a new (tiny) feature?

So I can sneak it into 8.3… 😎

@kdambekalns kdambekalns changed the title TASK: Add fromClassAndMethodName() to LogEnvironment FEATURE: Add fromClassAndMethodName() to LogEnvironment Dec 4, 2024
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.

2 participants