for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace yrc\web;
use yrc\web\JsonResponseFormatter;
use Yii;
class Json25519ResponseFormatter extends JsonResponseFormatter
{
/**
* Take the response generated by JsonResponseFormatter and anonymously encrypt it
* @param array $response
*/
protected function formatJson($response)
parent::formatJson($response);
$response
array
object<yrc\web\Response>
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
$response->getHeaders()->set('Content-Type', 'application/json+25519; charset=UTF-8');
getHeaders
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.
// Retrieve the token object from the user
$token = Yii::$app->user->getIdentity()->getToken();
// Calculate the keypair
$keyPair = \Sodium\crypto_box_keypair_from_secretkey_and_publickey(
\base64_decode($token->getCryptToken()->secret_box_kp),
\base64_decode($token->client_public)
);
// Calculate a nonce and set it in the header
$nonce = \Sodium\randombytes_buf(\Sodium\CRYPTO_BOX_NONCEBYTES);
$response->getHeaders()->set('x-nonce', \base64_encode($nonce));
$response->getHeaders()->set('x-pubkey', \base64_encode($token->getCryptToken()->getBoxPublicKey()));
// Encrypt the content
$response->content = \base64_encode(\Sodium\crypto_box(
$response->content,
$nonce,
$keyPair
));
}
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: