• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cweagans / composer-patches / 4108554590

pending completion
4108554590

Pull #447

github

GitHub
Merge 5bafa176f into a4b573156
Pull Request #447: 2.x WIP (don't merge yet)

381 of 381 new or added lines in 24 files covered. (100.0%)

438 of 500 relevant lines covered (87.6%)

2.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.25
/src/Downloader.php
1
<?php
2

3
namespace cweagans\Composer;
4

5
use Composer\Composer;
6
use cweagans\Composer\Downloader\DownloaderInterface;
7
use Composer\IO\IOInterface;
8
use cweagans\Composer\Capability\Downloader\DownloaderProvider;
9
use cweagans\Composer\Event\PluginEvent;
10
use cweagans\Composer\Event\PluginEvents;
11
use UnexpectedValueException;
12

13
class Downloader
14
{
15
    protected Composer $composer;
16

17
    protected IOInterface $io;
18

19
    protected array $disabledDownloaders;
20

21
    public function __construct(Composer $composer, IOInterface $io, array $disabledDownloaders)
22
    {
23
        $this->composer = $composer;
5✔
24
        $this->io = $io;
5✔
25
        $this->disabledDownloaders = $disabledDownloaders;
5✔
26
    }
27

28
    /**
29
     * Download a patch using the available downloaders.
30
     *
31
     * A downloader will update Patch->localPath if it was able to download the patch.
32
     *
33
     * @param Patch $patch
34
     *   The patch to download.
35
     */
36
    public function downloadPatch(Patch $patch)
37
    {
38
        foreach ($this->getDownloaders() as $downloader) {
5✔
39
            if (in_array(get_class($downloader), $this->disabledDownloaders, true)) {
5✔
40
                if ($this->io->isVerbose()) {
×
41
                    $this->io->write('<info>  - Skipping downloader ' . get_class($downloader) . '</info>');
×
42
                }
43
                continue;
×
44
            }
45

46
            $downloader->download($patch);
5✔
47

48
            if (isset($patch->localPath)) {
5✔
49
                return;
5✔
50
            }
51
        }
52
    }
53

54
    /**
55
     * Gather a list of all patch downloaders from all enabled Composer plugins.
56
     *
57
     * @return DownloaderInterface[]
58
     *   A list of Downloaders that are available.
59
     */
60
    protected function getDownloaders(): array
61
    {
62
        static $downloaders;
5✔
63
        if (!is_null($downloaders)) {
5✔
64
            return $downloaders;
4✔
65
        }
66

67
        $downloaders = [];
1✔
68
        $plugin_manager = $this->composer->getPluginManager();
1✔
69
        $capabilities = $plugin_manager->getPluginCapabilities(
1✔
70
            DownloaderProvider::class,
1✔
71
            ['composer' => $this->composer, 'io' => $this->io]
1✔
72
        );
1✔
73
        foreach ($capabilities as $capability) {
1✔
74
            /** @var DownloaderProvider $capability */
75
            $newDownloaders = $capability->getDownloaders();
1✔
76
            foreach ($newDownloaders as $downloader) {
1✔
77
                if (!$downloader instanceof DownloaderInterface) {
1✔
78
                    throw new UnexpectedValueException(
×
79
                        'Plugin capability ' . get_class($capability) . ' returned an invalid value.'
×
80
                    );
×
81
                }
82
            }
83
            $downloaders = array_merge($downloaders, $newDownloaders);
1✔
84
        }
85

86

87
        $event = new PluginEvent(PluginEvents::POST_DISCOVER_DOWNLOADERS, $downloaders);
1✔
88
        $this->composer->getEventDispatcher()->dispatch(PluginEvents::POST_DISCOVER_DOWNLOADERS, $event);
1✔
89
        $downloaders = $event->getCapabilities();
1✔
90

91
        return $downloaders;
1✔
92
    }
93
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc