Completed
Push — master ( 03910f...346372 )
by Matt
04:36
created

ProblemService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 11
rs 10
1
<?php
2
3
namespace App\Service;
4
5
use App\Repository\ImageRepository;
6
use App\Repository\ProblemRepository;
7
use App\Repository\WanderRepository;
8
use Symfony\Component\Routing\RouterInterface;
9
10
class ProblemService
11
{
12
    /** @var ProblemRepository */
13
    private $problemRepository;
14
15
    /** @var WanderRepository */
16
    private $wanderRepository;
17
18
    /** @var ImageRepository */
19
    private $imageRepository;
20
21
    /** @var RouterInterface */
22
    private $router;
23
24
    public function __construct(
25
        problemRepository $problemRepository,
26
        WanderRepository $wanderRepository,
27
        ImageRepository $imageRepository,
28
        RouterInterface $router
29
        )
30
    {
31
        $this->problemRepository = $problemRepository;
32
        $this->wanderRepository = $wanderRepository;
33
        $this->imageRepository = $imageRepository;
34
        $this->router = $router;
35
    }
36
37
    public function createProblemReport(): void
38
    {
39
        // I don't care about concurrency; there's only me using this and
40
        // I can always run it again if there's a problem; it's an unimportant
41
        // operation.
42
        $this->problemRepository->clearAllProblems();
43
44
        // Build a hash of all possible valid URLs for wanders and
45
        // images to compare what we find in descriptions, etc. with.
46
        $validUris = [];
47
        $wanders = $this->wanderRepository->findAll();
48
        foreach ($wanders as $wander) {
49
            $uri = $this->router->generate('wanders_show', [ 'id' => $wander->getId()]);
50
            $validUris[$uri] = true; // Really I just want a hash that doesn't actually map
51
        }
52
53
        $images = $this->imageRepository->findAll();
54
        foreach ($images as $image) {
55
            $uri = $this->router->generate('image_show', [ 'id' => $image->getId()]);
56
            $validUris[$uri] = true; // Really I just want a hash that doesn't actually map
57
        }
58
        dd($validUris);
59
    }
60
}