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;
120
121use function DI\create;
122use function DI\factory;
123use function DI\get;
124
125/**
126 * Registers the services exposed by the DevTools container.
127 */
128class DevToolsServiceProvider implements ServiceProviderInterface
129{
130    /**
131     * @return array
132     */
133    public function getFactories(): array
134    {
135        return [
136            // Process
137            EnvironmentInterface::class => get(Environment::class),
138            RuntimeEnvironmentInterface::class => get(RuntimeEnvironment::class),
139            ExtensionInterface::class => get(Extension::class),
140            OutputCapabilityDetectorInterface::class => get(OutputCapabilityDetector::class),
141            ProcessBuilderInterface::class => get(ProcessBuilder::class),
142            ProcessEnvironmentConfiguratorInterface::class => create(CompositeProcessEnvironmentConfigurator::class)
143                ->constructor([
144                    get(ColorPreservingProcessEnvironmentConfigurator::class),
145                    get(XdebugDisablingProcessEnvironmentConfigurator::class),
146                ]),
147            ProcessQueueInterface::class => get(ProcessQueue::class),
148
149            // Self-update
150            SelfUpdateRunnerInterface::class => get(ComposerSelfUpdateRunner::class),
151            SelfUpdateScopeResolverInterface::class => get(ComposerSelfUpdateScopeResolver::class),
152            VersionCheckerInterface::class => get(ComposerVersionChecker::class),
153            VersionCheckNotifierInterface::class => get(VersionCheckNotifier::class),
154            WorkingDirectorySwitcherInterface::class => get(WorkingDirectorySwitcher::class),
155
156            // Filesystem
157            FinderFactoryInterface::class => get(FinderFactory::class),
158            FilesystemInterface::class => get(Filesystem::class),
159
160            // Composer
161            ComposerJsonInterface::class => get(ComposerJson::class),
162
163            // Project
164            ProjectCapabilitiesResolverInterface::class => get(ProjectCapabilitiesResolver::class),
165
166            // Changelog
167            ChangelogManagerInterface::class => get(ChangelogManager::class),
168            ChangelogParserInterface::class => get(ChangelogParser::class),
169            MarkdownRendererInterface::class => get(MarkdownRenderer::class),
170            UnreleasedEntryCheckerInterface::class => get(UnreleasedEntryChecker::class),
171
172            // Git
173            GitClientInterface::class => get(GitClient::class),
174
175            // Symfony Components
176            FileLocatorInterface::class => factory(
177                static fn(): FileLocator => new FileLocator([
178                    WorkingProjectPathResolver::getProjectPath(),
179                    DevToolsPathResolver::getPackagePath(),
180                ])
181            ),
182
183            // PSR
184            LoggerInterface::class => get(OutputFormatLogger::class),
185            ClockInterface::class => get(SystemClock::class),
186
187            // Console
188            InputInterface::class => get(ArgvInput::class),
189            OutputInterface::class => get(ConsoleOutputInterface::class),
190            CommandLoaderInterface::class => get(DevToolsCommandLoader::class),
191            CommandProvider::class => get(DevToolsCommandProvider::class),
192            ConsoleOutputInterface::class => create(ConsoleOutput::class)
193                ->method('setVerbosity', ConsoleOutputInterface::VERBOSITY_VERBOSE)
194                ->method('setFormatter', get(LogLevelOutputFormatter::class)),
195            GithubActionOutput::class => create(GithubActionOutput::class)->constructor(
196                get(ConsoleOutputInterface::class),
197                get(RuntimeEnvironmentInterface::class)
198            ),
199            ContextProcessorInterface::class => create(CompositeContextProcessor::class)->constructor([
200                get(CommandInputProcessor::class),
201                get(CommandOutputProcessor::class),
202            ]),
203
204            // Coverage
205            CoverageSummaryLoaderInterface::class => get(CoverageSummaryLoader::class),
206
207            // Resource
208            DiffOutputBuilderInterface::class => get(UnifiedDiffOutputBuilder::class),
209            DifferInterface::class => get(UnifiedDiffer::class),
210
211            // GitIgnore
212            MergerInterface::class => get(Merger::class),
213            ReaderInterface::class => get(Reader::class),
214            WriterInterface::class => get(Writer::class),
215
216            // GitAttributes
217            CandidateProviderInterface::class => get(CandidateProvider::class),
218            ExistenceCheckerInterface::class => get(ExistenceChecker::class),
219            ExportIgnoreFilterInterface::class => get(ExportIgnoreFilter::class),
220            GitAttributesMergerInterface::class => get(GitAttributesMerger::class),
221            GitAttributesReaderInterface::class => get(GitAttributesReader::class),
222            GitAttributesWriterInterface::class => get(GitAttributesWriter::class),
223
224            // License
225            GeneratorInterface::class => get(Generator::class),
226            ResolverInterface::class => get(Resolver::class),
227
228            // Twig
229            LoaderInterface::class => create(FilesystemLoader::class)->constructor(
230                DevToolsPathResolver::getResourcesPath()
231            ),
232        ];
233    }
234
235    /**
236     * @return array
237     */
238    public function getExtensions(): array
239    {
240        return [];
241    }
242}