SubjectResolver::resolveSubject()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.6666
cc 2
eloc 5
nc 2
nop 1
crap 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