Skip to content

Commit

Permalink
chore: Various minor fixes reported by PHPStorm inspection
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Oct 7, 2023
1 parent 15f0116 commit 04765e8
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 85 deletions.
9 changes: 2 additions & 7 deletions requirement-checker/tests/IOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,9 @@ class IOTest extends TestCase
{
private static function getDefaultInteractive(): bool
{
if (function_exists('posix_isatty')
return !(function_exists('posix_isatty')
&& !@posix_isatty(STDOUT)
&& false === getenv('SHELL_INTERACTIVE')
) {
return false;
}

return true;
&& false === getenv('SHELL_INTERACTIVE'));
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/Compactor/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ private function retokenizeAttribute(array &$tokens, int $opener): ?array
{
Assert::keyExists($tokens, $opener);

/** @var PhpToken $token */
$token = $tokens[$opener];
$attributeBody = mb_substr($token->text, 2);
$subTokens = PhpToken::tokenize('<?php '.$attributeBody);
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/ComposerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

final class ComposerFile
{
private $path;
private $contents;
private string $path;
private array $contents;

public static function createEmpty(): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2038,7 +2038,7 @@ private static function retrieveReplacements(
}

/**
* @var string
* @var string $datetimeFormat
* @var bool $valueSetByUser
*/
[$datetimeFormat, $valueSetByUser] = self::retrieveDatetimeFormat($raw, $logger);
Expand Down
4 changes: 2 additions & 2 deletions src/Json/JsonValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
final class JsonValidationException extends UnexpectedValueException
{
private $validatedFile;
private $errors;
private ?string $validatedFile;
private array $errors;

/**
* @param string[] $errors
Expand Down
1 change: 1 addition & 0 deletions src/Pharaoh/PharDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ private function listAllFiles(string $folder, string $extension = '*'): array
* @var string[] $fileSub
*/
foreach ($files as $fileSub) {
// TODO: address this array_merge
$fileList = array_merge($fileList, $fileSub);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/BoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -748,10 +748,10 @@ public function test_it_artefacts_created_when_dumping_the_autoloader_are_added_
$this->box->startBuffering();
$this->box->addFiles(array_keys($files), false);
$this->box->endBuffering(static function () use (&$files): void {
FS::dumpFile('zip', '');
FS::dumpFile('zip');
$files['zip'] = '';

FS::dumpFile('zap', '');
FS::dumpFile('zap');
$files['zap'] = '';
});

Expand Down
2 changes: 1 addition & 1 deletion tests/Composer/ComposerOrchestratorComposer22Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function test_it_cannot_dump_the_autoloader_with_an_invalid_composer_json
): void {
FS::mirror(self::FIXTURES.'/dir000', $this->tmp);

FS::dumpFile('composer.json', '');
FS::dumpFile('composer.json');

try {
ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false);
Expand Down
2 changes: 1 addition & 1 deletion tests/Composer/ComposerOrchestratorComposer23Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function test_it_cannot_dump_the_autoloader_with_an_invalid_composer_json
): void {
FS::mirror(self::FIXTURES.'/dir000', $this->tmp);

FS::dumpFile('composer.json', '');
FS::dumpFile('composer.json');

try {
ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false);
Expand Down
2 changes: 1 addition & 1 deletion tests/Composer/ComposerOrchestratorComposer24Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function test_it_cannot_dump_the_autoloader_with_an_invalid_composer_json
): void {
FS::mirror(self::FIXTURES.'/dir000', $this->tmp);

FS::dumpFile('composer.json', '');
FS::dumpFile('composer.json');

try {
ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false);
Expand Down
78 changes: 39 additions & 39 deletions tests/Configuration/ConfigurationFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public function test_configured_files_are_relative_to_base_path_unless_they_are_

public function test_the_files_belonging_to_dev_packages_are_ignored_only_in_the_finder_config(): void
{
FS::dumpFile('composer.json', '{}', '');
FS::dumpFile('composer.json', '{}');
FS::dumpFile(
'composer.lock',
<<<'JSON'
Expand All @@ -354,19 +354,19 @@ public function test_the_files_belonging_to_dev_packages_are_ignored_only_in_the
}
JSON,
);
FS::dumpFile('vendor/composer/installed.json', '{}', '');
FS::dumpFile('vendor/composer/installed.json', '{}');

FS::touch('file0');
FS::touch('file1');

FS::dumpFile('vendor/acme/foo/af0', '');
FS::dumpFile('vendor/acme/foo/af1', '');
FS::dumpFile('vendor/acme/foo/af0');
FS::dumpFile('vendor/acme/foo/af1');

FS::dumpFile('vendor/acme/bar/ab0', '');
FS::dumpFile('vendor/acme/bar/ab1', '');
FS::dumpFile('vendor/acme/bar/ab0');
FS::dumpFile('vendor/acme/bar/ab1');

FS::dumpFile('vendor/acme/oof/ao0', '');
FS::dumpFile('vendor/acme/oof/ao1', '');
FS::dumpFile('vendor/acme/oof/ao0');
FS::dumpFile('vendor/acme/oof/ao1');

FS::mkdir('C');
FS::touch('C/fileC0');
Expand Down Expand Up @@ -1516,8 +1516,8 @@ public function test_the_composer_json_and_lock_files_are_always_included_even_w
FS::touch('B/fileB0');
FS::touch('B/fileB1');

FS::dumpFile('composer.json', '{}', '');
FS::dumpFile('composer.lock', '{}', '');
FS::dumpFile('composer.json', '{}');
FS::dumpFile('composer.lock', '{}');

$this->setConfig([
'files' => [
Expand Down Expand Up @@ -1840,7 +1840,7 @@ public function test_no_warning_is_given_when_the_installed_json_is_found_and_th

public function test_dev_files_are_excluded_or_included_depending_of_the_exclude_dev_files_setting(): void
{
FS::dumpFile('composer.json', '{}', '');
FS::dumpFile('composer.json', '{}');
FS::dumpFile(
'composer.lock',
<<<'JSON'
Expand All @@ -1855,16 +1855,16 @@ public function test_dev_files_are_excluded_or_included_depending_of_the_exclude
}
JSON,
);
FS::dumpFile('vendor/composer/installed.json', '{}', '');
FS::dumpFile('vendor/composer/installed.json', '{}');

FS::dumpFile('vendor/acme/foo/af0', '');
FS::dumpFile('vendor/acme/foo/af1', '');
FS::dumpFile('vendor/acme/foo/af0');
FS::dumpFile('vendor/acme/foo/af1');

FS::dumpFile('vendor/acme/bar/ab0', '');
FS::dumpFile('vendor/acme/bar/ab1', '');
FS::dumpFile('vendor/acme/bar/ab0');
FS::dumpFile('vendor/acme/bar/ab1');

FS::dumpFile('vendor/acme/oof/ao0', '');
FS::dumpFile('vendor/acme/oof/ao1', '');
FS::dumpFile('vendor/acme/oof/ao0');
FS::dumpFile('vendor/acme/oof/ao1');

$this->reloadConfig();

Expand Down Expand Up @@ -2061,11 +2061,11 @@ static function (): void {
// The main script is blacklisted but ensures this does not affect the other files collected, like here
// the files found in a directory which has the same name as the main script
static function (): void {
FS::dumpFile('acme', '');
FS::dumpFile('src/file00', '');
FS::dumpFile('src/file10', '');
FS::dumpFile('src/acme/file00', '');
FS::dumpFile('src/acme/file10', '');
FS::dumpFile('acme');
FS::dumpFile('src/file00');
FS::dumpFile('src/file10');
FS::dumpFile('src/acme/file00');
FS::dumpFile('src/acme/file10');
},
[
'main' => 'acme',
Expand Down Expand Up @@ -2239,12 +2239,12 @@ static function (): void {
// The main script is blacklisted but ensures this does not affect the other files collected, like here
// the files found in a directory which has the same name as the main script
static function (): void {
FS::dumpFile('index.php', '');
FS::dumpFile('acme', '');
FS::dumpFile('src/file00', '');
FS::dumpFile('src/file10', '');
FS::dumpFile('src/acme/file00', '');
FS::dumpFile('src/acme/file10', '');
FS::dumpFile('index.php');
FS::dumpFile('acme');
FS::dumpFile('src/file00');
FS::dumpFile('src/file10');
FS::dumpFile('src/acme/file00');
FS::dumpFile('src/acme/file10');
},
[
'output' => 'acme',
Expand Down Expand Up @@ -2316,8 +2316,8 @@ static function (): void {
FS::touch('main-script');
FS::touch('file0');
FS::touch('file-bin0');
FS::dumpFile('directory-bin0/file00', '');
FS::dumpFile('directory-bin1/file10', '');
FS::dumpFile('directory-bin0/file00');
FS::dumpFile('directory-bin1/file10');
},
[
'main' => 'main-script',
Expand All @@ -2338,7 +2338,7 @@ static function (): void {

yield [
static function (): void {
FS::dumpFile('directory0/file00', '');
FS::dumpFile('directory0/file00');
},
[
'directories' => ['directory0'],
Expand All @@ -2348,7 +2348,7 @@ static function (): void {

yield [
static function (): void {
FS::dumpFile('directory0/file00', '');
FS::dumpFile('directory0/file00');
},
[
'directories' => ['directory0'],
Expand All @@ -2359,7 +2359,7 @@ static function (): void {

yield [
static function (): void {
FS::dumpFile('directory1/file10', '');
FS::dumpFile('directory1/file10');
},
[
'finder' => [
Expand All @@ -2373,7 +2373,7 @@ static function (): void {

yield [
static function (): void {
FS::dumpFile('directory1/file10', '');
FS::dumpFile('directory1/file10');
},
[
'finder' => [
Expand All @@ -2388,8 +2388,8 @@ static function (): void {

yield [
static function (): void {
FS::dumpFile('directory0/file00', '');
FS::dumpFile('directory1/file10', '');
FS::dumpFile('directory0/file00');
FS::dumpFile('directory1/file10');
},
[
'directories' => ['directory0'],
Expand All @@ -2404,8 +2404,8 @@ static function (): void {

yield [
static function (): void {
FS::dumpFile('directory0/file00', '');
FS::dumpFile('directory1/file10', '');
FS::dumpFile('directory0/file00');
FS::dumpFile('directory1/file10');
},
[
'directories' => ['directory0'],
Expand Down
6 changes: 3 additions & 3 deletions tests/Configuration/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public function test_it_attempts_to_get_and_decode_the_json_and_lock_files(

public function test_it_throws_an_error_when_a_composer_file_is_found_but_invalid(): void
{
FS::dumpFile('composer.json', '');
FS::dumpFile('composer.json');

try {
$this->reloadConfig();
Expand All @@ -366,7 +366,7 @@ public function test_it_throws_an_error_when_a_composer_file_is_found_but_invali

public function test_it_throws_an_error_when_a_composer_lock_is_found_but_invalid(): void
{
FS::dumpFile('composer.lock', '');
FS::dumpFile('composer.lock');

try {
$this->reloadConfig();
Expand Down Expand Up @@ -2391,7 +2391,7 @@ public function test_by_default_there_is_no_stub_and_the_stub_is_generated(): vo

public function test_a_custom_stub_can_be_provided(): void
{
FS::dumpFile('custom-stub.php', '');
FS::dumpFile('custom-stub.php');

$this->setConfig([
'stub' => 'custom-stub.php',
Expand Down
11 changes: 4 additions & 7 deletions tests/Configuration/ConfigurationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@
use Symfony\Component\Filesystem\Path;
use function json_encode;
use const JSON_PRETTY_PRINT;
use const PHP_OS;
use const PHP_OS_FAMILY;

abstract class ConfigurationTestCase extends FileSystemTestCase
{
protected const DEFAULT_FILE = 'index.php';

/** @var Configuration */
protected $config;

/** @var string */
protected $file;
protected Configuration $config;
protected string $file;

protected function setUp(): void
{
Expand Down Expand Up @@ -58,7 +55,7 @@ final protected function reloadConfig(): void

final protected function isWindows(): bool
{
return false === mb_stripos(PHP_OS, 'darwin') && false !== mb_stripos(PHP_OS, 'win');
return 'Windows' === PHP_OS_FAMILY;
}

final protected function getNoFileConfig(): Configuration
Expand Down
Loading

0 comments on commit 04765e8

Please sign in to comment.