Spomky-Labs / otphp

:closed_lock_with_key: A PHP library for generating one time passwords according to RFC 4226 (HOTP) and the RFC 6238 (TOTP)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OTPHP\OTP::getQrCodeUri () method without parameters

microGears opened this issue · comments

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? / Specification no
Library version v9.1.4

When trying to use the OTPHP\OTP::getQrCodeUri () method without parameters:

$now    = time();
$period = self::TF_PERIOD;
$otp    = TOTP::create(self::TF_TOKEN, $period, 'sha1', 6);
$otp->setLabel(self::TF_LABEL);
$url = $otp->getQrCodeUri();

I get an error:
[Tue Aug 13 08:49:35.346689 2019] [php7:notice] [pid 12] [client 172.20.71.2:44216] [ArgumentCountError]: Too few arguments to function OTPHP\OTP::getQrCodeUri(), 0 passed in ...

Version PHP 7.2

It looks like you are not using v9.1.4 because this method does not require any argument.

The version you installed may be from th v10 branch where there is no default value anymore.

In any case I highly recommend you to set parameters as the default behaviour is to use the Google API that has been shutdown months ago (see #128).

Here is the code in the library

    /**
     * {@inheritdoc}
     */
    public function getQrCodeUri(string $uri = 'https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl={PROVISIONING_URI}', string $placeholder = '{PROVISIONING_URI}'): string
    {
        $provisioning_uri = urlencode($this->getProvisioningUri());

        return str_replace($placeholder, $provisioning_uri, $uri);
    }

API Google works great now...
Maybe there are some innovations in 7.2 regarding "declare (strict_types = 1);", because on 7.1 everything works fine.

declare (strict_types = 1); only indicates that the type of the arguments has to fulfill with the typehint. e.g. if the argument type is int, you cannot use "1234".
This is not the problem here. What is the output of composer show -i?