Completed
Push — master ( 1a48b1...65cd04 )
by Ramon
02:01
created

Encryptor::encrypt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 2
1
<?php
2
3
namespace Codecraft63\CertsignLogin;
4
5 View Code Duplication
class Encryptor
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
6
{
7
8
    use Util;
9
10
    /**
11
     * Encrypt text using certsign login private key.
12
     *
13
     * @param string $text
14
     * @param string $key
15
     * @throws \Exception
16
     * @return string
17
     */
18
    public static function encrypt(string $text, string $key): string
19
    {
20
        $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
21
        $cipher_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
22
        $iv = substr($key, 0, $cipher_size);
23
24
        mcrypt_generic_init($cipher, $key, $iv);
25
26
        $encrypted_text = mcrypt_generic($cipher, $text);
27
        $encrypted_text = str_replace("certplus", "\\+", str_replace("(\r\n|\n)", "", $encrypted_text));
28
        $encrypted_text = self::pkcs5_pad($encrypted_text, $cipher_size);
0 ignored issues
show
Documentation introduced by
$cipher_size is of type integer, but the function expects a object<Codecraft63\CertsignLogin\integer>.

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);
Loading history...
29
        mcrypt_generic_deinit($cipher);
30
        mcrypt_module_close($cipher);
31
32
        return $encrypted_text;
33
    }
34
}
35