for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace ncryptf;
use SodiumException;
use ncryptf\Keypair;
final class Utils
{
/**
* Securely erases a memory block
*
* @param string $data
* @return boolean
*/
public static function zero(string &$data) : bool
return \sodium_memzero($data) === null;
sodium_memzero($data)
null
This check looks for function or method calls that always return null and whose return value is used.
class A { function getObject() { return null; } } $a = new A(); if ($a->getObject()) {
The method getObject() can return nothing but null, so it makes no sense to use the return value.
getObject()
The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
}
* Generates a crypto keypair
* @return \ncryptf\Keypair
public static function generateKeypair() : Keypair
try {
$keypair = \sodium_crypto_box_keypair();
return new Keypair(
\sodium_crypto_box_secretkey($keypair),
\sodium_crypto_box_publickey($keypair)
);
} catch (SodiumException $e) {
throw new Exception($e->getMessage());
* Generates a signing keypair
public static function generateSigningKeypair() : Keypair
$keypair = \sodium_crypto_sign_keypair();
\sodium_crypto_sign_secretkey($keypair),
\sodium_crypto_sign_publickey($keypair)
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.