Skip to content

Commit 961fe39

Browse files
committed
Format code with new pint config
1 parent 3ca3591 commit 961fe39

File tree

14 files changed

+95
-77
lines changed

14 files changed

+95
-77
lines changed

config/printing.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
return [
46
/*
57
|--------------------------------------------------------------------------

src/Api/PrintNode/Entity/Entity.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ public function __construct(array $data = [])
1717
$this->mapResponse($data);
1818
}
1919

20+
public function toArray(): array
21+
{
22+
$publicProperties = (new ReflectionObject($this))->getProperties(ReflectionProperty::IS_PUBLIC);
23+
24+
return collect($publicProperties)
25+
->mapWithKeys(function (ReflectionProperty $property) {
26+
return [$property->name => $this->{$property->name}];
27+
})->toArray();
28+
}
29+
30+
public function jsonSerialize(): mixed
31+
{
32+
return $this->toArray();
33+
}
34+
2035
protected function mapResponse(array $data): void
2136
{
2237
foreach ($data as $key => $value) {
@@ -44,19 +59,4 @@ protected function getTimestamp($timestamp): ?Carbon
4459

4560
return $date;
4661
}
47-
48-
public function toArray(): array
49-
{
50-
$publicProperties = (new ReflectionObject($this))->getProperties(ReflectionProperty::IS_PUBLIC);
51-
52-
return collect($publicProperties)
53-
->mapWithKeys(function (ReflectionProperty $property) {
54-
return [$property->name => $this->{$property->name}];
55-
})->toArray();
56-
}
57-
58-
public function jsonSerialize(): mixed
59-
{
60-
return $this->toArray();
61-
}
6262
}

src/Api/PrintNode/Entity/PrintJob.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
class PrintJob extends Entity
1212
{
13+
protected const VALID_CONTENT_TYPES = [
14+
ContentType::PDF_BASE64,
15+
ContentType::RAW_BASE64,
16+
ContentType::PDF_URI,
17+
ContentType::RAW_URI,
18+
];
19+
1320
/**
1421
* The print job's ID.
1522
*/
@@ -60,13 +67,6 @@ class PrintJob extends Entity
6067
*/
6168
public ?Printer $printer = null;
6269

63-
protected const VALID_CONTENT_TYPES = [
64-
ContentType::PDF_BASE64,
65-
ContentType::RAW_BASE64,
66-
ContentType::PDF_URI,
67-
ContentType::RAW_URI,
68-
];
69-
7070
public function setPrinter(array $data): self
7171
{
7272
$this->printer = new Printer($data);
@@ -180,15 +180,15 @@ public function setCreateTimestamp($date): self
180180
return $this;
181181
}
182182

183-
protected function isValidContentType(string $type): bool
184-
{
185-
return in_array($type, static::VALID_CONTENT_TYPES, true);
186-
}
187-
188183
public function toArray(): array
189184
{
190185
return array_merge(parent::toArray(), [
191186
'createTimestamp' => $this->created,
192187
]);
193188
}
189+
190+
protected function isValidContentType(string $type): bool
191+
{
192+
return in_array($type, static::VALID_CONTENT_TYPES, true);
193+
}
194194
}

src/Api/PrintNode/Requests/PrintNodeRequest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,9 @@ public function __construct(protected string $apiKey)
3131
])->acceptJson();
3232
}
3333

