SCA with PHP Inspections (EA Extended)

main
Vladimir Reznichenko 7 years ago
parent 6c1da86437
commit c8615358cb

@ -199,7 +199,7 @@ EOF;
$targetDirLoader = null;
$mainAutoload = $mainPackage->getAutoload();
if ($mainPackage->getTargetDir() && !empty($mainAutoload['psr-0'])) {
$levels = count(explode('/', $filesystem->normalizePath($mainPackage->getTargetDir())));
$levels = substr_count($filesystem->normalizePath($mainPackage->getTargetDir()), '/') + 1;
$prefixes = implode(', ', array_map(function ($prefix) {
return var_export($prefix, true);
}, array_keys($mainAutoload['psr-0'])));
@ -601,7 +601,7 @@ HEADER;
if ($useIncludePath) {
$file .= <<<'INCLUDE_PATH'
$includePaths = require __DIR__ . '/include_paths.php';
array_push($includePaths, get_include_path());
$includePaths[] = get_include_path();
set_include_path(implode(PATH_SEPARATOR, $includePaths));

@ -90,7 +90,7 @@ EOT
$args = $input->getArgument('args');
if (!is_null($timeout = $input->getOption('timeout'))) {
if (null !== $timeout = $input->getOption('timeout')) {
if (!ctype_digit($timeout)) {
throw new \RuntimeException('Timeout value must be numeric and positive if defined, or 0 for forever');
}

@ -88,7 +88,7 @@ EOT
continue;
}
foreach ($package['suggest'] as $suggestion => $reason) {
if (false === strpos('/', $suggestion) && !is_null($platform->findPackage($suggestion, '*'))) {
if (false === strpos('/', $suggestion) && null !== $platform->findPackage($suggestion, '*')) {
continue;
}
if (!isset($installed[$suggestion])) {

@ -171,7 +171,8 @@ EOT
);
$autocompleterValues = array();
foreach ($requires as $require) {
$autocompleterValues[strtolower($require->getTarget())] = $require->getTarget();
$target = $require->getTarget();
$autocompleterValues[strtolower($target)] = $target;
}
$installedPackages = $composer->getRepositoryManager()->getLocalRepository()->getPackages();

@ -283,7 +283,7 @@ class RuleSetGenerator
switch ($job['cmd']) {
case 'install':
if (!$job['fixed'] && $ignorePlatformReqs && preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $job['packageName'])) {
continue;
break; // or `continue 2` ?
}
$packages = $this->pool->whatProvides($job['packageName'], $job['constraint']);

@ -51,7 +51,7 @@ class RuleSetIterator implements \Iterator
return;
}
if ($this->currentOffset >= sizeof($this->rules[$this->currentType])) {
if ($this->currentOffset >= count($this->rules[$this->currentType])) {
$this->currentOffset = 0;
do {
@ -63,7 +63,7 @@ class RuleSetIterator implements \Iterator
}
$this->currentType = $this->types[$this->currentTypeOffset];
} while (isset($this->types[$this->currentTypeOffset]) && !sizeof($this->rules[$this->currentType]));
} while (isset($this->types[$this->currentTypeOffset]) && !count($this->rules[$this->currentType]));
}
}
@ -83,7 +83,7 @@ class RuleSetIterator implements \Iterator
}
$this->currentType = $this->types[$this->currentTypeOffset];
} while (isset($this->types[$this->currentTypeOffset]) && !sizeof($this->rules[$this->currentType]));
} while (isset($this->types[$this->currentTypeOffset]) && !count($this->rules[$this->currentType]));
}
public function valid()

