Skip to content

Commit 279d134

Browse files
authored
Merge pull request #7 from kduma-OSS/develop
Cleanup commands and use PHP 8.1 features
2 parents b0fcd9a + 5d59ad1 commit 279d134

7 files changed

Lines changed: 23 additions & 42 deletions

File tree

app/Api/JobModel.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
class JobModel
66
{
77
public function __construct(
8-
public string $id,
9-
public string $name,
10-
public string $printer,
11-
public array $options,
12-
public string $type,
13-
public string $file_name,
14-
public mixed $content,
8+
public readonly string $id,
9+
public readonly string $name,
10+
public readonly string $printer,
11+
public readonly array $options,
12+
public readonly string $type,
13+
public readonly string $file_name,
14+
public readonly mixed $content,
1515
) {
1616
}
1717
}

app/Commands/.gitkeep

Whitespace-only changes.

app/Commands/ParsePpdOptionsFromPpdFileCommand.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace App\Commands;
44

5+
use Brick\VarExporter\ExportException;
56
use Brick\VarExporter\VarExporter;
6-
use Illuminate\Console\Scheduling\Schedule;
77
use LaravelZero\Framework\Commands\Command;
88

99
class ParsePpdOptionsFromPpdFileCommand extends Command
@@ -25,9 +25,11 @@ class ParsePpdOptionsFromPpdFileCommand extends Command
2525
/**
2626
* Execute the console command.
2727
*
28-
* @return mixed
28+
* @return int
29+
*
30+
* @throws ExportException
2931
*/
30-
public function handle()
32+
public function handle(): int
3133
{
3234
$contents = array_map('trim', file($this->argument('file')));
3335
$options_array = [];
@@ -100,16 +102,7 @@ public function handle()
100102
} else {
101103
echo json_encode($options_array, JSON_PRETTY_PRINT);
102104
}
103-
}
104105

105-
/**
106-
* Define the command's schedule.
107-
*
108-
* @param Schedule $schedule
109-
* @return void
110-
*/
111-
public function schedule(Schedule $schedule): void
112-
{
113-
// $schedule->command(static::class)->everyMinute();
106+
return self::SUCCESS;
114107
}
115108
}

app/Commands/RunServiceCommand.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use App\Printers\Protocols\LpdProtocol;
1515
use App\Printers\Protocols\PrinterProtocolInterface;
1616
use App\Printers\Protocols\RawProtocol;
17-
use Illuminate\Console\Scheduling\Schedule;
1817
use LaravelZero\Framework\Commands\Command;
1918

2019
class RunServiceCommand extends Command
@@ -38,9 +37,9 @@ class RunServiceCommand extends Command
3837
*
3938
* @param WebPrintHostInterface $api
4039
* @param PollTimeCalculatorInterface $ptc
41-
* @return mixed
40+
* @return never
4241
*/
43-
public function handle(WebPrintHostInterface $api, PollTimeCalculatorInterface $ptc)
42+
public function handle(WebPrintHostInterface $api, PollTimeCalculatorInterface $ptc): never
4443
{
4544
while (true) {
4645
$this->line('Checking for new jobs...');
@@ -96,15 +95,4 @@ private function processJob(WebPrintHostInterface $api, string $id)
9695
$api->markJobAsFailed($id, 'TypeNotSupportedException');
9796
}
9897
}
99-
100-
/**
101-
* Define the command's schedule.
102-
*
103-
* @param Schedule $schedule
104-
* @return void
105-
*/
106-
public function schedule(Schedule $schedule): void
107-
{
108-
// $schedule->command(static::class)->everyMinute();
109-
}
11098
}

app/PollingCalculators/ConstantPollTime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ConstantPollTime implements PollTimeCalculatorInterface
99
*
1010
* @param int $delay Delay in miliseconds between each check of new print jobs
1111
*/
12-
public function __construct(protected int $delay)
12+
public function __construct(protected readonly int $delay)
1313
{
1414
}
1515

app/PollingCalculators/DynamicPollTime.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class DynamicPollTime implements PollTimeCalculatorInterface
1616
* @param float $warmup_factor WarmUp factor
1717
*/
1818
public function __construct(
19-
protected int $minimum = 1000,
20-
protected int $maximum = 60000,
21-
protected float $increase_factor = 1.02,
22-
protected float $decrease_factor = 0,
23-
protected float $warmup_factor = 0,
19+
protected readonly int $minimum = 1000,
20+
protected readonly int $maximum = 60000,
21+
protected readonly float $increase_factor = 1.02,
22+
protected readonly float $decrease_factor = 0,
23+
protected readonly float $warmup_factor = 0,
2424
) {
2525
$this->current_delay = $this->minimum;
2626
}

app/Providers/AppServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AppServiceProvider extends ServiceProvider
1515
*
1616
* @return void
1717
*/
18-
public function boot()
18+
public function boot(): void
1919
{
2020
//
2121
}
@@ -25,7 +25,7 @@ public function boot()
2525
*
2626
* @return void
2727
*/
28-
public function register()
28+
public function register(): void
2929
{
3030
$this->app->singleton(WebPrintHostInterface::class, function ($app) {
3131
return new HttpWebPrintHost();

0 commit comments

Comments
 (0)