Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
68 / 68
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DevToolsServiceProvider
100.00% covered (success)
100.00%
68 / 68
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 getFactories
100.00% covered (success)
100.00%
67 / 67
100.00% covered (success)
100.00%
1 / 1
1
 getExtensions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * Fast Forward Development Tools for PHP projects.
7 *
8 * This file is part of fast-forward/dev-tools project.
9 *
10 * @author   Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
11 * @license  https://opensource.org/licenses/MIT MIT License
12 *
13 * @see      https://github.com/php-fast-forward/
14 * @see      https://github.com/php-fast-forward/dev-tools
15 * @see      https://github.com/php-fast-forward/dev-tools/issues
16 * @see      https://php-fast-forward.github.io/dev-tools/
17 * @see      https://datatracker.ietf.org/doc/html/rfc2119
18 */
19
20namespace FastForward\DevTools\Container\ServiceProvider;
21
22use Composer\Plugin\Capability\CommandProvider;
23use FastForward\DevTools\Changelog\Checker\UnreleasedEntryChecker;
24use FastForward\DevTools\Changelog\Checker\UnreleasedEntryCheckerInterface;
25use FastForward\DevTools\Changelog\Manager\ChangelogManager;
26use FastForward\DevTools\Changelog\Manager\ChangelogManagerInterface;
27use FastForward\DevTools\Changelog\Parser\ChangelogParser;
28use FastForward\DevTools\Changelog\Parser\ChangelogParserInterface;
29use FastForward\DevTools\Changelog\Renderer\MarkdownRenderer;
30use FastForward\DevTools\Changelog\Renderer\MarkdownRendererInterface;
31use FastForward\DevTools\Composer\Capability\DevToolsCommandProvider;
32use FastForward\DevTools\Composer\Json\ComposerJson;
33use FastForward\DevTools\Composer\Json\ComposerJsonInterface;
34use FastForward\DevTools\Console\CommandLoader\DevToolsCommandLoader;
35use FastForward\DevTools\Console\Formatter\LogLevelOutputFormatter;
36use FastForward\DevTools\Console\Logger\OutputFormatLogger;
37use FastForward\DevTools\Console\Logger\Processor\CommandInputProcessor;
38use FastForward\DevTools\Console\Logger\Processor\CommandOutputProcessor;
39use FastForward\DevTools\Console\Logger\Processor\CompositeContextProcessor;
40use FastForward\DevTools\Console\Logger\Processor\ContextProcessorInterface;
41use FastForward\DevTools\Console\Output\GithubActionOutput;
42use FastForward\DevTools\Console\Output\OutputCapabilityDetector;
43use FastForward\DevTools\Console\Output\OutputCapabilityDetectorInterface;
44use FastForward\DevTools\Environment\Environment;
45use FastForward\DevTools\Environment\EnvironmentInterface;
46use FastForward\DevTools\Environment\RuntimeEnvironment;
47use FastForward\DevTools\Environment\RuntimeEnvironmentInterface;
48use FastForward\DevTools\Filesystem\Filesystem;
49use FastForward\DevTools\Filesystem\FilesystemInterface;
50use FastForward\DevTools\Filesystem\FinderFactory;
51use FastForward\DevTools\Filesystem\FinderFactoryInterface;
52use FastForward\DevTools\Git\GitClient;
53use FastForward\DevTools\Git\GitClientInterface;
54use FastForward\DevTools\GitAttributes\CandidateProvider;
55use FastForward\DevTools\GitAttributes\CandidateProviderInterface;
56use FastForward\DevTools\GitAttributes\ExistenceChecker;
57use FastForward\DevTools\GitAttributes\ExistenceCheckerInterface;
58use FastForward\DevTools\GitAttributes\ExportIgnoreFilter;
59use FastForward\DevTools\GitAttributes\ExportIgnoreFilterInterface;
60use FastForward\DevTools\GitAttributes\Merger as GitAttributesMerger;
61use FastForward\DevTools\GitAttributes\MergerInterface as GitAttributesMergerInterface;
62use FastForward\DevTools\GitAttributes\Reader as GitAttributesReader;
63use FastForward\DevTools\GitAttributes\ReaderInterface as GitAttributesReaderInterface;
64use FastForward\DevTools\GitAttributes\Writer as GitAttributesWriter;
65use FastForward\DevTools\GitAttributes\WriterInterface as GitAttributesWriterInterface;
66use FastForward\DevTools\GitIgnore\Merger;
67use FastForward\DevTools\GitIgnore\MergerInterface;
68use FastForward\DevTools\GitIgnore\Reader;
69use FastForward\DevTools\GitIgnore\ReaderInterface;
70use FastForward\DevTools\GitIgnore\Writer;
71use FastForward\DevTools\GitIgnore\WriterInterface;
72use FastForward\DevTools\License\Generator;
73use FastForward\DevTools\License\GeneratorInterface;
74use FastForward\DevTools\License\Resolver;
75use FastForward\DevTools\License\ResolverInterface;
76use FastForward\DevTools\Path\DevToolsPathResolver;
77use FastForward\DevTools\Path\WorkingProjectPathResolver;
78use FastForward\DevTools\Php\Extension;
79use FastForward\DevTools\Php\ExtensionInterface;
80use FastForward\DevTools\PhpUnit\Coverage\CoverageSummaryLoader;
81use FastForward\DevTools\PhpUnit\Coverage\CoverageSummaryLoaderInterface;
82use FastForward\DevTools\Process\ColorPreservingProcessEnvironmentConfigurator;
83use FastForward\DevTools\Process\CompositeProcessEnvironmentConfigurator;
84use FastForward\DevTools\Process\ProcessBuilder;
85use FastForward\DevTools\Process\ProcessBuilderInterface;
86use FastForward\DevTools\Process\ProcessEnvironmentConfiguratorInterface;
87use FastForward\DevTools\Process\ProcessQueue;
88use FastForward\DevTools\Process\ProcessQueueInterface;
89use FastForward\DevTools\Process\XdebugDisablingProcessEnvironmentConfigurator;
90use FastForward\DevTools\Project\ProjectCapabilitiesResolver;
91use FastForward\DevTools\Project\ProjectCapabilitiesResolverInterface;
92use FastForward\DevTools\Psr\Clock\SystemClock;
93use FastForward\DevTools\Resource\DifferInterface;
94use FastForward\DevTools\Resource\UnifiedDiffer;
95use FastForward\DevTools\SelfUpdate\ComposerSelfUpdateRunner;
96use FastForward\DevTools\SelfUpdate\ComposerSelfUpdateScopeResolver;
97use FastForward\DevTools\SelfUpdate\ComposerVersionChecker;
98use FastForward\DevTools\SelfUpdate\SelfUpdateRunnerInterface;
99use FastForward\DevTools\SelfUpdate\SelfUpdateScopeResolverInterface;
100use FastForward\DevTools\SelfUpdate\VersionCheckerInterface;
101use FastForward\DevTools\SelfUpdate\VersionCheckNotifier;
102use FastForward\DevTools\SelfUpdate\VersionCheckNotifierInterface;
103use FastForward\DevTools\SelfUpdate\WorkingDirectorySwitcher;
104use FastForward\DevTools\SelfUpdate\WorkingDirectorySwitcherInterface;
105use Interop\Container\ServiceProviderInterface;
106use Psr\Clock\ClockInterface;
107use Psr\Log\LoggerInterface;
108use SebastianBergmann\Diff\Output\DiffOutputBuilderInterface;
109use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
110use Symfony\Component\Config\FileLocator;
111use Symfony\Component\Config\FileLocatorInterface;
112use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
113use Symfony\Component\Console\Input\ArgvInput;
114use Symfony\Component\Console\Input\InputInterface;
115use Symfony\Component\Console\Output\ConsoleOutput;
116use Symfony\Component\Console\Output\ConsoleOutputInterface;
117use Symfony\Component\Console\Output\OutputInterface;
118use Twig\Loader\FilesystemLoader;
119use Twig\Loader\LoaderInterface;
120use function DI\create;
121use function DI\factory;
122use function DI\get;
123
124/**
125 * Registers the services exposed by the DevTools container.
126 */
127class DevToolsServiceProvider implements ServiceProviderInterface
128{
129    /**
130     * @return array
131     */
132    public function getFactories(): array
133    {
134        return [
135            // Process
136            EnvironmentInterface::class => get(Environment::class),
137            RuntimeEnvironmentInterface::class => get(RuntimeEnvironment::class),
138            ExtensionInterface::class => get(Extension::class),
139            OutputCapabilityDetectorInterface::class => get(OutputCapabilityDetector::class),
140            ProcessBuilderInterface::class => get(ProcessBuilder::class),
141            ProcessEnvironmentConfiguratorInterface::class => create(CompositeProcessEnvironmentConfigurator::class)
142                ->constructor([
143                    get(ColorPreservingProcessEnvironmentConfigurator::class),
144                    get(XdebugDisablingProcessEnvironmentConfigurator::class),
145                ]),
146            ProcessQueueInterface::class => get(ProcessQueue::class),
147
148            // Self-update
149            SelfUpdateRunnerInterface::class => get(ComposerSelfUpdateRunner::class),
150            SelfUpdateScopeResolverInterface::class => get(ComposerSelfUpdateScopeResolver::class),
151            VersionCheckerInterface::class => get(ComposerVersionChecker::class),
152            VersionCheckNotifierInterface::class => get(VersionCheckNotifier::class),
153            WorkingDirectorySwitcherInterface::class => get(WorkingDirectorySwitcher::class),
154
155            // Filesystem
156            FinderFactoryInterface::class => get(FinderFactory::class),
157            FilesystemInterface::class => get(Filesystem::class),
158
159            // Composer
160            ComposerJsonInterface::class => get(ComposerJson::class),
161
162            // Project
163            ProjectCapabilitiesResolverInterface::class => get(ProjectCapabilitiesResolver::class),
164
165            // Changelog
166            ChangelogManagerInterface::class => get(ChangelogManager::class),
167            ChangelogParserInterface::class => get(ChangelogParser::class),
168            MarkdownRendererInterface::class => get(MarkdownRenderer::class),
169            UnreleasedEntryCheckerInterface::class => get(UnreleasedEntryChecker::class),
170
171            // Git
172            GitClientInterface::class => get(GitClient::class),
173
174            // Symfony Components
175            FileLocatorInterface::class => factory(
176                static fn(): FileLocator => new FileLocator([
177                    WorkingProjectPathResolver::getProjectPath(),
178                    DevToolsPathResolver::getPackagePath(),
179                ])
180            ),
181
182            // PSR
183            LoggerInterface::class => get(OutputFormatLogger::class),
184            ClockInterface::class => get(SystemClock::class),
185
186            // Console
187            InputInterface::class => get(ArgvInput::class),
188            OutputInterface::class => get(ConsoleOutputInterface::class),
189            CommandLoaderInterface::class => get(DevToolsCommandLoader::class),
190            CommandProvider::class => get(DevToolsCommandProvider::class),
191            ConsoleOutputInterface::class => create(ConsoleOutput::class)
192                ->method('setVerbosity', ConsoleOutputInterface::VERBOSITY_VERBOSE)
193                ->method('setFormatter', get(LogLevelOutputFormatter::class)),
194            GithubActionOutput::class => create(GithubActionOutput::class)->constructor(
195                get(ConsoleOutputInterface::class),
196                get(RuntimeEnvironmentInterface::class)
197            ),
198            ContextProcessorInterface::class => create(CompositeContextProcessor::class)->constructor([
199                get(CommandInputProcessor::class),
200                get(CommandOutputProcessor::class),
201            ]),
202
203            // Coverage
204            CoverageSummaryLoaderInterface::class => get(CoverageSummaryLoader::class),
205
206            // Resource
207            DiffOutputBuilderInterface::class => get(UnifiedDiffOutputBuilder::class),
208            DifferInterface::class => get(UnifiedDiffer::class),
209
210            // GitIgnore
211            MergerInterface::class => get(Merger::class),
212            ReaderInterface::class => get(Reader::class),
213            WriterInterface::class => get(Writer::class),
214
215            // GitAttributes
216            CandidateProviderInterface::class => get(CandidateProvider::class),
217            ExistenceCheckerInterface::class => get(ExistenceChecker::class),
218            ExportIgnoreFilterInterface::class => get(ExportIgnoreFilter::class),
219            GitAttributesMergerInterface::class => get(GitAttributesMerger::class),
220            GitAttributesReaderInterface::class => get(GitAttributesReader::class),
221            GitAttributesWriterInterface::class => get(GitAttributesWriter::class),
222
223            // License
224            GeneratorInterface::class => get(Generator::class),
225            ResolverInterface::class => get(Resolver::class),
226
227            // Twig
228            LoaderInterface::class => create(FilesystemLoader::class)->constructor(
229                DevToolsPathResolver::getResourcesPath()
230            ),
231        ];
232    }
233
234    /**
235     * @return array
236     */
237    public function getExtensions(): array
238    {
239        return [];
240    }
241}