Skip to content

Commit

Permalink
Privatize Dependency properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrieghe committed May 10, 2022
1 parent ea9f785 commit a0bac15
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Commands/CheckLicenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($notAllowedLicenses as $notAllowedLicense) {
$packagesUsingThisLicense = $this->usedLicensesParser->getPackagesWithLicense($notAllowedLicense, (bool)$input->getOption('no-dev'));
foreach ($packagesUsingThisLicense as $packageUsingThisLicense) {
if ($dependency->hasDependency($packageUsingThisLicense) || $dependency->name === $packageUsingThisLicense) {
if ($dependency->hasDependency($packageUsingThisLicense) || $dependency->is($packageUsingThisLicense)) {
$dependencyCheck = $dependencyCheck->addFailedDependency($packageUsingThisLicense, $notAllowedLicense);
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/Commands/Output/DependencyCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ public function addFailedDependency(string $dependency, string $license): self

public function renderNameWithLicense(): string
{
if (empty($this->dependency->license)) {
return $this->dependency->name;
}

return $this->dependency->name . ' [' . $this->dependency->license . ']';
return $this->dependency->renderNameWithLicense();
}

public function isAllowed(): bool
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Output/TableRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private function renderFailedLineWithCauseOfFailure(
return [
$this->renderBoolean($dependencyCheck->isAllowed()),
$dependencyCheck->renderNameWithLicense(),
$causeOfFailure->name . ' [' . $causeOfFailure->license . ']',
$causeOfFailure->renderNameWithLicense(),
];
}

Expand All @@ -137,7 +137,7 @@ private function renderAdditionalCauseOfFailure(Dependency $causeOfFailure): arr
return [
'',
'',
$causeOfFailure->name . ' [' . $causeOfFailure->license . ']',
$causeOfFailure->renderNameWithLicense(),
];
}
}
18 changes: 16 additions & 2 deletions src/Dependency.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@ final class Dependency
private array $subDependencies = [];

public function __construct(
public readonly string $name,
public readonly string $license,
private readonly string $name,
private readonly string $license,
) {
}

public function is(string $name): bool
{
return $this->name === $name;
}

public function renderNameWithLicense(): string
{
if (empty($this->license)) {
return $this->name;
}

return $this->name . ' [' . $this->license . ']';
}

public function addDependency(string $dependency): self
{
if (!$this->hasDependency($dependency)) {
Expand Down
13 changes: 2 additions & 11 deletions tests/DependencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@ class DependencyTest extends TestCase
/**
* @test
*/
public function itKnowsItsName(): void
public function itCanRenderNameWithLicense(): void
{
$dependency = new Dependency('foo', 'license');
$this->assertEquals('foo', $dependency->name);
}

/**
* @test
*/
public function itKnowsItsLicense(): void
{
$dependency = new Dependency('foo', 'license');
$this->assertEquals('license', $dependency->license);
$this->assertEquals('foo [license]', $dependency->renderNameWithLicense());
}

/**
Expand Down

0 comments on commit a0bac15

Please sign in to comment.