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

Commit 0274c08

Browse files
committed
updated narrowspark cs fixer config
cs fixes
1 parent ad6e25a commit 0274c08

35 files changed

+286
-234
lines changed

.php_cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<?php
22
use Narrowspark\CS\Config\Config;
33

4-
$config = new Config();
4+
$config = new Config(null, [
5+
'native_function_invocation' => [
6+
'exclude' => [
7+
'getcwd'
8+
],
9+
],
10+
]);
511
$config->getFinder()
612
->files()
713
->in(__DIR__)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"require-dev": {
2727
"composer/composer": "^1.6.0",
2828
"mockery/mockery": "^1.0.0",
29-
"narrowspark/php-cs-fixer-config": "^2.1.0",
29+
"narrowspark/php-cs-fixer-config": "^3.0.1",
3030
"narrowspark/testing-helper": "^6.0.0",
3131
"phpstan/phpstan": "^0.9.0",
3232
"phpstan/phpstan-phpunit": "^0.9.0",

src/Discovery/ClassFinder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function find(string $directory): array
2222
foreach ($finder as $file) {
2323
$realPath = $file->getRealPath();
2424
$class = self::findClassOrTraitOrInterface($realPath);
25-
25+
2626
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
2727
\gc_mem_caches();
2828

@@ -98,7 +98,7 @@ private static function getNamespace(int $key, array $tokens): ?string
9898
*/
9999
private static function isPartOfNamespace($token): bool
100100
{
101-
return \is_array($token) && ($token[0] === T_STRING || $token[0] === T_NS_SEPARATOR);
101+
return \is_array($token) && ($token[0] === \T_STRING || $token[0] === \T_NS_SEPARATOR);
102102
}
103103

104104
/**
@@ -134,7 +134,7 @@ private static function getClass($key, array $tokens): ?string
134134
*/
135135
private static function tokenIsNamespace(array $token): bool
136136
{
137-
return $token[0] === T_NAMESPACE;
137+
return $token[0] === \T_NAMESPACE;
138138
}
139139

140140
/**
@@ -146,7 +146,7 @@ private static function tokenIsNamespace(array $token): bool
146146
*/
147147
private static function isPartOfClass($token): bool
148148
{
149-
return \is_array($token) && $token[0] === T_STRING;
149+
return \is_array($token) && $token[0] === \T_STRING;
150150
}
151151

152152
/**
@@ -158,7 +158,7 @@ private static function isPartOfClass($token): bool
158158
*/
159159
private static function tokenIsClassOrTraitOrInterface(array $token): bool
160160
{
161-
return $token[0] === T_CLASS || $token[0] === T_INTERFACE || $token[0] === T_TRAIT;
161+
return $token[0] === \T_CLASS || $token[0] === \T_INTERFACE || $token[0] === \T_TRAIT;
162162
}
163163

164164
/**
@@ -170,6 +170,6 @@ private static function tokenIsClassOrTraitOrInterface(array $token): bool
170170
*/
171171
private static function isWhitespace($token): bool
172172
{
173-
return \is_array($token) && $token[0] === T_WHITESPACE;
173+
return \is_array($token) && $token[0] === \T_WHITESPACE;
174174
}
175175
}

src/Discovery/Configurator/EnvConfigurator.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function configure(PackageContract $package): void
4343
$value = '"' . \str_replace(['\\', '"', "\t", "\n"], ['\\\\', '\\"', '\t', '\n'], $value) . '"';
4444
}
4545

46-
$data .= "$key=$value\n";
46+
$data .= "${key}=${value}\n";
4747
}
4848

4949
if (! \file_exists(getcwd() . '/.env')) {
@@ -70,8 +70,7 @@ public function unconfigure(PackageContract $package): void
7070
if (! \file_exists($env)) {
7171
continue;
7272
}
73-
// @codeCoverageIgnoreEnd
74-
73+
/** @codeCoverageIgnoreEnd */
7574
$count = 0;
7675
$contents = \preg_replace(
7776
\sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $package->getName(), $package->getName(), "\n"),
@@ -87,7 +86,7 @@ public function unconfigure(PackageContract $package): void
8786
}
8887
// @codeCoverageIgnoreEnd
8988

90-
$this->write(sprintf('Removing environment variables from %s', $file));
89+
$this->write(\sprintf('Removing environment variables from %s', $file));
9190

9291
\file_put_contents($env, $contents);
9392
}

