Resolver   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 10
c 1
b 0
f 0
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A resolveByParsedDto() 0 12 1
1
<?php
2
3
/*
4
 * This file is part of the Veslo project <https://github.com/symfony-doge/veslo>.
5
 *
6
 * (C) 2019 Pavel Petrov <[email protected]>.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @license https://opensource.org/licenses/GPL-3.0 GPL-3.0
12
 */
13
14
declare(strict_types=1);
15
16
namespace Veslo\AnthillBundle\Vacancy;
17
18
use Veslo\AnthillBundle\Dto\Vacancy\Parser\ParsedDto;
19
use Veslo\AnthillBundle\Entity\Repository\VacancyRepository;
20
use Veslo\AnthillBundle\Entity\Vacancy;
21
22
/**
23
 * Extracts a vacancy instance from the specified context
24
 */
25
class Resolver
26
{
27
    /**
28
     * Vacancy repository
29
     *
30
     * @var VacancyRepository
31
     */
32
    private $vacancyRepository;
33
34
    /**
35
     * Resolver constructor.
36
     *
37
     * @param VacancyRepository $vacancyRepository Vacancy repository
38
     */
39
    public function __construct(VacancyRepository $vacancyRepository)
40
    {
41
        $this->vacancyRepository = $vacancyRepository;
42
    }
43
44
    /**
45
     * Returns a vacancy instance related to the specified parsed data, if exists, null otherwise
46
     *
47
     * @param ParsedDto $scanResult Context of parsed vacancy data from website
48
     *
49
     * @return Vacancy|null
50
     */
51
    public function resolveByParsedDto(ParsedDto $scanResult): ?Vacancy
52
    {
53
        $location    = $scanResult->getLocation();
54
        $roadmap     = $location->getRoadmap();
55
        $roadmapName = $roadmap->getName();
56
57
        $vacancy            = $scanResult->getVacancy();
58
        $externalIdentifier = $vacancy->getExternalIdentifier();
59
60
        $entity = $this->vacancyRepository->findByRoadmapNameAndExternalIdentifier($roadmapName, $externalIdentifier);
61
62
        return $entity;
63
    }
64
}
65