CS fixes
parent
8a154d7300
commit
dbfd47eeca
|
@ -173,7 +173,7 @@ class ClassMapGenerator
|
||||||
if ($name[0] === ':') {
|
if ($name[0] === ':') {
|
||||||
// This is an XHP class, https://github.com/facebook/xhp
|
// This is an XHP class, https://github.com/facebook/xhp
|
||||||
$name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1);
|
$name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1);
|
||||||
} else if ($matches['type'][$i] === 'enum') {
|
} elseif ($matches['type'][$i] === 'enum') {
|
||||||
// In Hack, something like:
|
// In Hack, something like:
|
||||||
// enum Foo: int { HERP = '123'; }
|
// enum Foo: int { HERP = '123'; }
|
||||||
// The regex above captures the colon, which isn't part of
|
// The regex above captures the colon, which isn't part of
|
||||||
|
|
|
@ -19,7 +19,6 @@ use Composer\Plugin\PluginEvents;
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
use Composer\Repository\RepositoryInterface;
|
use Composer\Repository\RepositoryInterface;
|
||||||
use Symfony\Component\Console\Helper\Table;
|
use Symfony\Component\Console\Helper\Table;
|
||||||
use Symfony\Component\Console\Helper\TableStyle;
|
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
|
@ -389,11 +389,11 @@ EOT
|
||||||
|
|
||||||
$licenses = $package->getLicense();
|
$licenses = $package->getLicense();
|
||||||
|
|
||||||
foreach($licenses as $licenseId) {
|
foreach ($licenses as $licenseId) {
|
||||||
$license = $spdxLicense->getLicenseByIdentifier($licenseId); // keys: 0 fullname, 1 osi, 2 url
|
$license = $spdxLicense->getLicenseByIdentifier($licenseId); // keys: 0 fullname, 1 osi, 2 url
|
||||||
|
|
||||||
// is license OSI approved?
|
// is license OSI approved?
|
||||||
if($license[1] === true) {
|
if ($license[1] === true) {
|
||||||
$out = sprintf('%s (%s) (OSI approved) %s', $license[0], $licenseId, $license[2]);
|
$out = sprintf('%s (%s) (OSI approved) %s', $license[0], $licenseId, $license[2]);
|
||||||
} else {
|
} else {
|
||||||
$out = sprintf('%s (%s) %s', $license[0], $licenseId, $license[2]);
|
$out = sprintf('%s (%s) %s', $license[0], $licenseId, $license[2]);
|
||||||
|
|
|
@ -126,6 +126,7 @@ class ConsoleIO extends BaseIO
|
||||||
if (true === $stderr && $this->output instanceof ConsoleOutputInterface) {
|
if (true === $stderr && $this->output instanceof ConsoleOutputInterface) {
|
||||||
$this->output->getErrorOutput()->write($messages, $newline);
|
$this->output->getErrorOutput()->write($messages, $newline);
|
||||||
$this->lastMessageErr = join($newline ? "\n" : '', (array) $messages);
|
$this->lastMessageErr = join($newline ? "\n" : '', (array) $messages);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,8 @@ class Git
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isAuthenticationFailure ($url, &$match) {
|
private function isAuthenticationFailure($url, &$match)
|
||||||
|
{
|
||||||
if (!preg_match('{(https?://)([^/]+)(.*)$}i', $url, $match)) {
|
if (!preg_match('{(https?://)([^/]+)(.*)$}i', $url, $match)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,229 +1,229 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of Composer.
|
* This file is part of Composer.
|
||||||
*
|
*
|
||||||
* (c) Nils Adermann <naderman@naderman.de>
|
* (c) Nils Adermann <naderman@naderman.de>
|
||||||
* Jordi Boggiano <j.boggiano@seld.be>
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Composer\Util;
|
namespace Composer\Util;
|
||||||
|
|
||||||
use Composer\Json\JsonFile;
|
use Composer\Json\JsonFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supports composer array and SPDX tag notation for disjunctive/conjunctive
|
* Supports composer array and SPDX tag notation for disjunctive/conjunctive
|
||||||
* licenses.
|
* licenses.
|
||||||
*
|
*
|
||||||
* @author Tom Klingenberg <tklingenberg@lastflood.net>
|
* @author Tom Klingenberg <tklingenberg@lastflood.net>
|
||||||
*/
|
*/
|
||||||
class SpdxLicense
|
class SpdxLicense
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $licenses;
|
private $licenses;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->loadLicenses();
|
$this->loadLicenses();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadLicenses()
|
private function loadLicenses()
|
||||||
{
|
{
|
||||||
if(is_array($this->licenses)) {
|
if (is_array($this->licenses)) {
|
||||||
return $this->licenses;
|
return $this->licenses;
|
||||||
}
|
}
|
||||||
|
|
||||||
$jsonFile = new JsonFile(__DIR__ . '/../../../res/spdx-licenses.json');
|
$jsonFile = new JsonFile(__DIR__ . '/../../../res/spdx-licenses.json');
|
||||||
$this->licenses = $jsonFile->read();
|
$this->licenses = $jsonFile->read();
|
||||||
|
|
||||||
return $this->licenses;
|
return $this->licenses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns license metadata by license identifier.
|
* Returns license metadata by license identifier.
|
||||||
*
|
*
|
||||||
* @param string $identifier
|
* @param string $identifier
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getLicenseByIdentifier($identifier)
|
public function getLicenseByIdentifier($identifier)
|
||||||
{
|
{
|
||||||
$license = $this->licenses[$identifier];
|
$license = $this->licenses[$identifier];
|
||||||
|
|
||||||
// add URL for the license text (it's not included in the json)
|
// add URL for the license text (it's not included in the json)
|
||||||
$license[2] = 'http://spdx.org/licenses/' . $identifier . '#licenseText';
|
$license[2] = 'http://spdx.org/licenses/' . $identifier . '#licenseText';
|
||||||
|
|
||||||
return $license;
|
return $license;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the short identifier of a license by full name.
|
* Returns the short identifier of a license by full name.
|
||||||
*
|
*
|
||||||
* @param string $identifier
|
* @param string $identifier
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getIdentifierByName($name)
|
public function getIdentifierByName($name)
|
||||||
{
|
{
|
||||||
foreach ($this->licenses as $identifier => $licenseData) {
|
foreach ($this->licenses as $identifier => $licenseData) {
|
||||||
if($licenseData[0] === $name) { // key 0 = fullname
|
if ($licenseData[0] === $name) { // key 0 = fullname
|
||||||
return $identifier;
|
return $identifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the OSI Approved status for a license by identifier.
|
* Returns the OSI Approved status for a license by identifier.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isOsiApprovedByIdentifier($identifier)
|
public function isOsiApprovedByIdentifier($identifier)
|
||||||
{
|
{
|
||||||
return $this->licenses[$identifier][1]; // key 1 = osi approved
|
return $this->licenses[$identifier][1]; // key 1 = osi approved
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check, if the identifier for a license is valid.
|
* Check, if the identifier for a license is valid.
|
||||||
*
|
*
|
||||||
* @param string $identifier
|
* @param string $identifier
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function isValidLicenseIdentifier($identifier)
|
private function isValidLicenseIdentifier($identifier)
|
||||||
{
|
{
|
||||||
$identifiers = array_keys($this->licenses);
|
$identifiers = array_keys($this->licenses);
|
||||||
|
|
||||||
return in_array($identifier, $identifiers);
|
return in_array($identifier, $identifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array|string $license
|
* @param array|string $license
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function validate($license)
|
public function validate($license)
|
||||||
{
|
{
|
||||||
if (is_array($license)) {
|
if (is_array($license)) {
|
||||||
$count = count($license);
|
$count = count($license);
|
||||||
if ($count !== count(array_filter($license, 'is_string'))) {
|
if ($count !== count(array_filter($license, 'is_string'))) {
|
||||||
throw new \InvalidArgumentException('Array of strings expected.');
|
throw new \InvalidArgumentException('Array of strings expected.');
|
||||||
}
|
}
|
||||||
$license = $count > 1 ? '('.implode(' or ', $license).')' : (string) reset($license);
|
$license = $count > 1 ? '('.implode(' or ', $license).')' : (string) reset($license);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_string($license)) {
|
if (!is_string($license)) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new \InvalidArgumentException(sprintf(
|
||||||
'Array or String expected, %s given.', gettype($license)
|
'Array or String expected, %s given.', gettype($license)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->isValidLicenseString($license);
|
return $this->isValidLicenseString($license);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $license
|
* @param string $license
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
private function isValidLicenseString($license)
|
private function isValidLicenseString($license)
|
||||||
{
|
{
|
||||||
$tokens = array(
|
$tokens = array(
|
||||||
'po' => '\(',
|
'po' => '\(',
|
||||||
'pc' => '\)',
|
'pc' => '\)',
|
||||||
'op' => '(?:or|and)',
|
'op' => '(?:or|and)',
|
||||||
'lix' => '(?:NONE|NOASSERTION)',
|
'lix' => '(?:NONE|NOASSERTION)',
|
||||||
'lir' => 'LicenseRef-\d+',
|
'lir' => 'LicenseRef-\d+',
|
||||||
'lic' => '[-+_.a-zA-Z0-9]{3,}',
|
'lic' => '[-+_.a-zA-Z0-9]{3,}',
|
||||||
'ws' => '\s+',
|
'ws' => '\s+',
|
||||||
'_' => '.',
|
'_' => '.',
|
||||||
);
|
);
|
||||||
|
|
||||||
$next = function () use ($license, $tokens) {
|
$next = function () use ($license, $tokens) {
|
||||||
static $offset = 0;
|
static $offset = 0;
|
||||||
|
|
||||||
if ($offset >= strlen($license)) {
|
if ($offset >= strlen($license)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($tokens as $name => $token) {
|
foreach ($tokens as $name => $token) {
|
||||||
if (false === $r = preg_match('{' . $token . '}', $license, $matches, PREG_OFFSET_CAPTURE, $offset)) {
|
if (false === $r = preg_match('{' . $token . '}', $license, $matches, PREG_OFFSET_CAPTURE, $offset)) {
|
||||||
throw new \RuntimeException('Pattern for token %s failed (regex error).', $name);
|
throw new \RuntimeException('Pattern for token %s failed (regex error).', $name);
|
||||||
}
|
}
|
||||||
if ($r === 0) {
|
if ($r === 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($matches[0][1] !== $offset) {
|
if ($matches[0][1] !== $offset) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$offset += strlen($matches[0][0]);
|
$offset += strlen($matches[0][0]);
|
||||||
|
|
||||||
return array($name, $matches[0][0]);
|
return array($name, $matches[0][0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \RuntimeException('At least the last pattern needs to match, but it did not (dot-match-all is missing?).');
|
throw new \RuntimeException('At least the last pattern needs to match, but it did not (dot-match-all is missing?).');
|
||||||
};
|
};
|
||||||
|
|
||||||
$open = 0;
|
$open = 0;
|
||||||
$require = 1;
|
$require = 1;
|
||||||
$lastop = null;
|
$lastop = null;
|
||||||
|
|
||||||
while (list($token, $string) = $next()) {
|
while (list($token, $string) = $next()) {
|
||||||
switch ($token) {
|
switch ($token) {
|
||||||
case 'po':
|
case 'po':
|
||||||
if ($open || !$require) {
|
if ($open || !$require) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$open = 1;
|
$open = 1;
|
||||||
break;
|
break;
|
||||||
case 'pc':
|
case 'pc':
|
||||||
if ($open !== 1 || $require || !$lastop) {
|
if ($open !== 1 || $require || !$lastop) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$open = 2;
|
$open = 2;
|
||||||
break;
|
break;
|
||||||
case 'op':
|
case 'op':
|
||||||
if ($require || !$open) {
|
if ($require || !$open) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$lastop || $lastop = $string;
|
$lastop || $lastop = $string;
|
||||||
if ($lastop !== $string) {
|
if ($lastop !== $string) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$require = 1;
|
$require = 1;
|
||||||
break;
|
break;
|
||||||
case 'lix':
|
case 'lix':
|
||||||
if ($open) {
|
if ($open) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
goto lir;
|
goto lir;
|
||||||
case 'lic':
|
case 'lic':
|
||||||
if (!$this->isValidLicenseIdentifier($string)) {
|
if (!$this->isValidLicenseIdentifier($string)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Fall-through intended
|
// Fall-through intended
|
||||||
case 'lir':
|
case 'lir':
|
||||||
lir:
|
lir:
|
||||||
if (!$require) {
|
if (!$require) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$require = 0;
|
$require = 0;
|
||||||
break;
|
break;
|
||||||
case 'ws':
|
case 'ws':
|
||||||
break;
|
break;
|
||||||
case '_':
|
case '_':
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
throw new \RuntimeException(sprintf('Unparsed token: %s.', print_r($token, true)));
|
throw new \RuntimeException(sprintf('Unparsed token: %s.', print_r($token, true)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !($open % 2 || $require);
|
return !($open % 2 || $require);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,14 +42,14 @@ class SpdxLicensesUpdater
|
||||||
$trs = $xPath->query('//table//tbody//tr');
|
$trs = $xPath->query('//table//tbody//tr');
|
||||||
|
|
||||||
// iterate over each row in the table
|
// iterate over each row in the table
|
||||||
foreach($trs as $tr) {
|
foreach ($trs as $tr) {
|
||||||
$tds = $tr->getElementsByTagName('td'); // get the columns in this row
|
$tds = $tr->getElementsByTagName('td'); // get the columns in this row
|
||||||
|
|
||||||
if($tds->length < 4) {
|
if ($tds->length < 4) {
|
||||||
throw new \Exception('Obtaining the license table failed. Wrong table format. Found less than 4 cells in a row.');
|
throw new \Exception('Obtaining the license table failed. Wrong table format. Found less than 4 cells in a row.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if(trim($tds->item(3)->nodeValue) == 'License Text') {
|
if (trim($tds->item(3)->nodeValue) == 'License Text') {
|
||||||
$fullname = trim($tds->item(0)->nodeValue);
|
$fullname = trim($tds->item(0)->nodeValue);
|
||||||
$identifier = trim($tds->item(1)->nodeValue);
|
$identifier = trim($tds->item(1)->nodeValue);
|
||||||
$osiApproved = ((isset($tds->item(2)->nodeValue) && $tds->item(2)->nodeValue === 'Y')) ? true : false;
|
$osiApproved = ((isset($tds->item(2)->nodeValue) && $tds->item(2)->nodeValue === 'Y')) ? true : false;
|
||||||
|
@ -64,4 +64,4 @@ class SpdxLicensesUpdater
|
||||||
|
|
||||||
return $licenses;
|
return $licenses;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue