Test Failed
Pull Request — master (#4)
by Ashoka
09:01 queued 03:06
created

ProjectTypeResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A resolve() 0 6 2
1
<?php
2
/**
3
 * Copyright MediaCT. All rights reserved.
4
 * https://www.mediact.nl
5
 */
6
7
namespace Mediact\TestingSuite\Composer;
8
9
use Composer\Composer;
10
11
/**
12
 * Resolves the project type.
13
 */
14
class ProjectTypeResolver
15
{
16
    /** @var Composer */
17
    private $composer;
18
19
    /** @var array */
20
    private $mapping = [
21
        'magento2-module' => 'magento2',
22
        'magento-module'  => 'magento1'
23
    ];
24
25
    /**
26
     * Constructor.
27
     *
28
     * @param Composer   $composer
29
     * @param array|null $mapping
30
     */
31
    public function __construct(Composer $composer, array $mapping = null)
32
    {
33
        $this->composer = $composer;
34
        $this->mapping  = $mapping ?? $this->mapping;
35
    }
36
37
    /**
38
     * Get the type.
39
     *
40
     * @return string
41
     */
42
    public function resolve(): string
43
    {
44
        $packageType = $this->composer->getPackage()->getType();
45
        return array_key_exists($packageType, $this->mapping)
46
            ? $this->mapping[$packageType]
47
            : 'default';
48
    }
49
}
50