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

ExecutionContext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolvePackage() 0 11 3
A __construct() 0 7 1
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