Skip to content

Commit 179ef50

Browse files
Fix PHP 8.4 and 8.5 deprecations (#229)
1 parent 1994d5e commit 179ef50

6 files changed

Lines changed: 26 additions & 15 deletions

File tree

src/Config/Repository.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ public function set($key, $value = null)
174174
* Load the configuration group for the key.
175175
*
176176
* @param string $group
177-
* @param string $namespace
177+
* @param string|null $namespace
178178
* @param string $collection
179179
* @return void
180180
*/
181-
protected function load($group, $namespace, $collection)
181+
protected function load($group, ?string $namespace, $collection)
182182
{
183183
$env = $this->environment;
184184

@@ -191,10 +191,10 @@ protected function load($group, $namespace, $collection)
191191

192192
$items = $this->loader->load($env, $group, $namespace);
193193

194-
// If we've already loaded this collection, we will just bail out since we do
195-
// not want to load it again. Once items are loaded a first time they will
196-
// stay kept in memory within this class and not loaded from disk again.
197-
if (isset($this->afterLoad[$namespace])) {
194+
// After load callbacks are only ever registered against a real namespace, so
195+
// the global namespace (null) can never have one. Guarding here also avoids
196+
// using null as an array offset, which is deprecated as of PHP 8.5.
197+
if ($namespace !== null && isset($this->afterLoad[$namespace])) {
198198
$items = $this->callAfterLoad($namespace, $group, $items);
199199
}
200200

@@ -209,7 +209,7 @@ protected function load($group, $namespace, $collection)
209209
* @param array $items
210210
* @return array
211211
*/
212-
protected function callAfterLoad($namespace, $group, $items)
212+
protected function callAfterLoad(string $namespace, $group, $items)
213213
{
214214
$callback = $this->afterLoad[$namespace];
215215

@@ -312,7 +312,7 @@ public function package($namespace, $hint)
312312
* @param \Closure $callback
313313
* @return void
314314
*/
315-
public function afterLoading($namespace, Closure $callback)
315+
public function afterLoading(string $namespace, Closure $callback)
316316
{
317317
$this->afterLoad[$namespace] = $callback;
318318
}

src/Console/Traits/ProcessesQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ trait ProcessesQuery
1616
* query by the provided chunkSize, running the callback on each record and
1717
* limiting number of records processed to the provided limit
1818
*/
19-
public function processQuery(Builder $query, callable $callback, int $chunkSize = 100, int $limit = null): void
19+
public function processQuery(Builder $query, callable $callback, int $chunkSize = 100, ?int $limit = null): void
2020
{
2121
$totalRecords = $query->count();
2222

src/Halcyon/Processors/Processor.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public function processSelectOne(Builder $query, $result)
1919

2020
$fileName = array_get($result, 'fileName');
2121

22+
// A record without a filename is not a valid template, so treat it as no result.
23+
if ($fileName === null) {
24+
return null;
25+
}
26+
2227
return [$fileName => $this->parseTemplateContent($query, $result, $fileName)];
2328
}
2429

@@ -39,6 +44,12 @@ public function processSelect(Builder $query, $results)
3944

4045
foreach ($results as $result) {
4146
$fileName = array_get($result, 'fileName');
47+
48+
// Skip records without a filename so they cannot collide on an empty key.
49+
if ($fileName === null) {
50+
continue;
51+
}
52+
4253
$items[$fileName] = $this->parseTemplateContent($query, $result, $fileName);
4354
}
4455

src/Html/FormBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,12 +478,12 @@ public function selectYear(string $name, int $begin = 1900, ?int $end = null, st
478478
/**
479479
* Create a select month field.
480480
*/
481-
public function selectMonth(string $name, string|array|null $selected = null, array $options = [], $format = '%B'): string
481+
public function selectMonth(string $name, string|array|null $selected = null, array $options = [], $format = 'F'): string
482482
{
483483
$months = [];
484484

485485
foreach (range(1, 12) as $month) {
486-
$months[$month] = strftime($format, mktime(0, 0, 0, $month, 1));
486+
$months[$month] = date($format, mktime(0, 0, 0, $month, 1));
487487
}
488488

489489
return $this->select($name, $months, $selected, $options);

src/Support/Facades/Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
* @method static string file(string $name, array $options = [])
2020
* @method static string textarea(string $name, string $value = null, array $options = [])
2121
* @method static string select(string $name, array $list = [], string $value = null, array $options = [])
22-
* @method static string selectRange(string $name, string $begin, string $end, string $selected = null, array $options = [])
22+
* @method static string selectRange(string $name, string|int|float $begin, string|int|float $end, string|array|null $selected = null, array $options = [])
2323
* @method static string selectYear()
24-
* @method static string selectMonth(string $name, string $selected = null, array $options = [], string $format = '%B')
24+
* @method static string selectMonth(string $name, string|array|null $selected = null, array $options = [], string $format = 'F')
2525
* @method static string getSelectOption(string|array $display, string $value, string $selected)
2626
* @method static string checkbox(string $name, $value = 1, bool $checked = null, array $options = [])
2727
* @method static string radio(string $name, $value = null, bool $checked = null, array $options = [])

tests/Scheduling/ScheduleListCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testDisplaySchedule()
5454
->expectsOutput(' * * * * * Winter\Storm\Tests\Scheduling\FooJob Next Due: 1 minute from now')
5555
->expectsOutput(' 0 9,17 * * * php artisan inspire ......... Next Due: 9 hours from now')
5656
->expectsOutput(' 0 10 * * * php artisan inspire ........ Next Due: 10 hours from now')
57-
->expectsOutput(' * * * * * Closure at: Winter\Storm\Tests\Scheduling\FooCall Next Due: 1 minute from now')
57+
->expectsOutput(' * * * * * Winter\Storm\Tests\Scheduling\FooCall Next Due: 1 minute from now')
5858
->expectsOutput(' * * * * * Closure at: Winter\Storm\Tests\Scheduling\FooCall::fooFunction Next Due: 1 minute from now')
5959
->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now');
6060
}
@@ -78,7 +78,7 @@ public function testDisplayScheduleWithSort()
7878
->assertSuccessful()
7979
->expectsOutput(' * * * * * php artisan foobar a='.ProcessUtils::escapeArgument('b').' ... Next Due: 1 minute from now')
8080
->expectsOutput(' * * * * * Winter\Storm\Tests\Scheduling\FooJob Next Due: 1 minute from now')
81-
->expectsOutput(' * * * * * Closure at: Winter\Storm\Tests\Scheduling\FooCall Next Due: 1 minute from now')
81+
->expectsOutput(' * * * * * Winter\Storm\Tests\Scheduling\FooCall Next Due: 1 minute from now')
8282
->expectsOutput(' * * * * * Closure at: Winter\Storm\Tests\Scheduling\FooCall::fooFunction Next Due: 1 minute from now')
8383
->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now')
8484
->expectsOutput(' 0 9,17 * * * php artisan inspire ......... Next Due: 9 hours from now')

0 commit comments

Comments
 (0)