34-
protected function endpoint(string $service): string
35-
{
36-
return $this->applyPaginationToUrl(static::BASE_URL . $service);
37-
}
38-
39-
protected function getRequest(string $service): array
34+
public function postRequest(string $service, array $data = [])
4035
{
41-
$response = $this->http->get($this->endpoint($service));
36+
$response = $this->http->post($this->endpoint($service), $data);
4237

4338
if (! $response->successful()) {
4439
$this->handleFailedResponse($response);
@@ -47,9 +42,14 @@ protected function getRequest(string $service): array
4742
return $response->json();
4843
}
4944

50-
public function postRequest(string $service, array $data = [])
45+
protected function endpoint(string $service): string
5146
{
52-
$response = $this->http->post($this->endpoint($service), $data);
47+
return $this->applyPaginationToUrl(static::BASE_URL . $service);
48+
}
49+
50+
protected function getRequest(string $service): array
51+
{
52+
$response = $this->http->get($this->endpoint($service));
5353

5454
if (! $response->successful()) {
5555
$this->handleFailedResponse($response);

src/Contracts/Driver.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Rawilk\Printing\Contracts;
46

57
use Illuminate\Support\Collection;

src/Contracts/PrintJob.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Rawilk\Printing\Contracts;
46

57
use Carbon\Carbon;

src/Contracts/PrintTask.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Rawilk\Printing\Contracts;
46

57
interface PrintTask

src/Contracts/Printer.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Rawilk\Printing\Contracts;
46

57
use Illuminate\Support\Collection;

src/Receipts/ReceiptPrinter.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,27 @@ public function __construct()
5656
static::$lineCharacterLength = config('printing.receipts.line_character_length', 45);
5757
}
5858

59+
public function __destruct()
60+
{
61+
$this->close();
62+
}
63+
64+
public function __toString(): string
65+
{
66+
return $this->connector->getData();
67+
}
68+
69+
public function __call($name, $arguments)
70+
{
71+
if (method_exists($this->printer, $name)) {
72+
$this->printer->{$name}(...$arguments);
73+
74+
return $this;
75+
}
76+
77+
throw new InvalidArgumentException("Method [{$name}] not found on receipt printer object.");
78+
}
79+
5980
public function centerAlign(): self
6081
{
6182
$this->printer->setJustification(Printer::JUSTIFY_CENTER);
@@ -131,25 +152,4 @@ public function doubleLine(): self
131152
{
132153
return $this->text(str_repeat('=', static::$lineCharacterLength));
133154
}
134-
135-
public function __toString(): string
136-
{
137-
return $this->connector->getData();
138-
}
139-
140-
public function __call($name, $arguments)
141-
{
142-
if (method_exists($this->printer, $name)) {
143-
$this->printer->{$name}(...$arguments);
144-
145-
return $this;
146-
}
147-
148-
throw new InvalidArgumentException("Method [{$name}] not found on receipt printer object.");
149-
}
150-
151-
public function __destruct()
152-
{
153-
$this->close();
154-
}
155155
}

tests/Concerns/FakesPrintNodeRequests.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Rawilk\Printing\Tests\Concerns;
46

57
use Illuminate\Support\Facades\Http;

tests/Feature/Drivers/CustomDriver/Driver/CustomDriver.php

+20-20
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,6 @@ public function printers(?int $limit = null, ?int $offset = null, string|int|nul
4040
->values();
4141
}
4242

43-
protected function customPrinters(): array
44-
{
45-
return [
46-
[
47-
'id' => 'printer_one',
48-
'name' => 'Printer One',
49-
'status' => 'online',
50-
'capabilities' => [],
51-
'description' => 'Printer one description',
52-
],
53-
[
54-
'id' => 'printer_two',
55-
'name' => 'Printer Two',
56-
'status' => 'offline',
57-
'capabilities' => [],
58-
'description' => 'Printer two description',
59-
],
60-
];
61-
}
62-
6343
public function printJobs(?int $limit = null, ?int $offset = null, ?string $dir = null): Collection
6444
{
6545
return collect();
@@ -79,4 +59,24 @@ public function printerPrintJob($printerId, $jobId): ?PrintJob
7959
{
8060
return null;
8161
}
62+
63+
protected function customPrinters(): array
64+
{
65+
return [
66+
[
67+
'id' => 'printer_one',
68+
'name' => 'Printer One',
69+
'status' => 'online',
70+
'capabilities' => [],
71+
'description' => 'Printer one description',
72+
],
73+
[
74+
'id' => 'printer_two',
75+
'name' => 'Printer Two',
76+
'status' => 'offline',
77+
'capabilities' => [],
78+
'description' => 'Printer two description',
79+
],
80+
];
81+
}
8282
}

tests/Feature/Drivers/CustomDriver/Driver/PrintTask.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Rawilk\Printing\Tests\Feature\Drivers\CustomDriver\Driver;
46

57
use Rawilk\Printing\Contracts\Printer;

tests/Pest.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Rawilk\Printing\Tests\Feature\Api\PrintNode\PrintNodeTestCase;
46
use Rawilk\Printing\Tests\TestCase;
57

tests/TestCase.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Rawilk\Printing\Tests;
46

57
use Dotenv\Dotenv;

0 commit comments

Comments
 (0)