Passed
Branch master (ee1d9b)
by Allan
03:37 queued 01:36
created

PackageResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A resolvePackage() 0 7 2
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerChangelogs\Resolvers;
7
8
use Vaimo\ComposerChangelogs\Exceptions\PackageResolverException;
9
10
class PackageResolver
11
{
12
    /**
13
     * @var \Vaimo\ComposerChangelogs\Repositories\PackageRepository
14
     */
15
    private $packageRepository;
16
17
    /**
18
     * @var \Composer\Package\RootPackageInterface
19
     */
20
    private $rootPackage;
21
22
    /**
23
     * @param \Vaimo\ComposerChangelogs\Repositories\PackageRepository $packageRepository
24
     * @param \Composer\Package\RootPackageInterface $rootPackage
25
     */
26
    public function __construct(
27
        \Vaimo\ComposerChangelogs\Repositories\PackageRepository $packageRepository,
28
        \Composer\Package\RootPackageInterface $rootPackage
29
    ) {
30
        $this->packageRepository = $packageRepository;
31
        $this->rootPackage = $rootPackage;
32
    }
33
34
    /**
35
     * @param string $packageName
36
     * @return \Composer\Package\PackageInterface
37
     * @throws PackageResolverException
38
     */
39
    public function resolvePackage($packageName)
40
    {
41
        if (!$packageName) {
42
            $packageName = $this->rootPackage->getName();
43
        }
44
45
        return $this->packageRepository->getByName($packageName);
46
    }
47
}
48