Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 4e8ba12

Browse files
committed
csf (also fixed workflow)
1 parent 7191fa1 commit 4e8ba12

29 files changed

+104
-98
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
fail-fast: false
2121
matrix:
22-
php: [ '8.1', '8.2' ]
22+
php: [ '8.2' ]
2323

2424
steps:
2525
- uses: actions/checkout@v3

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
$client->on(Client::GENERIC_PACKET, static function (GenericPacket $packet, Client $client) {
3030
var_dump($packet->getType());
3131
});
32-
32+
3333
$client->on(Client::DISCONNECT, static function (Client $client) {
3434
$client->server->logger->info('Client disconnected [' . color(Color::GREEN, $client->getIp()) . ']');
3535
});

src/Exceptions/CavePHPException.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
use Exception;
66

7-
class CavePHPException extends Exception {
8-
9-
}
7+
class CavePHPException extends Exception
8+
{
9+
}

src/Pools/Pool.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55
use CavePHP\Exceptions\CavePHPException;
66
use Countable;
77

8-
abstract class Pool implements Countable {
8+
abstract class Pool implements Countable
9+
{
910
private array $items = [];
1011

1112
abstract public function isInstance(object $item): bool;
1213

13-
public function __construct(array $items = []) {
14+
public function __construct(array $items = [])
15+
{
1416
$this->fill($items);
1517
}
1618

1719
public function fill(array $items): void
1820
{
1921
foreach ($items as $item) {
2022
if (!is_object($item) || !$this->isInstance($item)) {
21-
throw new CavePHPException("This object is not supported by this collection");
23+
throw new CavePHPException('This object is not supported by this collection');
2224
}
2325
}
2426

@@ -77,4 +79,4 @@ public function count(): int
7779
{
7880
return count($this->items);
7981
}
80-
}
82+
}

src/Server/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ public function disconnect(): void
6767
{
6868
$this->connection->close();
6969
}
70-
}
70+
}

src/Server/Logger/Color.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@
44

55
final class Color
66
{
7-
public const RED = "#ff695e";
8-
public const RED_INVERTED = "#db2828";
9-
public const ORANGE = "#ff851b";
10-
public const ORANGE_INVERTED = "#f2711c";
11-
public const YELLOW = "#ffe21f";
12-
public const YELLOW_INVERTED = "#fbbd08";
13-
public const OLIVE = "#d9e778";
14-
public const OLIVE_INVERTED = "#b5cc18";
15-
public const GREEN = "#2ecc40";
16-
public const GREEN_INVERTED = "#21ba45";
17-
public const TEAL = "#6dffff";
18-
public const TEAL_INVERTED = "#00b5ad";
19-
public const BLUE = "#54c8ff";
20-
public const BLUE_INVERTED = "#2185d0";
21-
public const VIOLET = "#a291fb";
22-
public const VIOLET_INVERTED = "#6435c9";
23-
public const PURPLE = "#dc73ff";
24-
public const PURPLE_INVERTED = "#a333c8";
25-
public const PINK = "#ff8edf";
26-
public const PINK_INVERTED = "#e03997";
27-
public const BROWN = "#d67c1c";
28-
public const BROWN_INVERTED = "#a5673f";
29-
public const GREY = "#dcddde";
30-
public const GREY_INVERTED = "#767676";
31-
public const BLACK = "#545454";
32-
public const BLACK_INVERTED = "#1b1c1d";
33-
}
7+
public const RED = '#ff695e';
8+
public const RED_INVERTED = '#db2828';
9+
public const ORANGE = '#ff851b';
10+
public const ORANGE_INVERTED = '#f2711c';
11+
public const YELLOW = '#ffe21f';
12+
public const YELLOW_INVERTED = '#fbbd08';
13+
public const OLIVE = '#d9e778';
14+
public const OLIVE_INVERTED = '#b5cc18';
15+
public const GREEN = '#2ecc40';
16+
public const GREEN_INVERTED = '#21ba45';
17+
public const TEAL = '#6dffff';
18+
public const TEAL_INVERTED = '#00b5ad';
19+
public const BLUE = '#54c8ff';
20+
public const BLUE_INVERTED = '#2185d0';
21+
public const VIOLET = '#a291fb';
22+
public const VIOLET_INVERTED = '#6435c9';
23+
public const PURPLE = '#dc73ff';
24+
public const PURPLE_INVERTED = '#a333c8';
25+
public const PINK = '#ff8edf';
26+
public const PINK_INVERTED = '#e03997';
27+
public const BROWN = '#d67c1c';
28+
public const BROWN_INVERTED = '#a5673f';
29+
public const GREY = '#dcddde';
30+
public const GREY_INVERTED = '#767676';
31+
public const BLACK = '#545454';
32+
public const BLACK_INVERTED = '#1b1c1d';
33+
}

