Test Failed
Push — master ( dde0ed...e2b526 )
by Francesco
03:04
created

KeyManagerWrapper.php (4 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the MesCryptoBundle package.
5
 *
6
 * (c) Francesco Cartenì <http://www.multimediaexperiencestudio.it/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mes\Security\CryptoBundle;
13
14
use Defuse\Crypto\Exception\CryptoException as BaseCryptoException;
15
use Defuse\Crypto\Exception\EnvironmentIsBrokenException;
16
use Mes\Security\CryptoBundle\Exception\CryptoException;
17
use Mes\Security\CryptoBundle\Model\KeyInterface;
18
use Mes\Security\CryptoBundle\Model\KeySecretAwareInterface;
19
20
/**
21
 * Class KeyManagerWrapper.
22
 */
23
class KeyManagerWrapper implements KeyManagerInterface
24
{
25
    /**
26
     * @var KeyManagerInterface|KeySecretAwareInterface
27
     */
28
    private $keyManager;
29
30
    /**
31
     * KeyManagerWrapper constructor.
32
     *
33
     * @param KeyManagerInterface $keyManager
34
     */
35 8
    public function __construct(KeyManagerInterface $keyManager)
36
    {
37 8
        $this->keyManager = $keyManager;
38 8
    }
39
40
    /**
41
     * {@inheritdoc}
42
     *
43
     * @throws CryptoException
44
     */
45 2
    public function generate($secret = null)
46
    {
47
        try {
48 2
            return $this->keyManager->generate($secret);
0 ignored issues
show
The method generate does only exist in Mes\Security\CryptoBundle\KeyManagerInterface, but not in Mes\Security\CryptoBundl...KeySecretAwareInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
49 1
        } catch (EnvironmentIsBrokenException $ex) {
50 1
            throw new CryptoException($ex->getMessage());
51
        }
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     *
57
     * @throws CryptoException
58
     */
59 2
    public function generateFromAscii($key_encoded, $secret = null)
60
    {
61
        try {
62 2
            return $this->keyManager->generateFromAscii($key_encoded, $secret);
0 ignored issues
show
The method generateFromAscii does only exist in Mes\Security\CryptoBundle\KeyManagerInterface, but not in Mes\Security\CryptoBundl...KeySecretAwareInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
63 1
        } catch (BaseCryptoException $ex) {
64 1
            throw new CryptoException($ex->getMessage());
65
        }
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 1
    public function getKey()
72
    {
73 1
        return $this->keyManager->getKey();
0 ignored issues
show
The method getKey does only exist in Mes\Security\CryptoBundle\KeyManagerInterface, but not in Mes\Security\CryptoBundl...KeySecretAwareInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 1
    public function setKey(KeyInterface $key)
80
    {
81 1
        $this->keyManager->setKey($key);
0 ignored issues
show
The method setKey does only exist in Mes\Security\CryptoBundle\KeyManagerInterface, but not in Mes\Security\CryptoBundl...KeySecretAwareInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
82 1
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 1
    public function getSecret()
88
    {
89 1
        return $this->keyManager->getSecret();
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 1
    public function setSecret($secret)
96
    {
97 1
        $this->keyManager->setSecret($secret);
98 1
    }
99
}
100