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

Make log level less strictly expected from psr log #83

Merged
merged 1 commit into from May 21, 2020

Conversation

JoshuaBehrens
Copy link
Contributor

Description

Running the 0.7.2 with -vvv fails:

 Uncaught TypeError: Argument 1 passed to Icanhazstring\Composer\Unused\Log\DebugLogger::buildRecord() must be of the type int, string given, called in vendor/icanhazstring/composer-unused/src/Log/DebugLogger.php on line 33 and defined in vendor/icanhazstring/composer-unused/src/Log/DebugLogger.php:44
Stack trace:
#0 vendor/icanhazstring/composer-unused/src/Log/DebugLogger.php(33): Icanhazstring\Composer\Unused\Log\DebugLogger->buildRecord('info', 'version', Array)
#1 phar:///usr/local/bin/composer/vendor/psr/log/Psr/Log/LoggerTrait.php(114): Icanhazstring\Composer\Unused\Log\DebugLogger->log('info', 'version', Array)
#2 vendor/icanhazstring/composer-unused/src/Command/UnusedCommand.php(274): Icanhazstring\Composer\Unused\Log\DebugLogger->info('version', Array)
#3 in vendor/icanhazstring/composer-unused/src/Log/DebugLogger.php on line 44

That is due to the constants exposed from psr/log are strings

<?php

namespace Psr\Log;

/**
 * Describes log levels.
 */
class LogLevel
{
    const EMERGENCY = 'emergency';
    const ALERT     = 'alert';
    const CRITICAL  = 'critical';
    const ERROR     = 'error';
    const WARNING   = 'warning';
    const NOTICE    = 'notice';
    const INFO      = 'info';
    const DEBUG     = 'debug';
}

The psr logger interface expects mixed levels:

<?php

namespace Psr\Log;

/**
 * Describes a logger instance.
 *
 * The message MUST be a string or object implementing __toString().
 *
 * The message MAY contain placeholders in the form: {foo} where foo
 * will be replaced by the context data in key "foo".
 *
 * The context array can contain arbitrary data. The only assumption that
 * can be made by implementors is that if an Exception instance is given
 * to produce a stack trace, it MUST be in a key named "exception".
 *
 * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
 * for the full interface specification.
 */
interface LoggerInterface
{
    /**
     * [...]
     */

    /**
     * Logs with an arbitrary level.
     *
     * @param mixed   $level
     * @param string  $message
     * @param mixed[] $context
     *
     * @return void
     *
     * @throws \Psr\Log\InvalidArgumentException
     */
    public function log($level, $message, array $context = array());
}

And the debug logger builds records expecting the level to be an int.

Checklist

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@icanhazstring
Copy link
Member

Hi @JoshuaBehrens thanks for the contribution 👍
Could you rebase with origin/master as I removed a phpstan complain about one check and also added some more workflow checks.

If this works out we can get this merged 🚀

@JoshuaBehrens
Copy link
Contributor Author

Rebase is out :shipit:

@icanhazstring
Copy link
Member

Nice. Thank you. Merged 👍

@icanhazstring icanhazstring merged commit 5b621f3 into composer-unused:master May 21, 2020
@JoshuaBehrens
Copy link
Contributor Author

Damn you are a very fast at reacting :) I like

@JoshuaBehrens JoshuaBehrens deleted the patch-1 branch May 21, 2020 14:32
JoshuaBehrens added a commit to HEPTACOM/heptaconnect-dataset-base that referenced this pull request Nov 2, 2020
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.

None yet

2 participants