Completed
Push — master ( 91fec0...3d39f9 )
by Anthony
05:07
created

McryptRijndael128   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 15
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getStrength() 0 3 1
A getCipher() 0 3 1
1
<?php
2
/**
3
 * mcrypt mixer using the Rijndael cipher with 128 bit block size
4
 *
5
 * PHP version 5.3
6
 *
7
 * @category   PHPCryptLib
8
 * @package    Random
9
 * @subpackage Mixer
10
 * @author     Anthony Ferrara <[email protected]>
11
 * @copyright  2013 The Authors
12
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
13
 * @version    Build @@version@@
14
 */
15
16
namespace RandomLib\Mixer;
17
18
use RandomLib\AbstractMcryptMixer;
19
use SecurityLib\Strength;
20
21
/**
22
 * mcrypt mixer using the Rijndael cipher with 128 bit block size
23
 *
24
 * @category   PHPCryptLib
25
 * @package    Random
26
 * @subpackage Mixer
27
 * @author     Anthony Ferrara <[email protected]>
28
 * @author     Chris Smith <[email protected]>
29
 */
30
class McryptRijndael128 extends AbstractMcryptMixer {
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public static function getStrength() {
35
        return new Strength(Strength::HIGH);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \SecurityLib\...ityLib\Strength::HIGH); (SecurityLib\Strength) is incompatible with the return type declared by the interface RandomLib\Mixer::getStrength of type RandomLib\Strength.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    protected function getCipher() {
42
        return 'rijndael-128';
43
    }
44
}
45