Skip to content

Commit

Permalink
Re-apply the CS fixes and update the .travis.yml file
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed Feb 5, 2019
1 parent 513b010 commit 7b05333
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
13 changes: 5 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
language: php

git:
depth: 1
dist: xenial

cache:
directories:
- $HOME/.composer/cache

sudo: false

env:
global:
- COMPOSER_ALLOW_XDEBUG=0
- COMPOSER_ROOT_VERSION='2.5.0'
- COMPOSER_ROOT_VERSION='2.7.0'

matrix:
include:
# Latest dependencies with all PHP versions
- php: 7.1
- php: 7.2
- php: 7.3

# Ignore the platform requirements for the upcoming PHP version
- php: nightly
env: COMPOSER_FLAGS='--ignore-platform-reqs'

# Generate the coverage with the latest PHP version
- php: 7.2
- php: 7.3
env: COVERAGE='--coverage-clover build/logs/clover.xml'

# Lowest dependencies with the oldest and latest PHP versions
- php: 7.1
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable' SYMFONY_DEPRECATIONS_HELPER='weak_vendors'
- php: 7.2
- php: 7.3
env: COMPOSER_FLAGS='--prefer-lowest --prefer-stable' SYMFONY_DEPRECATIONS_HELPER='weak_vendors'
allow_failures:
- php: nightly
Expand Down
32 changes: 17 additions & 15 deletions src/Composer/ArtifactsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ private function getComposerInformation(PackageInterface $package): ?array
$zip = new \ZipArchive();
$zip->open($package->getDistUrl());

if (0 == $zip->numFiles) {
if (!$zip->numFiles) {
return null;
}

$foundFileIndex = $this->locateFile($zip, 'composer.json');

if (false === $foundFileIndex) {
return null;
}

$configurationFileName = $zip->getNameIndex($foundFileIndex);

$composerFile = "zip://{$package->getDistUrl()}#$configurationFileName";
$json = file_get_contents($composerFile);

Expand All @@ -115,27 +115,29 @@ private function locateFile(\ZipArchive $zip, string $filename)
$indexOfShortestMatch = false;
$lengthOfShortestMatch = -1;

for ($i = 0; $i < $zip->numFiles; $i++) {
for ($i = 0; $i < $zip->numFiles; ++$i) {
$stat = $zip->statIndex($i);
if (strcmp(basename($stat['name']), $filename) === 0) {
$directoryName = dirname($stat['name']);
if ($directoryName === '.') {
//if composer.json is in root directory
//it has to be the one to use.

if (0 === strcmp(basename($stat['name']), $filename)) {
$directoryName = \dirname($stat['name']);

if ('.' === $directoryName) {
// If composer.json is in root directory, it has to be the one to use
return $i;
}

if (strpos($directoryName, '\\') !== false ||
strpos($directoryName, '/') !== false) {
//composer.json files below first directory are rejected
if (false !== strpos($directoryName, '\\') || false !== strpos($directoryName, '/')) {
// composer.json files below first directory are rejected
continue;
}

$length = strlen($stat['name']);
if ($indexOfShortestMatch === false || $length < $lengthOfShortestMatch) {
//Check it's not a directory.
$length = \strlen($stat['name']);

if (false === $indexOfShortestMatch || $length < $lengthOfShortestMatch) {
// Check it's not a directory
$contents = $zip->getFromIndex($i);
if ($contents !== false) {

if (false !== $contents) {
$indexOfShortestMatch = $i;
$lengthOfShortestMatch = $length;
}
Expand Down

0 comments on commit 7b05333

Please sign in to comment.