Skip to content

Commit

Permalink
Address layering rule issues introduced in 51d1211
Browse files Browse the repository at this point in the history
  • Loading branch information
mxr576 committed Jan 14, 2024
1 parent 51d1211 commit 7192602
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 67 deletions.
15 changes: 0 additions & 15 deletions phparkitect-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 7 additions & 8 deletions src/Presentation/Composer/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2023-2024 Dezső Biczó
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/mxr576/ddqg-composer-audit/LICENSE.md
*
*/

namespace mxr576\ddqgComposerAudit\Supportive\Factory;

use Composer\Package\Locker;
use Composer\Package\RootPackageInterface;
use Composer\Repository\InstalledRepository;
use Composer\Semver\VersionParser;
use mxr576\ddqgComposerAudit\Application\PackageFinder\FindNonDrupal10CompatiblePackages;
use mxr576\ddqgComposerAudit\Infrastructure\Composer\InstalledPackagesReadOnlyRepository;
use mxr576\ddqgComposerAudit\Infrastructure\Composer\NonDrupal10CompatiblePackageFinderConfigurationProvider;
use mxr576\ddqgComposerAudit\Supportive\Infrastructure\Composer\NonDrupal10CompatiblePackageVersionsProviderFromComposerLock;

/**
* @internal
*/
final class FindNonDrupal10CompatiblePackagesFactory
{
public function __construct(
private readonly RootPackageInterface $rootPackage,
private readonly VersionParser $versionParser,
) {
}

public function inInstalledDependencies(InstalledRepository $installedRepository): FindNonDrupal10CompatiblePackages
{
return new FindNonDrupal10CompatiblePackages(
new NonDrupal10CompatiblePackageVersionsProviderFromComposerLock(InstalledPackagesReadOnlyRepository::fromInstalledPackages($installedRepository), $this->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)
);
}
}

This file was deleted.

0 comments on commit 7192602

Please sign in to comment.