Skip to content

Commit 49aac0a

Browse files
committed
Merge branch 'cleanup'
2 parents 954c310 + 12d0fe3 commit 49aac0a

33 files changed

+368
-416
lines changed

phpstan-baseline-7.4.neon

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline-8.3.neon

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/delete-covers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
foreach ($files as $file) {
3232
$i++;
3333
$file = (string) $file;
34-
$relative = File::relativeToParent($file, dirname(__DIR__));
34+
$relative = File::getRelativePath($file, dirname(__DIR__));
3535
Console::logProgress(sprintf('Checking %d of %d:', $i, $count), $relative);
3636

3737
$input = @file($file);

scripts/generate.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@
134134
if (!$constant->isPublic()) {
135135
continue;
136136
}
137-
Env::unset($constant->getValue());
137+
/** @var string */
138+
$value = $constant->getValue();
139+
Env::unset($value);
138140
}
139141

140142
$args = [
@@ -143,6 +145,12 @@
143145
...array_slice($_SERVER['argv'], 1),
144146
];
145147

148+
$online = array_search('--online', $args);
149+
if ($online !== false) {
150+
unset($args[$online]);
151+
$online = true;
152+
}
153+
146154
/**
147155
* @param AbstractGenerateCommand|string $commandOrFile
148156
*/
@@ -158,7 +166,7 @@ function generated($commandOrFile): void
158166
throw new LogicException('No file generated');
159167
}
160168

161-
$generated[] = '/' . File::relativeToParent($file, Package::path());
169+
$generated[] = '/' . File::getRelativePath($file, Package::path());
162170
}
163171

