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

cweagans / composer-patches / 4110992550

pending completion
4110992550

Pull #447

github

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

457 of 457 new or added lines in 28 files covered. (100.0%)

456 of 570 relevant lines covered (80.0%)

3.29 hits per line

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

63.89
/src/Resolver.php
1
<?php
2

3
namespace cweagans\Composer;
4

5
use Composer\Composer;
6
use Composer\IO\IOInterface;
7
use Composer\IO\NullIO;
8
use cweagans\Composer\Capability\Resolver\ResolverProvider;
9
use cweagans\Composer\Event\PluginEvent;
10
use cweagans\Composer\Event\PluginEvents;
11
use cweagans\Composer\Resolver\ResolverInterface;
12
use LogicException;
13
use UnexpectedValueException;
14

15
class Resolver
16
{
17
    protected Composer $composer;
18

19
    protected IOInterface $io;
20

21
    protected IOInterface $inactive_io;
22

23
    protected array $disabledResolvers = [];
24

25
    public function __construct(Composer $composer, IOInterface $io, array $disabledResolvers)
26
    {
27
        $this->composer = $composer;
8✔
28
        $this->io = $io;
8✔
29
        $this->disabledResolvers = $disabledResolvers;
8✔
30
    }
31

32
    /**
33
     * Gather patches that need to be applied to the current set of packages.
34
     *
35
     * Note that this work is done unconditionally if this plugin is enabled,
36
     * even if patching is disabled in any way. The point where patches are applied
37
     * is where the work will be skipped. It's done this way to ensure that
38
     * patching can be disabled temporarily in a way that doesn't affect the
39
     * contents of composer.lock.
40
     */
41
    public function loadFromResolvers(): PatchCollection
42
    {
43
        $patchCollection = new PatchCollection();
8✔
44

45
        // Let each resolver discover patches and add them to the PatchCollection.
46
        /** @var ResolverInterface $resolver */
47
        foreach ($this->getPatchResolvers() as $resolver) {
8✔
48
            if (in_array(get_class($resolver), $this->disabledResolvers, true)) {
8✔
49
                if ($this->io->isVerbose()) {
×
50
                    $this->io->write(
×
51
                        '<info>  - Skipping resolver ' . get_class($resolver) . '</info>',
×
52
                        true,
×
53
                        IOInterface::VERBOSE
×
54
                    );
×
55
                }
56
                continue;
×
57
            }
58

59
            $resolver->resolve($patchCollection);
8✔
60
        }
61

62
        return $patchCollection;
8✔
63
    }
64

65
    public function silenceOutput(): void
66
    {
67
        $this->inactive_io = $this->io;
×
68
        $this->io = new NullIO();
×
69
    }
70

71
    public function unsilenceOutput(): void
72
    {
73
        $this->io = $this->inactive_io;
×
74
    }
75

76
    /**
77
     * Gather a list of all patch resolvers from all enabled Composer plugins.
78
     *
79
     * @return ResolverInterface[]
80
     *   A list of PatchResolvers to be run.
81
     */
82
    protected function getPatchResolvers(): array
83
    {
84
        $resolvers = [];
8✔
85
        $plugin_manager = $this->composer->getPluginManager();
8✔
86
        $capabilities = $plugin_manager->getPluginCapabilities(
8✔
87
            ResolverProvider::class,
8✔
88
            ['composer' => $this->composer, 'io' => $this->io]
8✔
89
        );
8✔
90
        foreach ($capabilities as $capability) {
8✔
91
            /** @var ResolverProvider $capability */
92
            $newResolvers = $capability->getResolvers();
8✔
93
            foreach ($newResolvers as $resolver) {
8✔
94
                if (!$resolver instanceof ResolverInterface) {
8✔
95
                    throw new UnexpectedValueException(
×
96
                        'Plugin capability ' . get_class($capability) . ' returned an invalid value.'
×
97
                    );
×
98
                }
99
            }
100
            $resolvers = array_merge($resolvers, $newResolvers);
8✔
101
        }
102

103
        $event = new PluginEvent(PluginEvents::POST_DISCOVER_RESOLVERS, $resolvers);
8✔
104
        $this->composer->getEventDispatcher()->dispatch(PluginEvents::POST_DISCOVER_RESOLVERS, $event);
8✔
105
        $resolvers = $event->getCapabilities();
8✔
106

107
        return $resolvers;
8✔
108
    }
109
}
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