Test Failed
Pull Request — master (#4)
by Ashoka
06:12
created

ProjectTypeResolver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
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
35
        is_array($mapping) && $this->mapping = $mapping;
36
    }
37
38
    /**
39
     * Get the type.
40
     *
41
     * @return string
42
     */
43
    public function resolve(): string
44
    {
45
        $packageType = $this->composer->getPackage()->getType();
46
        return array_key_exists($packageType, $this->mapping)
47
            ? $this->mapping[$packageType]
48
            : 'default';
49
    }
50
}
51