Skip to content

Commit

Permalink
Merge pull request #18 from atelierdisko/master
Browse files Browse the repository at this point in the history
Retrieve list of license identifiers and names
  • Loading branch information
Seldaek authored Jan 31, 2018
2 parents 9d3bb03 + 4ba0692 commit ce461a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/SpdxLicenses.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class SpdxLicenses
* The array is indexed by license identifiers, which contain
* a numerically indexed array with license details.
*
* [ license identifier =>
* [ 0 => full name (string), 1 => osi certified (bool), 2 => deprecated (bool) ]
* [ lowercased license identifier =>
* [ 0 => identifier (string), 1 => full name (string), 2 => osi certified (bool), 3 => deprecated (bool) ]
* , ...
* ]
*
Expand All @@ -45,8 +45,8 @@ class SpdxLicenses
* The array is indexed by license exception identifiers, which contain
* a numerically indexed array with license exception details.
*
* [ exception identifier =>
* [ 0 => full name (string) ]
* [ lowercased exception identifier =>
* [ 0 => exception identifier (string), 1 => full name (string) ]
* , ...
* ]
*
Expand Down Expand Up @@ -95,6 +95,16 @@ public function getLicenseByIdentifier($identifier)
);
}

/**
* Returns all licenses information, keyed by the lowercased license identifier.
*
* @return array[] Each item is [ 0 => identifier (string), 1 => full name (string), 2 => osi certified (bool), 3 => deprecated (bool) ]
*/
public function getLicenses()
{
return $this->licenses;
}

/**
* Returns license exception metadata by license exception identifier.
*
Expand Down
12 changes: 12 additions & 0 deletions tests/SpdxLicensesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ public function testGetLicenseByIdentifier()
$this->assertNull($licenseNull);
}

public function testGetLicenses()
{
$results = $this->licenses->getLicenses();

$this->assertArrayHasKey('cc-by-sa-4.0', $results);
$this->assertArrayHasKey(0, $results['cc-by-sa-4.0']);
$this->assertEquals('CC-BY-SA-4.0', $results['cc-by-sa-4.0'][0]);
$this->assertEquals('Creative Commons Attribution Share Alike 4.0', $results['cc-by-sa-4.0'][1]);
$this->assertEquals(false, $results['cc-by-sa-4.0'][2]);
$this->assertEquals(false, $results['cc-by-sa-4.0'][3]);
}

public function testGetExceptionByIdentifier()
{
$licenseNull = $this->licenses->getExceptionByIdentifier('Font-exception-2.0-Errorl');
Expand Down

0 comments on commit ce461a2

Please sign in to comment.