DefaultResetStrategy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A shouldAllowReset() 0 14 4
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Strategies\Package;
7
8
use Composer\Downloader\VcsCapableDownloaderInterface as VcsCapable;
9
use Composer\Downloader\ChangeReportInterface as ChangeReportCapable;
10
use Composer\Downloader\PathDownloader;
11
12
class DefaultResetStrategy implements \Vaimo\ComposerPatches\Interfaces\PackageResetStrategyInterface
13
{
14
    /**
15
     * @var \Composer\Installer\InstallationManager
16
     */
17
    private $installer;
18
19
    /**
20
     * @var \Composer\Downloader\DownloadManager
21
     */
22
    private $downloader;
23
24
    /**
25
     * @var \Vaimo\ComposerPatches\Compatibility\DependenciesFactory
26
     */
27
    private $dependencyFactory;
28
29
    /**
30
     * @param \Composer\Installer\InstallationManager $installer
31
     * @param \Composer\Downloader\DownloadManager $downloader
32
     * @param \Vaimo\ComposerPatches\Compatibility\DependenciesFactory
33
     */
34
    public function __construct(
35
        \Composer\Installer\InstallationManager $installer,
36
        \Composer\Downloader\DownloadManager $downloader
37
    ) {
38
        $this->installer = $installer;
39
        $this->downloader = $downloader;
40
        $this->dependencyFactory = new \Vaimo\ComposerPatches\Compatibility\DependenciesFactory();
41
    }
42
43
    public function shouldAllowReset(\Composer\Package\PackageInterface $package)
44
    {
45
        $downloader = $this->dependencyFactory->createPackageDownloader($this->downloader, $package);
46
47
        if ($downloader instanceof ChangeReportCapable
48
            && $downloader instanceof VcsCapable
49
            && !$downloader instanceof PathDownloader
50
        ) {
51
            $installPath = $this->installer->getInstallPath($package);
52
53
            return !(bool)$downloader->getLocalChanges($package, $installPath);
54
        }
55
56
        return true;
57
    }
58
}
59