Passed
Push — main ( cd254c...1dff49 )
by Alex
01:07
created

TraitCryption::encryption()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Erykai\Cryption;
4
5
use Exception;
6
7
trait TraitCryption
8
{
9
    /**
10
     * @throws Exception
11
     */
12
    protected function encryption(string $string): string
13
    {
14
15
        $this->setData($string);
0 ignored issues
show
Bug introduced by
It seems like setData() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
        $this->/** @scrutinizer ignore-call */ 
16
               setData($string);
Loading history...
16
        $base = $this->getData();
0 ignored issues
show
Bug introduced by
It seems like getData() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

16
        /** @scrutinizer ignore-call */ 
17
        $base = $this->getData();
Loading history...
17
        if(str_contains($string,'/')){
18
            $base = str_replace('/', 'bArRa', $base);
19
        }
20
21
        return $base;
22
    }
23
24
    /**
25
     * @param string $encryption
26
     * @return string
27
     */
28
    protected function decryption(string $encryption): string
29
    {
30
        if(str_contains($encryption,'bArRa')){
31
            $encryption = str_replace('bArRa', '/', $encryption);
32
        }
33
        $encryption = base64_decode($encryption);
34
        [$encryption, $decryption_key, $encryption_iv] = explode(".",$encryption);
35
        return openssl_decrypt ($encryption, CIPHERING,
36
            base64_encode(DECRYPT_KEY) . $decryption_key, iv: $encryption_iv);
37
38
    }
39
}