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

WordFinder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
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