Completed
Push — master ( b5ae25...349033 )
by Frederik
02:37
created

EntryTransactionDetail   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B getRelatedPartyAccount() 0 22 6
1
<?php
2
3
namespace Genkgo\Camt\Camt052\Decoder;
4
5
use Genkgo\Camt\DTO;
6
use Genkgo\Camt\Decoder\EntryTransactionDetail as BaseDecoder;
7
use \SimpleXMLElement;
8
use Genkgo\Camt\Iban;
9
10
class EntryTransactionDetail extends BaseDecoder
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function getRelatedPartyAccount(SimpleXMLElement $xmlRelatedPartyTypeAccount)
16
    {
17
        if (false === isset($xmlRelatedPartyTypeAccount->Id)) {
18
            return;
19
        }
20
21
        if (isset($xmlRelatedPartyTypeAccount->Id->IBAN)) {
22
            return new DTO\IbanAccount(new Iban((string) $xmlRelatedPartyTypeAccount->Id->IBAN));
23
        }
24
25
        if (isset($xmlRelatedPartyTypeAccount->Id->BBAN)) {
26
            return new Camt052DTO\BBANAccount((string) $xmlRelatedPartyTypeAccount->Id->BBAN);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \Genkgo\Camt\...TypeAccount->Id->BBAN); (Genkgo\Camt\Camt052\Decoder\Camt052DTO\BBANAccount) is incompatible with the return type declared by the abstract method Genkgo\Camt\Decoder\Entr...:getRelatedPartyAccount of type Genkgo\Camt\DTO\Account|null.

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...
27
        }
28
29
        if (isset($xmlRelatedPartyTypeAccount->Id->UPIC)) {
30
            return new Camt052DTO\UPICAccount((string) $xmlRelatedPartyTypeAccount->Id->UPIC);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \Genkgo\Camt\...TypeAccount->Id->UPIC); (Genkgo\Camt\Camt052\Decoder\Camt052DTO\UPICAccount) is incompatible with the return type declared by the abstract method Genkgo\Camt\Decoder\Entr...:getRelatedPartyAccount of type Genkgo\Camt\DTO\Account|null.

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...
31
        }
32
33
        if (isset($xmlRelatedPartyTypeAccount->Id->PrtryAcct)) {
34
            return new Camt052DTO\ProprietaryAccount((string) $xmlRelatedPartyTypeAccount->Id->PrtryAcct->Id);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \Genkgo\Camt\...nt->Id->PrtryAcct->Id); (Genkgo\Camt\Camt052\Deco...2DTO\ProprietaryAccount) is incompatible with the return type declared by the abstract method Genkgo\Camt\Decoder\Entr...:getRelatedPartyAccount of type Genkgo\Camt\DTO\Account|null.

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...
35
        }
36
    }
37
}
38