Failed Conditions
Push — master ( 58748a...c61078 )
by Philippe
61:45
created

EmailMisspellingHandler::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 19
nc 2
nop 1
dl 0
loc 23
rs 9.6333
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace PhpSpellCheck\MisspellingHandler;
5
6
use PhpSpellcheck\MisspellingInterface;
7
8
class EmailMisspellingHandler implements MisspellingHandlerInterface
9
{
10
    /**
11
     * @var EmailSenderInterface
0 ignored issues
show
Bug introduced by
The type PhpSpellCheck\Misspellin...er\EmailSenderInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
     */
13
    private $emailSender;
14
15
    public function __construct(EmailSenderInterface $emailSender)
16
    {
17
        $this->emailSender = $emailSender;
18
    }
19
20
    /**
21
     * @param MisspellingInterface[] $misspellings
22
     */
23
    public function handle(iterable $misspellings)
24
    {
25
        $message = <<<MSG
26
Dear me,
27
28
You're bad at writing.
29
30
Here's the proof:
31
32
MSG;
33
        foreach ($misspellings as  $misspelling) {
34
            $message .= \Safe\sprintf(
35
                'You wrote "%s" at line %d in the article "%s" but it\'s a misspelling. Here\'s my suggestions: %s',
36
                    $misspelling->getWord(),
37
                    $misspelling->getLineNumber(),
38
                    $misspelling->getContext()['article-name'],
39
                    explode(',', $misspelling->getSuggestions())
40
                ).PHP_EOL;
41
        }
42
43
        $this->emailSender
44
            ->body($message)
45
            ->send();
46
    }
47
}
48