Passed
Push — master ( 99b058...aba4a6 )
by Allan
07:10 queued 11s
created

Executor::repositoryWrite()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Compatibility;
7
8
use Vaimo\ComposerPatches\Patch\Definition as PatchDefinition;
9
10
class Executor
11
{
12
    public function repositoryWrite($repository, $installationManager, $isDevMode)
13
    {
14
        if (version_compare(\Composer\Composer::VERSION, '2.0', '<')) {
15
            $repository->write();
16
            return;
17
        }
18
19
        $repository->write($isDevMode, $installationManager);
20
    }
21
22
    public function downloadPackage($downloader, $package, $source, $destDir, $errorHandler, &$patchData, &$errors)
23
    {
24
        if (version_compare(\Composer\Composer::VERSION, '2.0', '<')) {
25
            $downloader->download($package, $destDir, false);
26
            return;
27
        }
28
29
        $resultPromise = $downloader->download($package, $destDir, null, false);
30
        $resultPromise->then(function ($path) use (&$patchData) {
31
            $patchData[PatchDefinition::PATH] = $path;
32
        }, function (\Exception $exception) use ($source, $errorHandler, &$patchData, &$errors) {
33
            try {
34
                if (!$exception instanceof \Composer\Downloader\TransportException) {
35
                    throw $exception;
36
                }
37
                $patchData[PatchDefinition::STATUS_LABEL] = $errorHandler->handleError($source, $exception);
38
            } catch (\Exception $error) {
39
                $errors[] = $error;
40
                throw $error;
41
            }
42
            $patchData[PatchDefinition::STATUS] = PatchDefinition::STATUS_ERRORS;
43
        });
44
    }
45
46
    public function assignTmpPathForPatchData(&$patchData, $path)
47
    {
48
        if (version_compare(\Composer\Composer::VERSION, '2.0', '<')) {
49
            $patchData[PatchDefinition::PATH] = $path;
50
        }
51
    }
52
53
    public function waitDownloadCompletion($composer)
54
    {
55
        if (version_compare(\Composer\Composer::VERSION, '2.0', '<')) {
56
            return;
57
        }
58
59
        $composer->getLoop()->getHttpDownloader()->wait();
60
    }
61
}
62