Factory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 3
dl 0
loc 29
ccs 7
cts 7
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getProcessor() 0 4 1
A getGenerator() 0 4 1
A getDefaultConfig() 0 6 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Canis.io
4
 * @license   MIT
5
 */
6
namespace Canis\Lumen\Jwt\Adapters\Lcobucci;
7
8
use Canis\Lumen\Jwt\Adapters\AbstractFactory;
9
10
class Factory
11
    extends AbstractFactory
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
12
{
13
    /**
14
     * @inheritdoc
15
     */
16 11
    public function getProcessor()
17
    {
18 11
        return new Processor($this->getConfig());
19
    }
20
21
    /**
22
     * @inheritdoc
23
     */
24 31
    public function getGenerator()
25
    {
26 31
        return new Generator($this->getConfig());
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32 31
    final protected function getDefaultConfig()
33
    {
34 31
        return array_merge(parent::getDefaultConfig(), [
0 ignored issues
show
Best Practice introduced by
The expression return array_merge(paren...tiInHeader' => false)); seems to be an array, but some of its elements' types (false) are incompatible with the return type of the parent method Canis\Lumen\Jwt\Adapters...ctory::getDefaultConfig of type array<string,integer|string[]>.

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 new Author('Johannes');
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return '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...
35
            'jtiInHeader' => false
36 31
        ]);
37
    }
38
}
39