@ -111,16 +111,16 @@ class Transaction
$packageId = $package->id;
if (!isset($visited[$packageId])) {
array_push($queue, $package);
$queue[] = $package;
if ($package instanceof AliasPackage) {
array_push($queue, $package->getAliasOf());
$queue[] = $package->getAliasOf();
} else {
foreach ($package->getRequires() as $link) {
$possibleRequires = $this->pool->whatProvides($link->getTarget(), $link->getConstraint());
foreach ($possibleRequires as $require) {
array_push($queue, $require);
$queue[] = $require;
}
}
}

@ -96,9 +96,7 @@ class PerforceDownloader extends VcsDownloader
*/
protected function getCommitLogs($fromReference, $toReference, $path)
{
$commitLogs = $this->perforce->getCommitLogs($fromReference, $toReference);
return $commitLogs;
return $this->perforce->getCommitLogs($fromReference, $toReference);
}
public function setPerforce($perforce)

@ -204,7 +204,7 @@ class Factory
if ($composerAuthEnv = getenv('COMPOSER_AUTH')) {
$authData = json_decode($composerAuthEnv, true);
if (is_null($authData)) {
if (null === $authData) {
throw new \UnexpectedValueException('COMPOSER_AUTH environment variable is malformed, should be a valid JSON object');
}
@ -437,7 +437,7 @@ class Factory
{
$composer = null;
try {
$composer = self::createComposer($io, $config->get('home') . '/composer.json', $disablePlugins, $config->get('home'), $fullLoad);
$composer = $this->createComposer($io, $config->get('home') . '/composer.json', $disablePlugins, $config->get('home'), $fullLoad);
} catch (\Exception $e) {
$io->writeError('Failed to initialize global composer: '.$e->getMessage(), true, IOInterface::DEBUG);
}

@ -223,9 +223,7 @@ class JsonFile
return $json;
}
$result = JsonFormatter::format($json, $unescapeUnicode, $unescapeSlashes);
return $result;
return JsonFormatter::format($json, $unescapeUnicode, $unescapeSlashes);
}
/**

@ -78,7 +78,7 @@ abstract class BaseRepository implements RepositoryInterface
foreach ($links as $link) {
foreach ($needles as $needle) {
if ($link->getTarget() === $needle) {
if (is_null($constraint) || (($link->getConstraint()->matches($constraint) === !$invert))) {
if ($constraint === null || ($link->getConstraint()->matches($constraint) === !$invert)) {
// already displayed this node's dependencies, cutting short
if (in_array($link->getSource(), $packagesInTree)) {
$results[$link->getSource()] = array($package, $link, false);

@ -158,8 +158,7 @@ class ChannelRest10Reader extends BaseChannelReader
$depthPath = '/r/' . strtolower($packageName) . '/deps.' . $version . '.txt';
$content = $this->requestContent($baseUrl, $depthPath);
$dependencyArray = unserialize($content);
$result = $dependencyReader->buildDependencyInfo($dependencyArray);
return $result;
return $dependencyReader->buildDependencyInfo($dependencyArray);
}
}

@ -216,10 +216,6 @@ class GitDriver extends VcsDriver
}
$process = new ProcessExecutor($io);
if ($process->execute('git ls-remote --heads ' . ProcessExecutor::escape($url), $output) === 0) {
return true;
}
return false;
return $process->execute('git ls-remote --heads ' . ProcessExecutor::escape($url), $output) === 0;
}
}

@ -87,9 +87,7 @@ class PerforceDriver extends VcsDriver
*/
public function getBranches()
{
$branches = $this->perforce->getBranches();
return $branches;
return $this->perforce->getBranches();
}
/**
@ -97,9 +95,7 @@ class PerforceDriver extends VcsDriver
*/
public function getTags()
{
$tags = $this->perforce->getTags();
return $tags;
return $this->perforce->getTags();
}
/**

@ -116,16 +116,14 @@ class Perforce
protected function executeCommand($command)
{
$this->commandResult = "";
$exit_code = $this->process->execute($command, $this->commandResult);
return $exit_code;
$this->commandResult = '';
return $this->process->execute($command, $this->commandResult);
}
public function getClient()
{
if (!isset($this->p4Client)) {
$cleanStreamName = str_replace('@', '', str_replace('/', '_', str_replace('//', '', $this->getStream())));
$cleanStreamName = str_replace(array('//', '/', '@'), array('', '_', ''), $this->getStream());
$this->p4Client = 'composer_perforce_' . $this->uniquePerforceClientName . '_' . $cleanStreamName;
}
@ -189,9 +187,7 @@ class Perforce
public function getP4ClientSpec()
{
$p4clientSpec = $this->path . '/' . $this->getClient() . '.p4.spec';
return $p4clientSpec;
return $this->path . '/' . $this->getClient() . '.p4.spec';
}
public function getUser()
@ -276,8 +272,7 @@ class Perforce
if ($useClient) {
$p4Command = $p4Command . '-c ' . $this->getClient() . ' ';
}
$p4Command = $p4Command . '-p ' . $this->getPort() . ' ';
$p4Command = $p4Command . $command;
$p4Command = $p4Command . '-p ' . $this->getPort() . ' ' . $command;
return $p4Command;
}
@ -538,9 +533,8 @@ class Perforce
return null;
}
$fields = explode(' ', $changes);
$changeList = $fields[1];
return $changeList;
return $fields[1];
}
/**
@ -562,9 +556,8 @@ class Perforce
$main = substr($fromReference, 0, $index) . '/...';
$command = $this->generateP4Command('filelog ' . $main . '@' . $fromChangeList. ',' . $toChangeList);
$this->executeCommand($command);
$result = $this->commandResult;
return $result;
return $this->commandResult;
}
public function getFilesystem()

@ -1031,10 +1031,6 @@ class RemoteFilesystem
// Path for a public download follows this pattern /{user}/{repo}/downloads/{whatever}
// {@link https://blog.bitbucket.org/2009/04/12/new-feature-downloads/}
$pathParts = explode('/', $path);
if (count($pathParts) >= 4 && $pathParts[3] == 'downloads') {
return true;
}
return false;
return count($pathParts) >= 4 && $pathParts[3] == 'downloads';
}
}

@ -36,7 +36,7 @@ class Silencer
$mask = E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE | E_DEPRECATED | E_USER_DEPRECATED | E_STRICT;
}
$old = error_reporting();
array_push(self::$stack, $old);
self::$stack[] = $old;
error_reporting($old & ~$mask);
return $old;

@ -139,7 +139,7 @@ final class StreamContextFactory
$phpVersion = 'PHP ' . PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;
}
if (!isset($options['http']['header']) || false === strpos(strtolower(implode('', $options['http']['header'])), 'user-agent')) {
if (!isset($options['http']['header']) || false === stripos(implode('', $options['http']['header']), 'user-agent')) {
$options['http']['header'][] = sprintf(
'User-Agent: Composer/%s (%s; %s; %s%s)',
Composer::VERSION === '@package_version@' ? 'source' : Composer::VERSION,

@ -24,7 +24,7 @@ class ComposerAutoloaderInitFilesAutoload
spl_autoload_unregister(array('ComposerAutoloaderInitFilesAutoload', 'loadClassLoader'));
$includePaths = require __DIR__ . '/include_paths.php';
array_push($includePaths, get_include_path());
$includePaths[] = get_include_path();
set_include_path(implode(PATH_SEPARATOR, $includePaths));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());

@ -92,9 +92,7 @@ class ArchiveManagerTest extends ArchiverTest
$packageName = $fileName;
}
$target = $this->targetDir.'/'.$packageName.'.'.$format;
return $target;
return $this->targetDir.'/'.$packageName.'.'.$format;
}
/**

@ -126,10 +126,7 @@ class ArrayLoaderTest extends \PHPUnit_Framework_TestCase
'abandoned' => 'foo/bar',
);
$validTestArguments = array($validConfig);
$argumentsToProvide = array($validTestArguments);
return $argumentsToProvide;
return array(array($validConfig));
}
protected function fixConfigWhenLoadConfigIsFalse($config)

@ -54,7 +54,7 @@ class GitHubTest extends \PHPUnit_Framework_TestCase
$this->isFalse(),
$this->anything()
)
->willReturn(sprintf('{}', $this->token))
->willReturn('{}')
;
$config = $this->getConfigMock();
@ -116,9 +116,7 @@ class GitHubTest extends \PHPUnit_Framework_TestCase
private function getConfigMock()
{
$config = $this->getMock('Composer\Config');
return $config;
return $this->getMock('Composer\Config');
}
private function getRemoteFilesystemMock()

@ -125,9 +125,7 @@ class GitLabTest extends \PHPUnit_Framework_TestCase
private function getConfigMock()
{
$config = $this->getMock('Composer\Config');
return $config;
return $this->getMock('Composer\Config');
}
private function getRemoteFilesystemMock()

Loading…
Cancel
Save