diff --git a/phparkitect-baseline.json b/phparkitect-baseline.json index 951e143..dc3a3ca 100644 --- a/phparkitect-baseline.json +++ b/phparkitect-baseline.json @@ -24,21 +24,6 @@ "fqcn": "mxr576\\ddqgComposerAudit\\Infrastructure\\Composer\\UnsupportedPackageFinderConfigurationProvider", "line": 78, "error": "depends on mxr576\\ddqgComposerAudit\\Application\\PackageFinder\\Type\\PackageIgnoreRule, but should not depend on these namespaces: mxr576\\ddqgComposerAudit\\Application, mxr576\\ddqgComposerAudit\\Presentation, mxr576\\ddqgComposerAudit\\Supportive because The Infrastructure layer should only depend on the Domain layer and on external namespaces. It is better if it does not depend on anything from Application. (See exceptions in baseline.)" - }, - { - "fqcn": "mxr576\\ddqgComposerAudit\\Presentation\\Composer\\Plugin", - "line": 86, - "error": "depends on mxr576\\ddqgComposerAudit\\Infrastructure\\Composer\\InstalledPackagesReadOnlyRepository, but should not depend on these namespaces: mxr576\\ddqgComposerAudit\\Domain, mxr576\\ddqgComposerAudit\\Infrastructure because The Presentation layer should only depend on the Application layer, stuff in Supportive and external namespaces." - }, - { - "fqcn": "mxr576\\ddqgComposerAudit\\Presentation\\Composer\\Plugin", - "line": 89, - "error": "depends on mxr576\\ddqgComposerAudit\\Infrastructure\\Composer\\InstalledPackagesReadOnlyRepository, but should not depend on these namespaces: mxr576\\ddqgComposerAudit\\Domain, mxr576\\ddqgComposerAudit\\Infrastructure because The Presentation layer should only depend on the Application layer, stuff in Supportive and external namespaces." - }, - { - "fqcn": "mxr576\\ddqgComposerAudit\\Presentation\\Composer\\Plugin", - "line": 89, - "error": "depends on mxr576\\ddqgComposerAudit\\Infrastructure\\Composer\\InstalledPackagesReadOnlyRepository, but should not depend on these namespaces: mxr576\\ddqgComposerAudit\\Domain, mxr576\\ddqgComposerAudit\\Infrastructure because The Presentation layer should only depend on the Application layer, stuff in Supportive and external namespaces." } ], "stopOnFailure": false diff --git a/src/Presentation/Composer/Plugin.php b/src/Presentation/Composer/Plugin.php index 9c53e2d..39d4565 100644 --- a/src/Presentation/Composer/Plugin.php +++ b/src/Presentation/Composer/Plugin.php @@ -22,13 +22,12 @@ use Composer\Package\Version\VersionParser; use Composer\Plugin\PluginInterface; use Composer\Repository\InstalledRepository; -use mxr576\ddqgComposerAudit\Infrastructure\Composer\InstalledPackagesReadOnlyRepository; use mxr576\ddqgComposerAudit\Presentation\Composer\Repository\ComposerAuditRepository; use mxr576\ddqgComposerAudit\Supportive\Adapter\Composer\DeprecatedPackageWasIgnoredAdapter; use mxr576\ddqgComposerAudit\Supportive\Adapter\Composer\UnsupportedPackageWasIgnoredAdapter; use mxr576\ddqgComposerAudit\Supportive\Factory\FindDeprecatedPackagesFactoryFromComposerRuntimeDependencies; use mxr576\ddqgComposerAudit\Supportive\Factory\FindInsecurePackagesFactoryFromComposerRuntimeDependencies; -use mxr576\ddqgComposerAudit\Supportive\Factory\FindNonDrupal10CompatiblePackagesFactoryFromComposerRuntimeDependencies; +use mxr576\ddqgComposerAudit\Supportive\Factory\FindNonDrupal10CompatiblePackagesFactory; use mxr576\ddqgComposerAudit\Supportive\Factory\FindUnsupportedPackagesFactoryFromComposerRuntimeDependencies; use Symfony\Component\Console\Input\InputInterface; @@ -82,15 +81,15 @@ public function activate(Composer $composer, IOInterface $io): void } } - // @todo Fix layering rules. + $version_parser = new VersionParser(); + + $d10_factory = new FindNonDrupal10CompatiblePackagesFactory($composer->getPackage(), $version_parser); if ($locked_dependencies) { - $installed_packages_repository = InstalledPackagesReadOnlyRepository::fromLocker($composer->getLocker(), $with_dev_dependencies); + $d10_non_compatible_finder = $with_dev_dependencies ? $d10_factory->inLockedDependencies($composer->getLocker()) : $d10_factory->inLockedRequiredDependencies($composer->getLocker()); } else { - $composer_installed_repository = new InstalledRepository([$composer->getRepositoryManager()->getLocalRepository()]); - $installed_packages_repository = $with_dev_dependencies ? InstalledPackagesReadOnlyRepository::fromInstalledPackages($composer_installed_repository) : InstalledPackagesReadOnlyRepository::fromInstalledRequiredPackages($composer_installed_repository, $composer->getPackage()); + $d10_non_compatible_finder = $with_dev_dependencies ? $d10_factory->inInstalledDependencies(new InstalledRepository([$composer->getRepositoryManager()->getLocalRepository()])) : $d10_factory->inInstalledRequiredDependencies(new InstalledRepository([$composer->getRepositoryManager()->getLocalRepository()])); } - $version_parser = new VersionParser(); // Composer currently only displays advisories from one repository for // a package. If multiple ones provides advisories only the first one // is visible. @@ -123,7 +122,7 @@ public function activate(Composer $composer, IOInterface $io): void ); $composer->getRepositoryManager()->prependRepository( new ComposerAuditRepository( - (new FindNonDrupal10CompatiblePackagesFactoryFromComposerRuntimeDependencies($composer->getPackage(), $installed_packages_repository, $version_parser))->create(), + $d10_non_compatible_finder, $io ) ); diff --git a/src/Supportive/Factory/FindNonDrupal10CompatiblePackagesFactory.php b/src/Supportive/Factory/FindNonDrupal10CompatiblePackagesFactory.php new file mode 100644 index 0000000..8d27a78 --- /dev/null +++ b/src/Supportive/Factory/FindNonDrupal10CompatiblePackagesFactory.php @@ -0,0 +1,72 @@ +versionParser), + $this->versionParser, + new NonDrupal10CompatiblePackageFinderConfigurationProvider($this->rootPackage) + ); + } + + public function inInstalledRequiredDependencies(InstalledRepository $installedRepository): FindNonDrupal10CompatiblePackages + { + return new FindNonDrupal10CompatiblePackages( + new NonDrupal10CompatiblePackageVersionsProviderFromComposerLock(InstalledPackagesReadOnlyRepository::fromInstalledRequiredPackages($installedRepository, $this->rootPackage), $this->versionParser), + $this->versionParser, + new NonDrupal10CompatiblePackageFinderConfigurationProvider($this->rootPackage) + ); + } + + public function inLockedDependencies(Locker $locker): FindNonDrupal10CompatiblePackages + { + return new FindNonDrupal10CompatiblePackages( + new NonDrupal10CompatiblePackageVersionsProviderFromComposerLock(InstalledPackagesReadOnlyRepository::fromLocker($locker, true), $this->versionParser), + $this->versionParser, + new NonDrupal10CompatiblePackageFinderConfigurationProvider($this->rootPackage) + ); + } + + public function inLockedRequiredDependencies(Locker $locker): FindNonDrupal10CompatiblePackages + { + return new FindNonDrupal10CompatiblePackages( + new NonDrupal10CompatiblePackageVersionsProviderFromComposerLock(InstalledPackagesReadOnlyRepository::fromLocker($locker, false), $this->versionParser), + $this->versionParser, + new NonDrupal10CompatiblePackageFinderConfigurationProvider($this->rootPackage) + ); + } +} diff --git a/src/Supportive/Factory/FindNonDrupal10CompatiblePackagesFactoryFromComposerRuntimeDependencies.php b/src/Supportive/Factory/FindNonDrupal10CompatiblePackagesFactoryFromComposerRuntimeDependencies.php deleted file mode 100644 index fae56b7..0000000 --- a/src/Supportive/Factory/FindNonDrupal10CompatiblePackagesFactoryFromComposerRuntimeDependencies.php +++ /dev/null @@ -1,44 +0,0 @@ -installedPackageFinder, $this->versionParser), - $this->versionParser, - new NonDrupal10CompatiblePackageFinderConfigurationProvider($this->rootPackage) - ); - } -}