Passed
Push — master ( e1d963...85ca69 )
by Roman
04:38
created

WordFinder::search()   A

Complexity

Conditions 3
Paths 5

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 10
cc 3
nc 5
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Crossword\Domain\Service;
6
7
use App\Crossword\Domain\Criteria\WordSearchCriteria;
8
use App\Crossword\Domain\Exception\ApiClientException;
9
use App\Crossword\Domain\Exception\WordFoundException;
10
use App\Crossword\Domain\Port\DictionaryInterface;
11
use App\SharedKernel\Domain\Model\Word;
12
use Psr\Log\LoggerInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Log\LoggerInterface 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...
13
14
final class WordFinder
15
{
16
    private LoggerInterface $logger;
17
    private DictionaryInterface $dictionary;
18
19
    public function __construct(DictionaryInterface $dictionary, LoggerInterface $logger)
20
    {
21
        $this->logger = $logger;
22
        $this->dictionary = $dictionary;
23
    }
24
25 3
    public function search(WordSearchCriteria $criteria): Word
26
    {
27
        try {
28 3
            $searchWordDto = $this->dictionary->searchWord($criteria);
29 2
            if ($searchWordDto->count()) {
30 1
                return new Word($searchWordDto->word(), $searchWordDto->definition());
31
            }
32
33 1
            throw new WordFoundException();
34 2
        } catch (ApiClientException $exception) {
35 1
            $this->logger->error($exception->getMessage());
36
37 1
            throw new WordFoundException();
38
        }
39
    }
40
}
41