Test Failed
Pull Request — develop (#27)
by Michiel
06:05
created

UserSecretStorageTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 24
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSecret() 0 4 1
A setSecret() 0 4 1
1
<?php
2
3
/**
4
 * Copyright 2022 SURF B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
trait UserSecretStorageTrait
20
{
21
    private $encryption;
22
23
    /**
24
     * Get the user's secret
25
     * @param String $userId
26
     * @return String The user's secret
27
     */
28
    public function getSecret($userId)
29
    {
30
        $encryptedSecret = $this->getUserSecret($userId);
0 ignored issues
show
Bug introduced by
It seems like getUserSecret() 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

30
        /** @scrutinizer ignore-call */ 
31
        $encryptedSecret = $this->getUserSecret($userId);
Loading history...
31
        return $this->encryption->decrypt($encryptedSecret);
32
    }
33
34
    /**
35
     * Store a secret for a user.
36
     * @param String $userId
37
     * @param String $secret
38
     */
39
    public function setSecret($userId, $secret)
40
    {
41
        $encryptedSecret = $this->encryption->encrypt($secret);
42
        $this->setUserSecret($userId, $encryptedSecret);
0 ignored issues
show
Bug introduced by
It seems like setUserSecret() 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

42
        $this->/** @scrutinizer ignore-call */ 
43
               setUserSecret($userId, $encryptedSecret);
Loading history...
43
    }
44
}
45