SubjectResolver   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 26
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addPart() 0 5 1
A resolveSubject() 0 9 2
1
<?php declare(strict_types = 1);
2
3
namespace JDR\Mailer\Part;
4
5
use JDR\Mailer\Email\Email;
6
7
class SubjectResolver implements EmailPartResolver
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12 3
    public function addPart(Email $email, EmailPart $part)
13
    {
14 3
        $subject = $this->resolveSubject($part);
0 ignored issues
show
Compatibility introduced by
$part of type object<JDR\Mailer\Part\EmailPart> is not a sub-type of object<JDR\Mailer\Part\Subject>. It seems like you assume a concrete implementation of the interface JDR\Mailer\Part\EmailPart to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
15 3
        $email->setSubject($subject);
16 3
    }
17
18
    /**
19
     * Resolve the subject.
20
     *
21
     * @return string
22
     */
23 3
    private function resolveSubject(Subject $part)
24
    {
25 3
        $subject = $part->getSubject();
26 3
        foreach ($part->getParameters() as $search => $replace) {
27 2
            $subject = str_replace($search, $replace, $subject);
28
        }
29
30 3
        return $subject;
31
    }
32
}
33