164172
$status = 0;
@@ -170,8 +178,10 @@ function generated($commandOrFile): void
170178
if (is_array($class)) {
171179
$facadeArgs = $class;
172180
$class = array_shift($facadeArgs);
173-
if (is_array(reset($facadeArgs))) {
174-
$aliases = array_shift($facadeArgs);
181+
$first = reset($facadeArgs);
182+
if (is_array($first)) {
183+
$aliases = $first;
184+
array_shift($facadeArgs);
175185
}
176186
}
177187
$status |= $generateFacade(...[...$args, ...$facadeArgs, $class, ...$aliases, $facade]);
@@ -215,10 +225,18 @@ function generated($commandOrFile): void
215225

216226
foreach ($data as $file => $uri) {
217227
$file = "{$dir}/tests/data/{$file}";
218-
if (!in_array('--check', $args)) {
228+
$exists = file_exists($file);
229+
if ($exists && !$online) {
230+
Console::log('Skipping', $file);
231+
} elseif (!$exists && in_array('--check', $args)) {
232+
Console::info('Would create', $file);
233+
Console::count(Level::ERROR);
234+
$status |= 1;
235+
continue;
236+
} elseif (!in_array('--check', $args)) {
219237
Console::log('Downloading', $uri);
220238
$content = File::getContents($uri);
221-
if (!file_exists($file) || File::getContents($file) !== $content) {
239+
if (!$exists || File::getContents($file) !== $content) {
222240
Console::info('Replacing', $file);
223241
File::createDir(dirname($file));
224242
File::writeContents($file, $content);
@@ -239,7 +257,7 @@ function generated($commandOrFile): void
239257
$file = "$dir/.gitattributes";
240258
$attributes = Regex::grep(
241259
'/(^#| linguist-generated$)/',
242-
Arr::trim(file($file)),
260+
Arr::trim(File::getLines($file)),
243261
\PREG_GREP_INVERT
244262
);
245263
// @phpstan-ignore-next-line

src/Toolkit/Cli/CliCommand.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ final public function getSynopsis(?CliHelpStyleInterface $style = null): string
514514

515515
$name = $b . $this->getNameWithProgram() . $b;
516516
$full = $this->getOptionsSynopsis($style, $collapsed);
517-
$synopsis = Arr::implode(' ', [$name, $full]);
517+
$synopsis = Arr::implode(' ', [$name, $full], '');
518518

519519
if ($width !== null) {
520520
$wrapped = $formatter->format(
@@ -538,7 +538,7 @@ final public function getSynopsis(?CliHelpStyleInterface $style = null): string
538538
return $wrapped;
539539
}
540540

541-
$synopsis = Arr::implode(' ', [$name, $collapsed]);
541+
$synopsis = Arr::implode(' ', [$name, $collapsed], '');
542542
}
543543

544544
$synopsis = $formatter->format(
@@ -664,14 +664,14 @@ private function getOptionsSynopsis(CliHelpStyleInterface $style, ?string &$coll
664664
$optionalCount === 1 ? $esc . '[' . $style->maybeEscapeTags('<option>') . ']' : '',
665665
$required ? implode(' ', $required) : '',
666666
$positional ? $esc . '[' . $b . '--' . $b . '] ' . implode(' ', $positional) : '',
667-
]);
667+
], '');
668668

669669
return Arr::implode(' ', [
670670
$shortFlag ? $esc . '[' . $b . '-' . implode('', $shortFlag) . $b . ']' : '',
671671
$optional ? implode(' ', $optional) : '',
672672
$required ? implode(' ', $required) : '',
673673
$positional ? $esc . '[' . $b . '--' . $b . '] ' . implode(' ', $positional) : '',
674-
]);
674+
], '');
675675
}
676676

677677
/**

src/Toolkit/Console/ConsoleWriter.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Salient\Utility\Get;
3333
use Salient\Utility\Inflect;
3434
use Salient\Utility\Str;
35+
use Salient\Utility\Sys;
3536
use Throwable;
3637

3738
/**
@@ -438,7 +439,7 @@ public function summary(
438439
) {
439440
return $this->write(
440441
Level::INFO,
441-
Arr::implode(' ', [$msg1, $successText, $usage ?? null]),
442+
Arr::implode(' ', [$msg1, $successText, $usage ?? null], ''),
442443
null,
443444
$withStandardMessageType
444445
? MessageType::SUMMARY
@@ -457,7 +458,7 @@ public function summary(
457458
$withoutErrorCount || $withStandardMessageType
458459
? Level::INFO
459460
: ($errors ? Level::ERROR : Level::WARNING),
460-
Arr::implode(' ', [$msg1, $msg2 ?? null, $usage ?? null]),
461+
Arr::implode(' ', [$msg1, $msg2 ?? null, $usage ?? null], ''),
461462
null,
462463
$withoutErrorCount || $withStandardMessageType
463464
? MessageType::SUMMARY
@@ -923,7 +924,13 @@ private function _write(
923924
bool $msg2HasTags = false
924925
) {
925926
if (!$this->State->Targets) {
926-
$logTarget = StreamTarget::fromPath(File::getStablePath('.log'));
927+
$logTarget = StreamTarget::fromPath(sprintf(
928+
'%s/%s-%s-%s.log',
929+
Sys::getTempDir(),
930+
Sys::getProgramBasename(),
931+
Get::hash(File::realpath(Sys::getProgramName())),
932+
Sys::getUserId(),
933+
));
927934
$this->registerTarget($logTarget, LevelGroup::ALL);
928935
$this->maybeRegisterStdioTargets();
929936
}

src/Toolkit/Container/Application.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private function getPath(
138138
}
139139

140140
return $this->checkPath(
141-
Arr::implode('/', [$path, $app, $windowsChild]),
141+
Arr::implode('/', [$path, $app, $windowsChild], ''),
142142
$name,
143143
$create,
144144
$save,
@@ -166,7 +166,7 @@ private function getPath(
166166
}
167167

168168
return $this->checkPath(
169-
Arr::implode('/', [$path, $app, $child]),
169+
Arr::implode('/', [$path, $app, $child], ''),
170170
$name,
171171
$create,
172172
$save,

src/Toolkit/Core/Concern/MultipleErrorExceptionTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public function __construct(
4040
default:
4141
$message = Arr::implode(
4242
$separator ?? ":\n",
43-
[$message, $append ?? rtrim(Format::list($errors))]
43+
[$message, $append ?? rtrim(Format::list($errors))],
44+
''
4445
);
4546
break;
4647
}

src/Toolkit/Core/ConfigurationManager.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function loadDirectory(string $directory): self
7070
*/
7171
public function has(string $key): bool
7272
{
73-
return Arr::has($key, $this->Items);
73+
return Arr::has($this->Items, $key);
7474
}
7575

7676
/**
@@ -84,9 +84,9 @@ public function has(string $key): bool
8484
public function get(string $key, $default = null)
8585
{
8686
if (func_num_args() > 1) {
87-
return Arr::get($key, $this->Items, $default);
87+
return Arr::get($this->Items, $key, $default);
8888
}
89-
return Arr::get($key, $this->Items);
89+
return Arr::get($this->Items, $key);
9090
}
9191

9292
/**
@@ -102,11 +102,12 @@ public function getMany(array $keys): array
102102
{
103103
foreach ($keys as $key => $default) {
104104
if (is_int($key)) {
105+
/** @var string */
105106
$key = $default;
106-
$values[$key] = Arr::get($key, $this->Items);
107+
$values[$key] = Arr::get($this->Items, $key);
107108
continue;
108109
}
109-
$values[$key] = Arr::get($key, $this->Items, $default);
110+
$values[$key] = Arr::get($this->Items, $key, $default);
110111
}
111112
return $values ?? [];
112113
}
@@ -128,7 +129,7 @@ public function all(): array
128129
*/
129130
public function offsetExists($offset): bool
130131
{
131-
return Arr::get($offset, $this->Items, null) !== null;
132+
return Arr::get($this->Items, $offset, null) !== null;
132133
}
133134

134135
/**
@@ -140,6 +141,6 @@ public function offsetExists($offset): bool
140141
#[ReturnTypeWillChange]
141142
public function offsetGet($offset)
142143
{
143-
return Arr::get($offset, $this->Items);
144+
return Arr::get($this->Items, $offset);
144145
}
145146
}

src/Toolkit/Core/Introspector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ static function (
811811
return Arr::implode(' ', [
812812
$first($instance),
813813
$last($instance),
814-
]);
814+
], '');
815815
};
816816
}
817817
}

0 commit comments

Comments
 (0)