Skip to content

Commit 1dc83b2

Browse files
committed
feat: add more getters
1 parent dd3b10d commit 1dc83b2

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/PublicCode.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ public function __construct(array $data)
1515
$this->data = $data;
1616
}
1717

18+
public function getPubliccodeYmlVersion(): string
19+
{
20+
return $this->data['publiccodeYmlVersion'];
21+
}
22+
1823
public function getName(): string
1924
{
2025
return $this->data['name'];
2126
}
2227

28+
public function getApplicationSuite(): ?string
29+
{
30+
return $this->data['applicationSuite'] ?? null;
31+
}
32+
2333
public function getUrl(): string
2434
{
2535
return $this->data['url'];
@@ -30,6 +40,31 @@ public function getLandingUrl(): ?string
3040
return $this->data['landingURL'] ?? null;
3141
}
3242

43+
/**
44+
* @return string[]
45+
*/
46+
public function getIsBasedOn(): array
47+
{
48+
if ($this->data['isBasedOn'] === null) {
49+
return [];
50+
}
51+
if (is_string($this->data['isBasedOn'])) {
52+
return [$this->data['isBasedOn']];
53+
}
54+
55+
return $this->data['isBasedOn'];
56+
}
57+
58+
public function getSoftwareVersion(): ?string
59+
{
60+
return $this->data['softwareVersion'] ?? null;
61+
}
62+
63+
public function getLogo(): ?string
64+
{
65+
return $this->data['logo'] ?? null;
66+
}
67+
3368
public function getDescription(string $language = 'en'): ?string
3469
{
3570
return $this->data['description'][$language]['shortDescription'] ?? null;
@@ -70,6 +105,11 @@ public function getCategories(): array
70105
return $this->data['categories'];
71106
}
72107

108+
public function getRoadmap(): array
109+
{
110+
return $this->data['roadmap'];
111+
}
112+
73113
public function getPlatforms(): array
74114
{
75115
return $this->data['platforms'];

tests/ParserTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ParserTest extends TestCase
1414

1515
protected function setUp(): void
1616
{
17-
$path = __DIR__ . '/fixtures/valid.minimal.yml';
17+
$path = __DIR__ . '/fixtures/valid.yml';
1818

1919
$this->parser = new Parser();
2020

@@ -30,10 +30,16 @@ public function testPublicCodeAccessors(): void
3030
{
3131
$publicCode = $this->parser->parse($this->yaml);
3232

33+
$this->assertEquals('0', $publicCode->getPubliccodeYmlVersion());
3334
$this->assertEquals('Medusa', $publicCode->getName());
35+
$this->assertEquals("mySuite", $publicCode->getApplicationSuite());
3436
$this->assertEquals('https://github.com/italia/developers.italia.it.git', $publicCode->getUrl());
37+
$this->assertEquals(null, $publicCode->getLandingUrl());
38+
$this->assertEquals('0.10.11', $publicCode->getSoftwareVersion());
39+
$this->assertEquals(null, $publicCode->getLogo());
3540
$this->assertEquals('AGPL-3.0-or-later', $publicCode->getLicense());
3641
$this->assertEquals(['web'], $publicCode->getPlatforms());
42+
$this->assertEquals(null, $publicCode->getRoadmap());
3743

3844
$this->assertNotNull($publicCode->getDescription('en_GB'));
3945
$this->assertNull($publicCode->getDescription('it'));

tests/fixtures/valid.minimal.yml renamed to tests/fixtures/valid.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ publiccodeYmlVersion: "0"
22

33
name: Medusa
44
url: "https://github.com/italia/developers.italia.it.git"
5+
applicationSuite: mySuite
56

67
platforms:
78
- web
89

910
categories:
1011
- cloud-management
1112

13+
softwareVersion: "0.10.11"
14+
1215
developmentStatus: development
1316

1417
softwareType: "standalone/other"

0 commit comments

Comments
 (0)