Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
added narrowspark/coding-standard
Browse files Browse the repository at this point in the history
cs fixes and phpstan fixes
  • Loading branch information
danielbannert committed Jul 25, 2018
1 parent 3f2e10b commit ebbb58d
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 31 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ before_install:
chmod a+x ./build/travis/configure_php.sh
chmod a+x ./build/travis/script.sh
- ./build/travis/configure_php.sh
- composer validate

install:
- composer global require hirak/prestissimo
Expand Down
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@
"require-dev": {
"composer/composer": "^1.6.0",
"mockery/mockery": "^1.0.0",
"narrowspark/php-cs-fixer-config": "^3.0.1",
"narrowspark/coding-standard": "^1.0.0",
"narrowspark/testing-helper": "^6.0.0",
"phpstan/phpstan": "^0.9.0",
"phpstan/phpstan-phpunit": "^0.9.0",
"phpunit/phpunit": "^7.0.0",
"phpunit/phpunit": "^7.2.0",
"symfony/phpunit-bridge": "^4.0.8"
},
"config": {
Expand Down
9 changes: 9 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
includes:
# - vendor/pepakriz/phpstan-exception-rules/extension.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
# - vendor/phpstan/phpstan-strict-rules/rules.neon
# - vendor/thecodingmachine/phpstan-strict-rules/phpstan-strict-rules.neon

parameters:
autoload_directories:
- %currentWorkingDirectory%/src

excludes_analyse:
- %currentWorkingDirectory%/src/Discovery/Prefetcher/CurlDownloader.php

ignoreErrors:
# QuestionInstallationManager
- '#Call to an undefined method Composer\\Installer\\InstallationManager::getOperations#'
- '#\$package of method Composer\\Package\\Version\\VersionSelector\:\:findRecommendedRequireVersion\(\) expects Composer\\Package\\PackageInterface, Composer\\Package\\PackageInterface\|true given#'
# ScriptExecutor
- '#Call to static method cerebroBinary\(\) on an unknown class Viserio\\Component\\Console\\Application#'
- '#Parameter \#1 \$stream of class Symfony\\Component\\Console\\Output\\StreamOutput constructor expects resource, resource\|false given#'

- '#Call to an undefined method Composer\\DependencyResolver\\Operation\\OperationInterface\:\:getPackage#'

Expand All @@ -22,5 +30,6 @@ parameters:
- '#Call to an undefined method Composer\\Downloader\\DownloaderInterface\:\:getCacheKey#'
# ParallelDownloader
- '#Call to an undefined static method Composer\\Util\\RemoteFilesystem\:\:getRemoteContents#'
- '#Call to function method_exists\(\) with #'
# Discovery
- '#does not call parent constructor from Composer\\Repository\\ComposerRepository#'
2 changes: 1 addition & 1 deletion src/Common/Configurator/AbstractConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function write($messages): void
*/
protected function isFileMarked(string $packageName, string $file): bool
{
return \is_file($file) && \mb_strpos(\file_get_contents($file), \sprintf('###> %s ###', $packageName)) !== false;
return \is_file($file) && \mb_strpos((string) \file_get_contents($file), \sprintf('###> %s ###', $packageName)) !== false;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Common/Traits/ExpandTargetDirTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
trait ExpandTargetDirTrait
{
/**
* @param array $options
* @param string $target
* @param string[] $options
* @param string $target
*
* @return string
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Discovery/ClassFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function find(string $directory): array

/** @var \SplFileInfo $file */
foreach ($finder as $file) {
$realPath = $file->getRealPath();
$realPath = (string) $file->getRealPath();
$class = self::findClassOrTraitOrInterface($realPath);

// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
Expand Down Expand Up @@ -50,7 +50,7 @@ public static function find(string $directory): array
private static function findClassOrTraitOrInterface(string $path): ?string
{
$namespace = null;
$tokens = \token_get_all(\file_get_contents($path));
$tokens = \token_get_all((string) \file_get_contents($path));

foreach ($tokens as $key => $token) {
if (\is_array($token)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Discovery/Configurator/EnvConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function unconfigure(PackageContract $package): void
$contents = \preg_replace(
\sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $package->getName(), $package->getName(), "\n"),
'',
\file_get_contents($env),
(string) \file_get_contents($env),
-1,
$count
);
Expand Down
2 changes: 1 addition & 1 deletion src/Discovery/Configurator/GitIgnoreConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function unconfigure(PackageContract $package): void
$contents = \preg_replace(
\sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $package->getName(), $package->getName(), "\n"),
"\n",
\file_get_contents($file),
(string) \file_get_contents($file),
-1,
$count
);
Expand Down
22 changes: 14 additions & 8 deletions src/Discovery/Discovery.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ public function onCommand(CommandEvent $event): void
if ($event->getInput()->hasOption('no-suggest')) {
$event->getInput()->setOption('no-suggest', true);
}

if ($event->getInput()->hasOption('remove-vcs')) {
$event->getInput()->setOption('remove-vcs', true);
}
}

/**
Expand Down Expand Up @@ -621,11 +625,11 @@ private function updateComposerLock(): void
$lockFile,
$this->composer->getRepositoryManager(),
$this->composer->getInstallationManager(),
$composerJson
(string) $composerJson
);

$lockData = $locker->getLockData();
$lockData['_content-hash'] = Locker::getContentHash($composerJson);
$lockData['_content-hash'] = Locker::getContentHash((string) $composerJson);

$lockFile->write($lockData);
}
Expand Down Expand Up @@ -786,14 +790,16 @@ private function doUninstall(PackageContract $package, PackageConfigurator $pack
*/
private function getErrorMessage(): ?string
{
$errorMessage = null;

if (! \extension_loaded('openssl')) {
$errorMessage = 'You must enable the openssl extension in your "php.ini" file.';
} elseif (\version_compare('1.6', Composer::VERSION, '>')) {
$errorMessage = \sprintf('Your version "%s" of Composer is too old; Please upgrade.', Composer::VERSION);
return 'You must enable the openssl extension in your "php.ini" file.';
}

\preg_match_all('/\d+.\d+.\d+/m', Composer::VERSION, $matches, \PREG_SET_ORDER, 0);

if ($matches !== null && \version_compare('1.6.0', $matches[0], '<=')) {
return \sprintf('Your version "%s" of Composer is too old; Please upgrade.', Composer::VERSION);
}

return $errorMessage;
return null;
}
}
2 changes: 1 addition & 1 deletion src/Discovery/Installer/ConfiguratorInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function saveConfiguratorsToLockFile(array $autoload, string $name): a
}

if ($this->lock->has(self::LOCK_KEY)) {
$configurators = \array_merge($this->lock->get(self::LOCK_KEY), $configurators);
$configurators = \array_merge((array) $this->lock->get(self::LOCK_KEY), $configurators);
}

$this->lock->add(self::LOCK_KEY, $configurators);
Expand Down
4 changes: 2 additions & 2 deletions src/Discovery/Installer/QuestionInstallationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function uninstall(PackageContract $package, array $dependencies): array
$this->addDiscoveryInstallationManagerToComposer($oldInstallManager);

$this->updateComposerJson(
\array_merge($dependencies, $package->getOption('selected-question-packages') ?? []),
\array_merge($dependencies, (array) $package->getOption('selected-question-packages')),
self::REMOVE
);

Expand Down Expand Up @@ -233,7 +233,7 @@ private function askDependencyQuestion(string $question, array $packages): strin
$ask,
function ($input) use ($packageNames) {
/** @codeCoverageIgnoreStart */
$input = \is_numeric($input) ? (int) \trim($input) : -1;
$input = \is_numeric($input) ? (int) \trim((string) $input) : -1;

return $packageNames[$input] ?? null;
// @codeCoverageIgnoreEnd
Expand Down
2 changes: 1 addition & 1 deletion src/Discovery/Prefetcher/CurlDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private function onProgress($ch, callable $notify, array $progress, array $previ
return;
}

if (! $previousProgress['http_code'] && $progress['http_code'] && $progress['http_code'] < 200 || $progress['http_code'] <= 400) {
if (! ($previousProgress['http_code'] && $progress['http_code'] && $progress['http_code'] < 200) || $progress['http_code'] <= 400) {
$code = 403 === $progress['http_code'] ? \STREAM_NOTIFY_AUTH_RESULT : \STREAM_NOTIFY_FAILURE;
$notify($code, \STREAM_NOTIFY_SEVERITY_ERR, \curl_error($ch), $progress['http_code'], 0, 0, false);
}
Expand Down
12 changes: 7 additions & 5 deletions src/Discovery/Prefetcher/ParallelDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function __construct(IOInterface $io, Config $config, array $options = []
{
$this->io = $io;

if (! \method_exists(parent::class, 'getRemoteContents')) {
if (! \method_exists(RemoteFilesystem::class, 'getRemoteContents')) {
$this->io->writeError('Composer >=1.7 not found, downloads will happen in sequence', true, IOInterface::DEBUG);
// @codeCoverageIgnoreStart
} elseif (! \extension_loaded('curl')) {
Expand Down Expand Up @@ -142,12 +142,12 @@ public function download(array &$nextArgs, callable $nextCallback, bool $quiet =
];

if (! $this->quiet) {
if (! $this->downloader && \method_exists(parent::class, 'getRemoteContents')) {
if ($this->downloader !== null && \method_exists(RemoteFilesystem::class, 'getRemoteContents')) {
$this->io->writeError('<warning>Enable the "cURL" PHP extension for faster downloads</warning>');
}

$note = \DIRECTORY_SEPARATOR === '\\' ? '' : (\mb_stripos(\PHP_OS, 'darwin') !== false ? '🎵' : '🎶');
$note .= $this->downloader ? (\DIRECTORY_SEPARATOR !== '\\' ? ' 💨' : '') : '';
$note .= $this->downloader !== null ? (\DIRECTORY_SEPARATOR !== '\\' ? ' 💨' : '') : '';

$this->io->writeError('');
$this->io->writeError(\sprintf('<info>Prefetching %d packages</info> %s', $this->downloadCount, $note));
Expand Down Expand Up @@ -323,7 +323,7 @@ protected function getRemoteContents($originUrl, $fileUrl, $context)
return self::$cache[$fileUrl] = $this->getRemoteContents($originUrl, $fileUrl, $context);
}

if (! $this->downloader) {
if ($this->downloader !== null) {
return parent::getRemoteContents($originUrl, $fileUrl, $context);
}

Expand Down Expand Up @@ -352,7 +352,9 @@ private function getNext(): void
try {
$state->maxNestingReached = false;

($this->nextCallback)(...\array_shift($state->nextArgs));
if ($this->nextCallback !== null) {
($this->nextCallback)(...\array_shift($state->nextArgs));
}
} catch (TransportException $exception) {
$this->io->writeError('Skipping download: ' . $exception->getMessage(), true, IOInterface::DEBUG);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Discovery/ScriptExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public function execute(string $type, string $cmd): void
return;
}

/** @param resource $resource */
$resource = \fopen('php://memory', 'rwb');
$cmdOutput = new StreamOutput(
\fopen('php://memory', 'rw'),
$resource,
OutputInterface::VERBOSITY_VERBOSE,
$this->io->isDecorated()
);
Expand All @@ -108,7 +110,7 @@ public function execute(string $type, string $cmd): void

\fseek($cmdOutput->getStream(), 0);

foreach (\explode("\n", \stream_get_contents($cmdOutput->getStream())) as $line) {
foreach (\explode("\n", (string) \stream_get_contents($cmdOutput->getStream())) as $line) {
$this->io->writeError('!! ' . $line);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ private function arrangeSimpleRootPackage(string $stability = 'dev')
*
* @return \Narrowspark\Discovery\Package
*/
private function arrangeInstallPackage(string $name)
private function arrangeInstallPackage(string $name): \Narrowspark\Discovery\Package
{
return new Package(
$name,
Expand Down

0 comments on commit ebbb58d

Please sign in to comment.