Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/PublicCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ public function __construct(array $data)
$this->data = $data;
}

public function getPubliccodeYmlVersion(): string
{
return $this->data['publiccodeYmlVersion'];
}

public function getName(): string
{
return $this->data['name'];
}

public function getApplicationSuite(): ?string
{
return $this->data['applicationSuite'] ?? null;
}

public function getUrl(): string
{
return $this->data['url'];
Expand All @@ -30,6 +40,31 @@ public function getLandingUrl(): ?string
return $this->data['landingURL'] ?? null;
}

/**
* @return string[]
*/
public function getIsBasedOn(): array
{
if ($this->data['isBasedOn'] === null) {
return [];
}
if (is_string($this->data['isBasedOn'])) {
return [$this->data['isBasedOn']];
}

return $this->data['isBasedOn'];
}

public function getSoftwareVersion(): ?string
{
return $this->data['softwareVersion'] ?? null;
}

public function getLogo(): ?string
{
return $this->data['logo'] ?? null;
}

public function getDescription(string $language = 'en'): ?string
{
return $this->data['description'][$language]['shortDescription'] ?? null;
Expand Down Expand Up @@ -70,6 +105,11 @@ public function getCategories(): array
return $this->data['categories'];
}

public function getRoadmap(): ?string
{
return $this->data['roadmap'] ?? null;
}

public function getPlatforms(): array
{
return $this->data['platforms'];
Expand Down
8 changes: 7 additions & 1 deletion tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ParserTest extends TestCase

protected function setUp(): void
{
$path = __DIR__ . '/fixtures/valid.minimal.yml';
$path = __DIR__ . '/fixtures/valid.yml';

$this->parser = new Parser();

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

$this->assertEquals('0', $publicCode->getPubliccodeYmlVersion());
$this->assertEquals('Medusa', $publicCode->getName());
$this->assertEquals('mySuite', $publicCode->getApplicationSuite());
$this->assertEquals('https://github.com/italia/developers.italia.it.git', $publicCode->getUrl());
$this->assertEquals(null, $publicCode->getLandingUrl());
$this->assertEquals('0.10.11', $publicCode->getSoftwareVersion());
$this->assertEquals(null, $publicCode->getLogo());
$this->assertEquals('AGPL-3.0-or-later', $publicCode->getLicense());
$this->assertEquals(['web'], $publicCode->getPlatforms());
$this->assertEquals(null, $publicCode->getRoadmap());

$this->assertNotNull($publicCode->getDescription('en_GB'));
$this->assertNull($publicCode->getDescription('it'));
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/valid.minimal.yml → tests/fixtures/valid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ publiccodeYmlVersion: "0"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
applicationSuite: mySuite

platforms:
- web

categories:
- cloud-management

softwareVersion: "0.10.11"

developmentStatus: development

softwareType: "standalone/other"
Expand Down
Loading