dochne/google-authenticator

I get the following error: Call to a member function writeDataUri() on null

Closed this issue · 2 comments

This happens in EndroidQrImageGenerator.php:25 because of the following code:

public function generateUri(Secret $secret)
    {
        $qrCode = new QrCode($secret->getUri());
        $qrCode->setSize($this->size);
        return $qrCode->setWriterByName('png')->writeDataUri();
    }

It should be something like:

public function generateUri(Secret $secret)
    {
        $qrCode = new QrCode($secret->getUri());
        $qrCode->setSize($this->size);
        return $qrCode->getWriter('png')->writeDataUri($qrCode);
    }

instead of setWriterByName('png') should be getWriter('png') and writeDataUri needs QrCode as argument

Hi! Thanks for the issue report! It looks like the newest version I developed this against was Endroid ~2 and that they're now on version ~3.

I suspect you installed the version 3 one which made a breaking change to their functions.

Simplest way to have it working would be to install Endroid@~2.

I'd upgrade the version here but that would be a BC that would require a semvar jump as I don't require it, merely suggest it

Thanks for the quick reply!!
I downgraded Endroid version and it's working fine!!