Completed
Push — master ( bc5c42...47bad9 )
by Ben
02:53
created

Pdf16Encryption   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 39.29 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 11
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A encrypt() 11 22 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * BaconPdf
4
 *
5
 * @link      http://github.com/Bacon/BaconPdf For the canonical source repository
6
 * @copyright 2015 Ben Scholzen (DASPRiD)
7
 * @license   http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
8
 */
9
10
namespace Bacon\Pdf\Encryption;
11
12
class Pdf16Encryption extends Pdf14Encryption
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function encrypt($plaintext, $objectNumber, $generationNumber)
18
    {
19 View Code Duplication
        if (function_exists('random_bytes')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
20
            // As of PHP 7
21
            $initializationVector = random_bytes(16);
22
        } else {
23
            $initializationVector = '';
24
            mt_srand();
25
26
            for ($i = 0; $i < 16; ++$i) {
27
                $initializationVector .= chr(mt_rand(0, 255));
28
            }
29
        }
30
31
        return $initializationVector . openssl_encrypt(
32
            $plaintext,
33
            'aes-128-cbc',
34
            $this->computeIndividualEncryptionKey($objectNumber, $generationNumber) . "\x73\x41\x6c\x54",
35
            '',
36
            $initializationVector
37
        );
38
    }
39
}
40