Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
60 / 60
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DevToolsServiceProvider
100.00% covered (success)
100.00%
60 / 60
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 getFactories
100.00% covered (success)
100.00%
59 / 59
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\ServiceProvider;
21
22use Composer\Plugin\Capability\CommandProvider;
23use FastForward\DevTools\Changelog\Manager\ChangelogManager;
24use FastForward\DevTools\Changelog\Manager\ChangelogManagerInterface;
25use FastForward\DevTools\Changelog\Parser\ChangelogParser;
26use FastForward\DevTools\Changelog\Parser\ChangelogParserInterface;
27use FastForward\DevTools\Composer\Capability\DevToolsCommandProvider;
28use FastForward\DevTools\Composer\Json\ComposerJson;
29use FastForward\DevTools\Composer\Json\ComposerJsonInterface;
30use FastForward\DevTools\Git\GitClient;
31use FastForward\DevTools\Git\GitClientInterface;
32use FastForward\DevTools\Changelog\Renderer\MarkdownRenderer;
33use FastForward\DevTools\Changelog\Renderer\MarkdownRendererInterface;
34use FastForward\DevTools\Changelog\Checker\UnreleasedEntryChecker;
35use FastForward\DevTools\Changelog\Checker\UnreleasedEntryCheckerInterface;
36use FastForward\DevTools\Console\CommandLoader\DevToolsCommandLoader;
37use FastForward\DevTools\Console\Formatter\LogLevelOutputFormatter;
38use FastForward\DevTools\Console\DevTools;
39use FastForward\DevTools\Console\Logger\OutputFormatLogger;
40use FastForward\DevTools\Console\Logger\Processor\CommandInputProcessor;
41use FastForward\DevTools\Console\Logger\Processor\CommandOutputProcessor;
42use FastForward\DevTools\Console\Logger\Processor\CompositeContextProcessor;
43use FastForward\DevTools\Console\Logger\Processor\ContextProcessorInterface;
44use FastForward\DevTools\Console\Output\GithubActionOutput;
45use FastForward\DevTools\Console\Output\OutputCapabilityDetector;
46use FastForward\DevTools\Console\Output\OutputCapabilityDetectorInterface;
47use FastForward\DevTools\Environment\Environment;
48use FastForward\DevTools\Environment\EnvironmentInterface;
49use FastForward\DevTools\Filesystem\FinderFactory;
50use FastForward\DevTools\Filesystem\FinderFactoryInterface;
51use FastForward\DevTools\Filesystem\Filesystem;
52use FastForward\DevTools\Filesystem\FilesystemInterface;
53use FastForward\DevTools\GitAttributes\CandidateProvider;
54use FastForward\DevTools\GitAttributes\CandidateProviderInterface;
55use FastForward\DevTools\GitAttributes\ExistenceChecker;
56use FastForward\DevTools\GitAttributes\ExistenceCheckerInterface;
57use FastForward\DevTools\GitAttributes\ExportIgnoreFilter;
58use FastForward\DevTools\GitAttributes\ExportIgnoreFilterInterface;
59use FastForward\DevTools\GitAttributes\Merger as GitAttributesMerger;
60use FastForward\DevTools\GitAttributes\MergerInterface as GitAttributesMergerInterface;
61use FastForward\DevTools\GitAttributes\Reader as GitAttributesReader;
62use FastForward\DevTools\GitAttributes\ReaderInterface as GitAttributesReaderInterface;
63use FastForward\DevTools\GitAttributes\Writer as GitAttributesWriter;
64use FastForward\DevTools\GitAttributes\WriterInterface as GitAttributesWriterInterface;
65use FastForward\DevTools\GitIgnore\Merger;
66use FastForward\DevTools\GitIgnore\MergerInterface;
67use FastForward\DevTools\GitIgnore\Reader;
68use FastForward\DevTools\GitIgnore\ReaderInterface;
69use FastForward\DevTools\GitIgnore\Writer;
70use FastForward\DevTools\GitIgnore\WriterInterface;
71use FastForward\DevTools\License\Generator;
72use FastForward\DevTools\License\GeneratorInterface;
73use FastForward\DevTools\License\Resolver;
74use FastForward\DevTools\License\ResolverInterface;
75use FastForward\DevTools\Php\Extension;
76use FastForward\DevTools\Php\ExtensionInterface;
77use FastForward\DevTools\PhpUnit\Coverage\CoverageSummaryLoader;
78use FastForward\DevTools\PhpUnit\Coverage\CoverageSummaryLoaderInterface;
79use FastForward\DevTools\Process\ColorPreservingProcessEnvironmentConfigurator;
80use FastForward\DevTools\Process\CompositeProcessEnvironmentConfigurator;
81use FastForward\DevTools\Process\ProcessBuilder;
82use FastForward\DevTools\Process\ProcessBuilderInterface;
83use FastForward\DevTools\Process\ProcessEnvironmentConfiguratorInterface;
84use FastForward\DevTools\Process\ProcessQueue;
85use FastForward\DevTools\Process\ProcessQueueInterface;
86use FastForward\DevTools\Process\XdebugDisablingProcessEnvironmentConfigurator;
87use FastForward\DevTools\Path\DevToolsPathResolver;
88use FastForward\DevTools\Path\WorkingProjectPathResolver;
89use FastForward\DevTools\Psr\Clock\SystemClock;
90use FastForward\DevTools\Resource\DifferInterface;
91use FastForward\DevTools\Resource\UnifiedDiffer;
92use Interop\Container\ServiceProviderInterface;
93use Psr\Clock\ClockInterface;
94use Psr\Log\LoggerInterface;
95use SebastianBergmann\Diff\Output\DiffOutputBuilderInterface;
96use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
97use Symfony\Component\Config\FileLocator;
98use Symfony\Component\Config\FileLocatorInterface;
99use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
100use Symfony\Component\Console\Input\ArgvInput;
101use Symfony\Component\Console\Input\InputInterface;
102use Symfony\Component\Console\Output\ConsoleOutput;
103use Symfony\Component\Console\Output\ConsoleOutputInterface;
104use Symfony\Component\Console\Output\OutputInterface;
105use Twig\Loader\FilesystemLoader;
106use Twig\Loader\LoaderInterface;
107
108use function DI\create;
109use function DI\get;
110
111/**
112 * DevToolsServiceProvider registers the services provided by this package.
113 *
114 * This class implements the ServiceProviderInterface from the PHP-Interop container package,
115 * allowing it to be used with any compatible dependency injection container.
116 */
117 class DevToolsServiceProvider implements ServiceProviderInterface
118{
119    /**
120     * @return array
121     */
122    public function getFactories(): array
123    {
124        return [
125            // Process
126            EnvironmentInterface::class => get(Environment::class),
127            ExtensionInterface::class => get(Extension::class),
128            OutputCapabilityDetectorInterface::class => get(OutputCapabilityDetector::class),
129            ProcessBuilderInterface::class => get(ProcessBuilder::class),
130            ProcessEnvironmentConfiguratorInterface::class => create(CompositeProcessEnvironmentConfigurator::class)
131                ->constructor([
132                    get(ColorPreservingProcessEnvironmentConfigurator::class),
133                    get(XdebugDisablingProcessEnvironmentConfigurator::class),
134                ]),
135            ProcessQueueInterface::class => get(ProcessQueue::class),
136
137            // Filesystem
138            FinderFactoryInterface::class => get(FinderFactory::class),
139            FilesystemInterface::class => get(Filesystem::class),
140
141            // Composer
142            ComposerJsonInterface::class => get(ComposerJson::class),
143
144            // Changelog
145            ChangelogManagerInterface::class => get(ChangelogManager::class),
146            ChangelogParserInterface::class => get(ChangelogParser::class),
147            MarkdownRendererInterface::class => get(MarkdownRenderer::class),
148            UnreleasedEntryCheckerInterface::class => get(UnreleasedEntryChecker::class),
149
150            // Git
151            GitClientInterface::class => get(GitClient::class),
152
153            // Symfony Components
154            FileLocatorInterface::class => create(FileLocator::class)->constructor([
155                WorkingProjectPathResolver::getProjectPath(),
156                DevToolsPathResolver::getPackagePath(),
157            ]),
158
159            // PSR
160            LoggerInterface::class => get(OutputFormatLogger::class),
161            ClockInterface::class => get(SystemClock::class),
162
163            // Console
164            InputInterface::class => get(ArgvInput::class),
165            OutputInterface::class => get(ConsoleOutputInterface::class),
166            CommandLoaderInterface::class => get(DevToolsCommandLoader::class),
167            DevTools::class => create(DevTools::class)->constructor(get(DevToolsCommandLoader::class)),
168            CommandProvider::class => get(DevToolsCommandProvider::class),
169            ConsoleOutputInterface::class => create(ConsoleOutput::class)
170                ->method('setVerbosity', ConsoleOutputInterface::VERBOSITY_VERBOSE)
171                ->method('setFormatter', get(LogLevelOutputFormatter::class)),
172            GithubActionOutput::class => create(GithubActionOutput::class)->constructor(
173                get(ConsoleOutputInterface::class),
174                get(EnvironmentInterface::class)
175            ),
176            ContextProcessorInterface::class => create(CompositeContextProcessor::class)->constructor([
177                get(CommandInputProcessor::class),
178                get(CommandOutputProcessor::class),
179            ]),
180
181            // Coverage
182            CoverageSummaryLoaderInterface::class => get(CoverageSummaryLoader::class),
183
184            // Resource
185            DiffOutputBuilderInterface::class => get(UnifiedDiffOutputBuilder::class),
186            DifferInterface::class => get(UnifiedDiffer::class),
187
188            // GitIgnore
189            MergerInterface::class => get(Merger::class),
190            ReaderInterface::class => get(Reader::class),
191            WriterInterface::class => get(Writer::class),
192
193            // GitAttributes
194            CandidateProviderInterface::class => get(CandidateProvider::class),
195            ExistenceCheckerInterface::class => get(ExistenceChecker::class),
196            ExportIgnoreFilterInterface::class => get(ExportIgnoreFilter::class),
197            GitAttributesMergerInterface::class => get(GitAttributesMerger::class),
198            GitAttributesReaderInterface::class => get(GitAttributesReader::class),
199            GitAttributesWriterInterface::class => get(GitAttributesWriter::class),
200
201            // License
202            GeneratorInterface::class => get(Generator::class),
203            ResolverInterface::class => get(Resolver::class),
204
205            // Twig
206            LoaderInterface::class => create(FilesystemLoader::class)->constructor(
207                DevToolsPathResolver::getResourcesPath()
208            ),
209        ];
210    }
211
212    /**
213     * @return array
214     */
215    public function getExtensions(): array
216    {
217        return [];
218    }
219}