Skip to content

Commit 6c0a8e3

Browse files
authored
Merge pull request #7 from codedmonkey/package-metadata
Refactor package metadata
2 parents 698d5e1 + 2b6bfc7 commit 6c0a8e3

35 files changed

+2129
-1094
lines changed

migrations/Version20260325114538.php

Lines changed: 850 additions & 0 deletions
Large diffs are not rendered by default.

phpstan.dist.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ parameters:
1111
- tests/bootstrap.php
1212
ignoreErrors:
1313
- '#^Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition\:\:children\(\)\.$#'
14-
- '#CodedMonkey\\Dirigent\\Doctrine\\Entity\\AbstractVersionLink given\.#'
15-
- '#^PHPDoc tag @var with type CodedMonkey\\Dirigent\\Doctrine\\Entity\\AbstractVersionLink is not subtype of native type#'
1614
- '#^Property CodedMonkey\\Dirigent\\Doctrine\\Entity\\[a-zA-Z]+\:\:\$id \(int\|null\) is never assigned int so it can be removed from the property type\.$#'
1715
-
1816
message: '#^Class CodedMonkey\\Dirigent\\Doctrine\\Entity\\TrackedEntity has an uninitialized readonly property \$createdAt\. Assign it in the constructor\.$#'

src/Controller/ApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function packageDistribution(Request $request, string $reference, string
128128
throw $this->createNotFoundException();
129129
}
130130

131-
if (null === $version = $this->versionRepository->findOneByNormalizedVersion($package, $versionName)) {
131+
if (null === $version = $this->versionRepository->findOneByNormalizedName($package, $versionName)) {
132132
throw $this->createNotFoundException();
133133
}
134134

src/Controller/Dashboard/DashboardPackagesInfoController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function versionInfo(#[MapPackage] Package $package, #[MapPackage] Versio
5252
return $this->render('dashboard/packages/package_info.html.twig', [
5353
'package' => $package,
5454
'version' => $version,
55+
'metadata' => $version->getCurrentMetadata(),
5556

5657
'dependentCount' => $dependentCount,
5758
'implementationCount' => $implementationCount,

src/Doctrine/Entity/AbstractVersionLink.php renamed to src/Doctrine/Entity/AbstractMetadataLink.php

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,71 @@
22

33
namespace CodedMonkey\Dirigent\Doctrine\Entity;
44

5+
use CodedMonkey\Dirigent\Entity\MetadataLinkType;
56
use Doctrine\DBAL\Types\Types;
67
use Doctrine\ORM\Mapping as ORM;
78

89
#[ORM\MappedSuperclass]
9-
abstract class AbstractVersionLink
10+
abstract class AbstractMetadataLink
1011
{
1112
#[ORM\Id]
1213
#[ORM\Column]
1314
#[ORM\GeneratedValue]
1415
private ?int $id = null;
1516

16-
protected Version $version;
17-
18-
#[ORM\Column]
19-
private int $index;
17+
protected Metadata $metadata;
2018

2119
#[ORM\Column(length: 191)]
2220
private string $linkedPackageName;
2321

2422
#[ORM\Column(type: Types::TEXT)]
2523
private string $linkedVersionConstraint;
2624

27-
public function getId(): ?int
28-
{
29-
return $this->id;
30-
}
31-
32-
public function getIndex(): int
33-
{
34-
return $this->index;
35-
}
25+
#[ORM\Column]
26+
private int $index;
3627

37-
public function setIndex(int $index): void
38-
{
28+
public function __construct(
29+
Metadata $metadata,
30+
string $linkedPackageName,
31+
string $linkedVersionConstraint,
32+
int $index,
33+
) {
34+
$this->metadata = $metadata;
35+
$this->linkedPackageName = $linkedPackageName;
36+
$this->linkedVersionConstraint = $linkedVersionConstraint;
3937
$this->index = $index;
38+
39+
$this->addToCollection();
4040
}
4141

42-
public function getVersion(): Version
42+
public function getId(): ?int
4343
{
44-
return $this->version;
44+
return $this->id;
4545
}
4646

47-
public function setVersion(Version $version): void
47+
public function getMetadata(): Metadata
4848
{
49-
$this->version = $version;
49+
return $this->metadata;
5050
}
5151

5252
public function getLinkedPackageName(): string
5353
{
5454
return $this->linkedPackageName;
5555
}
5656

57-
public function setLinkedPackageName(string $packageName): void
57+
public function getLinkedVersionConstraint(): string
5858
{
59-
$this->linkedPackageName = $packageName;
59+
return $this->linkedVersionConstraint;
6060
}
6161

62-
public function getLinkedVersionConstraint(): string
62+
public function getIndex(): int
6363
{
64-
return $this->linkedVersionConstraint;
64+
return $this->index;
6565
}
6666

67-
public function setLinkedVersionConstraint(string $packageVersion): void
67+
private function addToCollection(): void
6868
{
69-
$this->linkedVersionConstraint = $packageVersion;
69+
$linkType = MetadataLinkType::fromClass(static::class);
70+
$linkType->getMetadataLinks($this->metadata)->add($this);
7071
}
7172
}

0 commit comments

Comments
 (0)