Passed
Push — master ( 834a40...f4d4c2 )
by Allan
02:10
created

ExecutionContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerChangelogs\Console\Command;
7
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
use Vaimo\ComposerChangelogs\Exceptions\PackageResolverException;
11
use Vaimo\ComposerChangelogs\Factories;
12
13
class ExecutionContext
14
{
15
    /**
16
     * @var \Vaimo\ComposerChangelogs\Composer\Context
17
     */
18
    private $composerCtx;
19
20
    /**
21
     * @var \Vaimo\ComposerChangelogs\Console\OutputGenerator
22
     */
23
    private $outputGenerator;
24
25
    /**
26
     * @param \Vaimo\ComposerChangelogs\Composer\Context $composerCtx
27
     */
28
    public function __construct(
29
        OutputInterface $output,
30
        \Vaimo\ComposerChangelogs\Composer\Context $composerCtx
31
    ) {
32
        $this->composerCtx = $composerCtx;
33
34
        $this->outputGenerator = new \Vaimo\ComposerChangelogs\Console\OutputGenerator($output);
35
    }
36
    
37
    public function resolvePackage($name)
38
    {
39
        $packageRepoFactory = new Factories\PackageResolverFactory($this->composerCtx);
40
        $packageResolver = $packageRepoFactory->create();
41
        
42
        try {
43
            return $packageResolver->resolvePackage(is_string($name) ? $name : '');
44
        } catch (PackageResolverException $exception) {
45
            $this->outputGenerator->writeResolverException($exception);
46
47
            return null;
48
        }
49
    }
50
}
51