Passed
Pull Request — main (#442)
by MusikAnimal
09:07 queued 04:41
created

BlameRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 8
dl 0
loc 13
rs 10
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types = 1);
4
5
namespace App\Repository;
6
7
use App\Model\Edit;
8
use App\Model\Page;
9
use GuzzleHttp\Client;
10
use Psr\Cache\CacheItemPoolInterface;
11
use Psr\Container\ContainerInterface;
12
use Psr\Log\LoggerInterface;
13
14
/**
15
 * BlameRepository is responsible for retrieving authorship data about a single page.
16
 * @codeCoverageIgnore
17
 */
18
class BlameRepository extends AuthorshipRepository
19
{
20
    protected EditRepository $editRepo;
21
    protected UserRepository $userRepo;
22
23
    public function __construct(
24
        ContainerInterface $container,
25
        CacheItemPoolInterface $cache,
26
        Client $guzzle,
27
        LoggerInterface $logger,
28
        bool $isWMF,
29
        int $queryTimeout,
30
        EditRepository $editRepo,
31
        UserRepository $userRepo
32
    ) {
33
        parent::__construct($container, $cache, $guzzle, $logger, $isWMF, $queryTimeout);
34
        $this->editRepo = $editRepo;
35
        $this->userRepo = $userRepo;
36
    }
37
38
    /**
39
     * Get an Edit given the revision ID.
40
     * @param Page $page Given so that the Edit will point to the same instance, rather than create a new Page.
41
     * @param int $revId
42
     * @return Edit|null null if not found.
43
     */
44
    public function getEditFromRevId(Page $page, int $revId): ?Edit
45
    {
46
        return $this->editRepo->getEditFromRevIdForPage($this->userRepo, $page->getProject(), $revId, $page);
47
    }
48
}
49