Completed
Push — master ( f15022...630d96 )
by Neomerx
02:54
created

BaseCrypt::clearErrors()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
crap 2
1
<?php namespace Limoncello\Crypt;
2
3
/**
4
 * Copyright 2015-2016 [email protected] (www.neomerx.com)
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
/**
20
 * @package Limoncello\Crypt
21
 */
22
abstract class BaseCrypt
23
{
24
    /**
25
     * @return void
26
     */
27 6
    protected function clearErrors()
28
    {
29 6
        while ($this->openSslErrorString() !== false) {
0 ignored issues
show
Unused Code introduced by
This while loop is empty and can be removed.

This check looks for while loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
30
            // drop all accumulated error messages if any
31
        }
32 6
    }
33
34
    /**
35
     * @return null|string
36
     */
37 1
    protected function getErrorMessage()
38
    {
39 1
        $message = null;
40 1
        while (($errorLine = $this->openSslErrorString()) !== false) {
41 1
            $message .= ($message === null ? $errorLine : PHP_EOL . $errorLine);
42
        }
43
44 1
        return $message;
45
    }
46
47
    /**
48
     * @param CryptException $exception
49
     */
50 1
    protected function throwException(CryptException $exception)
51
    {
52 1
        throw $exception;
53
    }
54
55
    /**
56
     * We need this wrapper for testing purposes so we can mock system call to Open SSL.
57
     *
58
     * @return string|false
59
     */
60 5
    protected function openSslErrorString()
61
    {
62 5
        return openssl_error_string();
63
    }
64
}
65