src/Server/Logger/Level.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace CavePHP\Server\Logger;
44

5-
use CavePHP\Server\Logger\Color;
6-
use Stringable;
7-
85
enum Level: string
96
{
107
case ERROR = Color::RED_INVERTED;

src/Server/Logger/Logger.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public function log(Level $level, Stringable|string $message, array $context = [
1515
return;
1616
}
1717

18-
$makeContextString = static function (array|int $item): string
19-
{
18+
$makeContextString = static function (array|int $item): string {
2019
if (is_array($item)) {
2120
return json_encode($item);
2221
}
@@ -30,7 +29,7 @@ public function log(Level $level, Stringable|string $message, array $context = [
3029
$message .= ' |';
3130

3231
foreach ($context as $item) {
33-
$message .= " " . $makeContextString($item);
32+
$message .= ' ' . $makeContextString($item);
3433
}
3534
}
3635

@@ -39,9 +38,9 @@ public function log(Level $level, Stringable|string $message, array $context = [
3938

4039
protected function formatMessage(Level $level, string $message): string
4140
{
42-
$log = "";
41+
$log = '';
4342

44-
$log .= '[' .color($level->value, $level->name) . '] ';
43+
$log .= '[' . color($level->value, $level->name) . '] ';
4544
$log .= '[' . color(Color::BROWN, date('Y-m-d H:i:s')) . ']';
4645
$log .= " {$message}";
4746

@@ -52,16 +51,19 @@ public function error(string $message, array $context = []): void
5251
{
5352
$this->log(Level::ERROR, $message, $context);
5453
}
54+
5555
public function warning(string $message, array $context = []): void
5656
{
5757
$this->log(Level::WARNING, $message, $context);
5858
}
59+
5960
public function info(string $message, array $context = []): void
6061
{
6162
$this->log(Level::INFO, $message, $context);
6263
}
64+
6365
public function debug(string $message, array $context = []): void
6466
{
6567
$this->log(Level::DEBUG, $message, $context);
6668
}
67-
}
69+
}

src/Server/Packets/ByteStream.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ class ByteStream
1515
public const LONG = 'l';
1616
public const FLOAT = 'f';
1717
public const DOUBLE = 'd';
18-
private Bytes $data;
1918

19+
private Bytes $data;
2020
private int $position = 0;
2121

22-
public function __construct() {
23-
$this->data = new Bytes;
22+
public function __construct()
23+
{
24+
$this->data = new Bytes();
2425
}
2526

2627
/**
@@ -34,6 +35,7 @@ public function read(int $length = 1): string
3435

3536
$data = $this->data->getRange($this->position, $length);
3637
$this->move($length);
38+
3739
return $data;
3840
}
3941

@@ -94,7 +96,7 @@ public function readBoolean(): bool
9496

9597
public function readVarInt(): int
9698
{
97-
return (new McVarInt)->read($this);
99+
return (new McVarInt())->read($this);
98100
}
99101

100102
/**
@@ -131,8 +133,9 @@ public function getData(): Bytes
131133

132134
public static function createWithData(string $data): self
133135
{
134-
$stream = new self;
136+
$stream = new self();
135137
$stream->write($data);
138+
136139
return $stream;
137140
}
138-
}
141+
}

src/Server/Packets/Bytes.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Bytes implements Countable, Stringable
1111
{
1212
private stdClass $data;
1313

14-
public function __construct() {
14+
public function __construct()
15+
{
1516
$this->data = new stdClass();
1617
}
1718

@@ -50,4 +51,4 @@ public function __toString()
5051
{
5152
return implode('', get_object_vars($this->data));
5253
}
53-
}
54+
}

src/Server/Packets/GenericPacket.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ class GenericPacket
1212

1313
public function __construct(
1414
public readonly Client $client
15-
)
16-
{
17-
$this->stream = new ByteStream;
15+
) {
16+
$this->stream = new ByteStream();
1817
}
1918

2019
public function getLength(): int

src/Server/Packets/McVars/McChar.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
namespace CavePHP\Server\Packets\McVars;
44

55
use Attribute;
6-
use CavePHP\Server\Packets\ByteStream;
76

87
#[Attribute(Attribute::TARGET_PROPERTY)]
98
class McChar
109
{
11-
12-
}
10+
}

src/Server/Packets/McVars/McDouble.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
#[Attribute(Attribute::TARGET_PROPERTY)]
88
class McDouble
99
{
10-
11-
}
10+
}

src/Server/Packets/McVars/McFloat.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
#[Attribute(Attribute::TARGET_PROPERTY)]
88
class McFloat
99
{
10-
11-
}
10+
}

src/Server/Packets/McVars/McInt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ public function read(ByteStream $stream): int
1212
{
1313
return $stream->readInt();
1414
}
15-
}
15+
}

src/Server/Packets/McVars/McIntEnum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ public function read(ByteStream $stream): BackedEnum
2525

2626
return $this->enum::tryFrom($int);
2727
}
28-
}
28+
}

src/Server/Packets/McVars/McLong.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
#[Attribute(Attribute::TARGET_PROPERTY)]
88
class McLong
99
{
10-
11-
}
10+
}

src/Server/Packets/McVars/McShort.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
#[Attribute(Attribute::TARGET_PROPERTY)]
88
class McShort
99
{
10-
11-
}
10+
}

src/Server/Packets/McVars/McString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ public function read(ByteStream $stream): string
2424
{
2525
return $stream->read($this->length);
2626
}
27-
}
27+
}

src/Server/Packets/McVars/McUnsignedChar.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
#[Attribute(Attribute::TARGET_PROPERTY)]
88
class McUnsignedChar
99
{
10-
11-
}
10+
}

src/Server/Packets/McVars/McUnsignedShort.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ public function read(ByteStream $stream): mixed
1212
{
1313
return $stream->readUnsignedShort();
1414
}
15-
}
15+
}

src/Server/Packets/McVars/McVar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
interface McVar
1010
{
1111
public function read(ByteStream $stream): mixed;
12-
}
12+
}

src/Server/Packets/McVars/McVarInt.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class McVarInt implements McVar
1212
public const SEGMENT_BITS = 0x7F;
1313
public const CONTINUE_BIT = 0x80;
1414

15-
public function read(ByteStream $stream): int {
15+
public function read(ByteStream $stream): int
16+
{
1617
$value = 0;
1718
$shift = 0;
1819

@@ -22,10 +23,10 @@ public function read(ByteStream $stream): int {
2223
$shift += 7;
2324

2425
if ($shift >= 32) {
25-
throw new CavePHPException("VarInt is too big");
26+
throw new CavePHPException('VarInt is too big');
2627
}
2728
} while ($byte & self::CONTINUE_BIT);
2829

2930
return $value;
3031
}
31-
}
32+
}

0 commit comments

Comments
 (0)