src/Discovery/Configurator/GitIgnoreConfigurator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function configure(PackageContract $package): void
3232

3333
foreach ($package->getConfiguratorOptions('gitignore') as $value) {
3434
$value = self::expandTargetDir($this->options, $value);
35-
$data .= "$value\n";
35+
$data .= "${value}\n";
3636
}
3737

3838
\file_put_contents($gitignore, "\n" . \ltrim($this->markData($package->getName(), $data), "\r\n"), \FILE_APPEND);
@@ -49,8 +49,7 @@ public function unconfigure(PackageContract $package): void
4949
if (! \file_exists($file)) {
5050
return;
5151
}
52-
// @codeCoverageIgnoreEnd
53-
52+
/** @codeCoverageIgnoreEnd */
5453
$count = 0;
5554
$contents = \preg_replace(
5655
\sprintf('{%s*###> %s ###.*###< %s ###%s+}s', "\n", $package->getName(), $package->getName(), "\n"),

src/Discovery/Discovery.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,10 @@ public static function getSubscribedEvents(): array
197197

198198
return [
199199
'auto-scripts' => 'executeAutoScripts',
200-
InstallerEvents::PRE_DEPENDENCIES_SOLVING => [['onPreDependenciesSolving', PHP_INT_MAX]],
201-
InstallerEvents::POST_DEPENDENCIES_SOLVING => [['populateFilesCacheDir', PHP_INT_MAX]],
202-
PackageEvents::PRE_PACKAGE_INSTALL => [['populateFilesCacheDir', ~PHP_INT_MAX]],
203-
PackageEvents::PRE_PACKAGE_UPDATE => [['populateFilesCacheDir', ~PHP_INT_MAX]],
200+
InstallerEvents::PRE_DEPENDENCIES_SOLVING => [['onPreDependenciesSolving', \PHP_INT_MAX]],
201+
InstallerEvents::POST_DEPENDENCIES_SOLVING => [['populateFilesCacheDir', \PHP_INT_MAX]],
202+
PackageEvents::PRE_PACKAGE_INSTALL => [['populateFilesCacheDir', ~\PHP_INT_MAX]],
203+
PackageEvents::PRE_PACKAGE_UPDATE => [['populateFilesCacheDir', ~\PHP_INT_MAX]],
204204
PackageEvents::POST_PACKAGE_INSTALL => 'record',
205205
PackageEvents::POST_PACKAGE_UPDATE => 'record',
206206
PackageEvents::POST_PACKAGE_UNINSTALL => 'record',
@@ -228,7 +228,7 @@ public function activate(Composer $composer, IOInterface $io): void
228228
// to avoid issues when Discovery is upgraded, we load all PHP classes now
229229
// that way, we are sure to use all files from the same version.
230230
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(\dirname(__DIR__), FilesystemIterator::SKIP_DOTS)) as $file) {
231-
// @var \SplFileInfo $file
231+
/** @var \SplFileInfo $file */
232232
if (\mb_substr($file->getFilename(), -4) === '.php') {
233233
require_once $file;
234234
}
@@ -531,9 +531,9 @@ public function whatProvides(Pool $pool, $name, $bypassFilters = false)
531531
}
532532

533533
$this->rfs->download($packages, function ($packageName, $constraint) use (&$listed, &$packages, $pool): void {
534-
// @var \Composer\Package\PackageInterface $package
534+
/** @var \Composer\Package\PackageInterface $package */
535535
foreach ($pool->whatProvides($packageName, $constraint, true) as $package) {
536-
// @var \Composer\Package\Link $link
536+
/** @var \Composer\Package\Link $link */
537537
foreach (\array_merge($package->getRequires(), $package->getConflicts(), $package->getReplaces()) as $link) {
538538
if (isset($listed[$link->getTarget()]) || \mb_strpos($link->getTarget(), '/') === false) {
539539
continue;

src/Discovery/Installer/InstallationManager.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
use Composer\Installer\InstallationManager as BaseInstallationManager;
1010
use Composer\Repository\RepositoryInterface;
1111

12-
/**
13-
* @internal
14-
*/
1512
class InstallationManager extends BaseInstallationManager
1613
{
1714
/**

src/Discovery/Installer/Installer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ private static function getPreferredInstallOptions(Config $config, InputInterfac
8484
// noop
8585
break;
8686
}
87-
// @codeCoverageIgnoreEnd
88-
87+
/** @codeCoverageIgnoreEnd */
8988
$preferSource = self::getOption($input, 'prefer-source', $preferSource);
9089
$preferDist = self::getOption($input, 'prefer-dist', $preferDist);
9190

src/Discovery/Installer/QuestionInstallationManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function install(PackageContract $package, array $dependencies): array
200200

201201
$this->packagesToInstall[$packageName] = $constraint;
202202

203-
$this->io->write(sprintf(
203+
$this->io->write(\sprintf(
204204
'Added package <info>%s</info> to composer.json with constraint <info>%s</info>;'
205205
. ' to upgrade, run <info>composer require %s:VERSION</info>',
206206
$packageName,
@@ -350,7 +350,7 @@ private function askDependencyQuestion(string $question, array $packages): strin
350350
$package = $this->io->askAndValidate(
351351
$ask,
352352
function ($input) use ($packageNames) {
353-
// @codeCoverageIgnoreStart
353+
/** @codeCoverageIgnoreStart */
354354
$input = \is_numeric($input) ? (int) \trim($input) : -1;
355355

356356
return $packageNames[$input] ?? null;

src/Discovery/Prefetcher/CurlDownloader.php

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ final class CurlDownloader
4848
*/
4949
private static $options = [
5050
'http' => [
51-
'method' => CURLOPT_CUSTOMREQUEST,
52-
'content' => CURLOPT_POSTFIELDS,
53-
'proxy' => CURLOPT_PROXY,
51+
'method' => \CURLOPT_CUSTOMREQUEST,
52+
'content' => \CURLOPT_POSTFIELDS,
53+
'proxy' => \CURLOPT_PROXY,
5454
],
5555
'ssl' => [
56-
'ciphers' => CURLOPT_SSL_CIPHER_LIST,
57-
'cafile' => CURLOPT_CAINFO,
58-
'capath' => CURLOPT_CAPATH,
56+
'ciphers' => \CURLOPT_SSL_CIPHER_LIST,
57+
'cafile' => \CURLOPT_CAINFO,
58+
'capath' => \CURLOPT_CAPATH,
5959
],
6060
];
6161

@@ -80,17 +80,17 @@ public function __construct()
8080
{
8181
$this->multiHandle = $mh = \curl_multi_init();
8282

83-
\curl_multi_setopt($mh, CURLMOPT_PIPELINING, /*CURLPIPE_HTTP1 | CURLPIPE_MULTIPLEX*/ 3);
83+
\curl_multi_setopt($mh, \CURLMOPT_PIPELINING, /*CURLPIPE_HTTP1 | CURLPIPE_MULTIPLEX*/ 3);
8484

8585
if (\defined('CURLMOPT_MAX_HOST_CONNECTIONS')) {
86-
\curl_multi_setopt($mh, CURLMOPT_MAX_HOST_CONNECTIONS, 10);
86+
\curl_multi_setopt($mh, \CURLMOPT_MAX_HOST_CONNECTIONS, 10);
8787
}
8888

8989
$this->shareHandle = $sh = \curl_share_init();
9090

91-
\curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_COOKIE);
92-
\curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
93-
\curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
91+
\curl_share_setopt($sh, \CURLSHOPT_SHARE, \CURL_LOCK_DATA_COOKIE);
92+
\curl_share_setopt($sh, \CURLSHOPT_SHARE, \CURL_LOCK_DATA_DNS);
93+
\curl_share_setopt($sh, \CURLSHOPT_SHARE, \CURL_LOCK_DATA_SSL_SESSION);
9494
}
9595

9696
/**
@@ -119,18 +119,18 @@ public function get(string $url, $context, ?string $file): array
119119
$headers = \array_diff($params['options']['http']['header'], ['Connection: close']);
120120

121121
if (! isset($params['options']['http']['protocol_version'])) {
122-
\curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
122+
\curl_setopt($ch, \CURLOPT_HTTP_VERSION, \CURL_HTTP_VERSION_1_0);
123123
} else {
124124
$headers[] = 'Connection: keep-alive';
125125
}
126126

127-
\curl_setopt($ch, CURLOPT_URL, $url);
128-
\curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
129-
\curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
130-
\curl_setopt($ch, CURLOPT_DNS_USE_GLOBAL_CACHE, false);
131-
\curl_setopt($ch, CURLOPT_WRITEHEADER, $hd);
132-
\curl_setopt($ch, CURLOPT_FILE, $fd);
133-
\curl_setopt($ch, CURLOPT_SHARE, $this->shareHandle);
127+
\curl_setopt($ch, \CURLOPT_URL, $url);
128+
\curl_setopt($ch, \CURLOPT_HTTPHEADER, $headers);
129+
\curl_setopt($ch, \CURLOPT_FOLLOWLOCATION, true);
130+
\curl_setopt($ch, \CURLOPT_DNS_USE_GLOBAL_CACHE, false);
131+
\curl_setopt($ch, \CURLOPT_WRITEHEADER, $hd);
132+
\curl_setopt($ch, \CURLOPT_FILE, $fd);
133+
\curl_setopt($ch, \CURLOPT_SHARE, $this->shareHandle);
134134

135135
foreach (self::$options as $type => $options) {
136136
foreach ($options as $name => $curlopt) {
@@ -152,7 +152,7 @@ public function get(string $url, $context, ?string $file): array
152152

153153
\curl_multi_add_handle($this->multiHandle, $ch);
154154

155-
$params['notification'](STREAM_NOTIFY_RESOLVE, STREAM_NOTIFY_SEVERITY_INFO, '', 0, 0, 0, false);
155+
$params['notification'](\STREAM_NOTIFY_RESOLVE, \STREAM_NOTIFY_SEVERITY_INFO, '', 0, 0, 0, false);
156156

157157
$active = true;
158158

@@ -166,7 +166,7 @@ public function get(string $url, $context, ?string $file): array
166166
continue;
167167
}
168168

169-
$progress = array_diff_key(\curl_getinfo($h), self::$timeInfo);
169+
$progress = \array_diff_key(\curl_getinfo($h), self::$timeInfo);
170170
$job = $this->jobs[$i];
171171

172172
unset($this->jobs[$i]);
@@ -180,7 +180,7 @@ public function get(string $url, $context, ?string $file): array
180180
throw new TransportException(\curl_error($h));
181181
}
182182

183-
if ($job['file'] && \curl_errno($h) === CURLE_OK && ! isset($this->exceptions[$i])) {
183+
if ($job['file'] && \curl_errno($h) === \CURLE_OK && ! isset($this->exceptions[$i])) {
184184
\fclose($job['fd']);
185185
\rename($job['file'] . '~', $job['file']);
186186
}
@@ -214,8 +214,8 @@ public function get(string $url, $context, ?string $file): array
214214
}
215215
}
216216

217-
if (\curl_error($ch) !== '' || \curl_errno($ch) !== CURLE_OK) {
218-
$this->exceptions[(int) $ch] = new TransportException(\curl_error($ch), \curl_getinfo($ch, CURLINFO_HTTP_CODE) ?: 0);
217+
if (\curl_error($ch) !== '' || \curl_errno($ch) !== \CURLE_OK) {
218+
$this->exceptions[(int) $ch] = new TransportException(\curl_error($ch), \curl_getinfo($ch, \CURLINFO_HTTP_CODE) ?: 0);
219219
}
220220

221221
if (isset($this->exceptions[(int) $ch])) {
@@ -260,16 +260,16 @@ private function onProgress($ch, callable $notify, array $progress, array $previ
260260
}
261261

262262
if (! $previousProgress['http_code'] && $progress['http_code'] && $progress['http_code'] < 200 || $progress['http_code'] <= 400) {
263-
$code = 403 === $progress['http_code'] ? STREAM_NOTIFY_AUTH_RESULT : STREAM_NOTIFY_FAILURE;
264-
$notify($code, STREAM_NOTIFY_SEVERITY_ERR, \curl_error($ch), $progress['http_code'], 0, 0, false);
263+
$code = 403 === $progress['http_code'] ? \STREAM_NOTIFY_AUTH_RESULT : \STREAM_NOTIFY_FAILURE;
264+
$notify($code, \STREAM_NOTIFY_SEVERITY_ERR, \curl_error($ch), $progress['http_code'], 0, 0, false);
265265
}
266266

267267
if ($previousProgress['download_content_length'] < $progress['download_content_length']) {
268-
$notify(STREAM_NOTIFY_FILE_SIZE_IS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, 0, (int) $progress['download_content_length'], false);
268+
$notify(\STREAM_NOTIFY_FILE_SIZE_IS, \STREAM_NOTIFY_SEVERITY_INFO, '', 0, 0, (int) $progress['download_content_length'], false);
269269
}
270270

271271
if ($previousProgress['size_download'] < $progress['size_download']) {
272-
$notify(STREAM_NOTIFY_PROGRESS, STREAM_NOTIFY_SEVERITY_INFO, '', 0, (int) $progress['size_download'], (int) $progress['download_content_length'], false);
272+
$notify(\STREAM_NOTIFY_PROGRESS, \STREAM_NOTIFY_SEVERITY_INFO, '', 0, (int) $progress['size_download'], (int) $progress['download_content_length'], false);
273273
}
274274
}
275275
}

src/Discovery/Prefetcher/ParallelDownloader.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ public function __construct(IOInterface $io, Config $config, array $options = []
101101
{
102102
$this->io = $io;
103103

104-
if (! method_exists(parent::class, 'getRemoteContents')) {
104+
if (! \method_exists(parent::class, 'getRemoteContents')) {
105105
$this->io->writeError('Composer >=1.7 not found, downloads will happen in sequence', true, IOInterface::DEBUG);
106106
// @codeCoverageIgnoreStart
107-
} elseif (! extension_loaded('curl')) {
107+
} elseif (! \extension_loaded('curl')) {
108108
$this->io->writeError('ext-curl not found, downloads will happen in sequence', true, IOInterface::DEBUG);
109109
} else {
110110
$this->downloader = new CurlDownloader();
@@ -146,8 +146,8 @@ public function download(array &$nextArgs, callable $nextCallback, bool $quiet =
146146
$this->io->writeError('<warning>Enable the "cURL" PHP extension for faster downloads</warning>');
147147
}
148148

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

152152
$this->io->writeError('');
153153
$this->io->writeError(\sprintf('<info>Prefetching %d packages</info> %s', $this->downloadCount, $note));
@@ -253,7 +253,7 @@ public function getContents($originUrl, $fileUrl, $progress = true, $options = [
253253
*/
254254
public function callbackGet($notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax, $nativeDownload = true): void
255255
{
256-
if (! $nativeDownload && STREAM_NOTIFY_SEVERITY_ERR === $severity) {
256+
if (! $nativeDownload && \STREAM_NOTIFY_SEVERITY_ERR === $severity) {
257257
throw new TransportException($message, $messageCode);
258258
}
259259

@@ -263,12 +263,12 @@ public function callbackGet($notificationCode, $severity, $message, $messageCode
263263
return;
264264
}
265265

266-
if (STREAM_NOTIFY_FILE_SIZE_IS === $notificationCode) {
266+
if (\STREAM_NOTIFY_FILE_SIZE_IS === $notificationCode) {
267267
$state->bytesMaxCount++;
268268
$state->bytesMax += $bytesMax;
269269
}
270270

271-
if (! $bytesMax || STREAM_NOTIFY_PROGRESS !== $notificationCode) {
271+
if (! $bytesMax || \STREAM_NOTIFY_PROGRESS !== $notificationCode) {
272272
if ($state->nextArgs && ! $nativeDownload) {
273273
$this->getNext();
274274
}
@@ -352,7 +352,7 @@ private function getNext(): void
352352
try {
353353
$state->maxNestingReached = false;
354354

355-
($this->nextCallback)(...array_shift($state->nextArgs));
355+
($this->nextCallback)(...\array_shift($state->nextArgs));
356356
} catch (TransportException $exception) {
357357
$this->io->writeError('Skipping download: ' . $exception->getMessage(), true, IOInterface::DEBUG);
358358
}

src/Discovery/Prefetcher/Prefetcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ public function fetchAllFromOperations(InstallerEvent $event): void
188188

189189
$url = $this->getUrlFromPackage($package);
190190

191-
if ($url === null || ! $originUrl = \parse_url($url, PHP_URL_HOST)) {
191+
if ($url === null || ! $originUrl = \parse_url($url, \PHP_URL_HOST)) {
192192
continue;
193193
}
194194

195-
$destination = $this->cacheFilesDir . DIRECTORY_SEPARATOR . $this->getCacheKey($package, $url);
195+
$destination = $this->cacheFilesDir . \DIRECTORY_SEPARATOR . $this->getCacheKey($package, $url);
196196

197197
if (\file_exists($destination)) {
198198
continue;

0 commit comments

Comments
 (0)