From 3e39f85352cbd837082109973aa6825894e47388 Mon Sep 17 00:00:00 2001 From: Thiery Laverdure Date: Sat, 11 Oct 2025 14:36:34 -0400 Subject: [PATCH 1/9] Create pint.yml --- .github/workflows/pint.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/pint.yml diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml new file mode 100644 index 0000000..7ff288d --- /dev/null +++ b/.github/workflows/pint.yml @@ -0,0 +1,34 @@ +name: pint + +on: + pull_request: + branches: [main] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Run Pint + run: ./vendor/bin/pint --ci + + - name: Check for changes + id: verify-changed-files + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "changed=true" >> $GITHUB_OUTPUT + echo "Changes detected after Pint" + git status --porcelain + else + echo "changed=false" >> $GITHUB_OUTPUT + echo "No changes detected after Pint" + fi + + - name: Commit and Push changes + if: steps.verify-changed-files.outputs.changed == 'true' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add api/generated_openapi.json + git commit -m "Apply PHP Pint fixes" + git push From 1123b9754f13fbe3adfd83d65074e9c82fcff0d0 Mon Sep 17 00:00:00 2001 From: Thiery Laverdure Date: Sat, 11 Oct 2025 14:37:30 -0400 Subject: [PATCH 2/9] Update pint.yml --- .github/workflows/pint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 7ff288d..4cd8f66 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -29,6 +29,6 @@ jobs: run: | git config --local user.email "action@github.com" git config --local user.name "GitHub Action" - git add api/generated_openapi.json + git add -u git commit -m "Apply PHP Pint fixes" git push From b34380f363859c1b4bd561696bbb6b2dc83a881b Mon Sep 17 00:00:00 2001 From: Thiery Laverdure Date: Sat, 11 Oct 2025 14:38:56 -0400 Subject: [PATCH 3/9] Add PHP setup and dependency installation to Pint workflow --- .github/workflows/pint.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 4cd8f66..8294a6a 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -9,6 +9,17 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: "8.4" + tools: composer:v2 + coverage: xdebug + + - name: Install Dependencies + run: composer install --no-interaction --prefer-dist --optimize-autoloader + - name: Run Pint run: ./vendor/bin/pint --ci From b38590f93e0a8c3f5eb239738f018472dbe19ee1 Mon Sep 17 00:00:00 2001 From: Thiery Laverdure Date: Sat, 11 Oct 2025 14:42:17 -0400 Subject: [PATCH 4/9] Create pint.json --- pint.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pint.json diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..ce62d18 --- /dev/null +++ b/pint.json @@ -0,0 +1,3 @@ +{ + "exclude": ["src/Generated"] +} From 37e620bfee0888849e2f972e6857816b8a4218d4 Mon Sep 17 00:00:00 2001 From: Thiery Laverdure Date: Sat, 11 Oct 2025 14:42:46 -0400 Subject: [PATCH 5/9] Update Pint execution to use Composer script --- .github/workflows/pint.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 8294a6a..a293601 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -21,7 +21,7 @@ jobs: run: composer install --no-interaction --prefer-dist --optimize-autoloader - name: Run Pint - run: ./vendor/bin/pint --ci + run: composer run pint - name: Check for changes id: verify-changed-files diff --git a/composer.json b/composer.json index efe8661..2287a6b 100644 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ }, "scripts": { "generate_openapi": "openapi-generator-cli generate -c openapi_config.yaml", - "format": "vendor/bin/pint --no-interaction", + "pint": "vendor/bin/pint --no-interaction", "test": "vendor/bin/pest", "test-coverage": "vendor/bin/pest --coverage-html coverage" } From 12ee3cc713ede0ca7813ea50cbaa671f99222103 Mon Sep 17 00:00:00 2001 From: Thiery Laverdure Date: Sat, 11 Oct 2025 14:44:09 -0400 Subject: [PATCH 6/9] Update pint.yml --- .github/workflows/pint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index a293601..137a6ed 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -42,4 +42,4 @@ jobs: git config --local user.name "GitHub Action" git add -u git commit -m "Apply PHP Pint fixes" - git push + git push origin HEAD:${{ github.head_ref }} From 8282ead1ac1cd81f33e11cfd30b920e3d2a780ef Mon Sep 17 00:00:00 2001 From: Thiery Laverdure Date: Sat, 11 Oct 2025 14:47:23 -0400 Subject: [PATCH 7/9] Update Pint workflow for improved permissions and git push --- .github/workflows/pint.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index 137a6ed..e671c11 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -7,8 +7,13 @@ on: jobs: lint: runs-on: ubuntu-latest + permissions: + contents: write steps: - uses: actions/checkout@v5 + with: + ref: ${{ github.head_ref }} + fetch-depth: 0 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -42,4 +47,4 @@ jobs: git config --local user.name "GitHub Action" git add -u git commit -m "Apply PHP Pint fixes" - git push origin HEAD:${{ github.head_ref }} + git push From be43ddf0937aecd437b6d60d779ad1e905f8abc3 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sat, 11 Oct 2025 18:47:55 +0000 Subject: [PATCH 8/9] Apply PHP Pint fixes --- src/Connection.php | 16 ++++++++-------- src/Exceptions/QueryException.php | 2 +- src/HasRequestHeaders.php | 2 +- src/HttpStreamingTransport.php | 4 ++-- src/HttpTransport.php | 4 ++-- src/LitebaseClient.php | 3 +-- src/LitebasePDO.php | 4 ++-- src/LitebaseStatement.php | 19 +++++++++---------- src/Query.php | 6 +++--- src/QueryRequestEncoder.php | 12 ++++++------ src/QueryResult.php | 4 ++-- src/RequestSigner.php | 10 +++++----- src/SignsRequests.php | 6 +++--- tests/LitebaseStatementTest.php | 1 - 14 files changed, 45 insertions(+), 48 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index ef76921..979bf2a 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -45,7 +45,7 @@ class Connection /** * Create a new connection instance. * - * @param array $requestHeaders + * @param array $requestHeaders */ public function __construct(public string $url, public array $requestHeaders = []) { @@ -183,7 +183,7 @@ protected function createThreads(): void if ($byte === "\r") { // Expecting "\n" after "\r" - $nextByte = $this->socket ? fread($this->socket, 1) : false; + $nextByte = $this->socket ? fread($this->socket, 1) : false; if ($nextByte === "\n") { break; @@ -214,7 +214,7 @@ protected function createThreads(): void while ($bytesRead < $chunkSize) { $remainingBytes = $chunkSize - $bytesRead; - $readLength = max(1, (int)$remainingBytes); + $readLength = max(1, (int) $remainingBytes); $data = $this->socket && $remainingBytes > 0 ? fread($this->socket, $readLength) : @@ -357,7 +357,7 @@ public function open(): void stream_set_timeout($this->socket, 5); $error = fwrite($this->socket, "POST {$this->path} HTTP/1.1\r\n"); - $error = fwrite($this->socket, implode("\r\n", $this->headers) . "\r\n"); + $error = fwrite($this->socket, implode("\r\n", $this->headers)."\r\n"); $error = fwrite($this->socket, "\r\n"); if ($error === false) { @@ -367,7 +367,7 @@ public function open(): void $this->open = true; $this->messages = [ - pack('C', QueryStreamMessageType::OPEN_CONNECTION->value . pack('V', 0)), + pack('C', QueryStreamMessageType::OPEN_CONNECTION->value.pack('V', 0)), ...$this->messages, ]; @@ -381,7 +381,7 @@ public function send(Query $query): QueryResult { $queryRequest = $this->queryRequestEncoder->encode($query); - $frame = pack('C', QueryStreamMessageType::FRAME->value) . pack('V', strlen($queryRequest)) . $queryRequest; + $frame = pack('C', QueryStreamMessageType::FRAME->value).pack('V', strlen($queryRequest)).$queryRequest; $this->messages[] = $frame; @@ -410,7 +410,7 @@ public function send(Query $query): QueryResult continue; } catch (Exception $reconnectException) { - throw new Exception('[Litebase Client Error]: Failed to reconnect after connection loss: ' . $reconnectException->getMessage()); + throw new Exception('[Litebase Client Error]: Failed to reconnect after connection loss: '.$reconnectException->getMessage()); } } } @@ -565,7 +565,7 @@ protected function writeMessage(string $message): void $chunkSize = dechex(strlen($message)); $n = $this->socket ? - fwrite($this->socket, $chunkSize . "\r\n" . $message . "\r\n") : + fwrite($this->socket, $chunkSize."\r\n".$message."\r\n") : false; if ($n === false) { diff --git a/src/Exceptions/QueryException.php b/src/Exceptions/QueryException.php index 26fa2f6..b8cfc8a 100644 --- a/src/Exceptions/QueryException.php +++ b/src/Exceptions/QueryException.php @@ -24,7 +24,7 @@ class QueryException extends Exception /** * Create a new QueryException instance. * - * @param array $parameters + * @param array $parameters */ public function __construct(string $message, string $statement, array $parameters, ?Throwable $previous = null) { diff --git a/src/HasRequestHeaders.php b/src/HasRequestHeaders.php index 709ae19..fc6edfd 100644 --- a/src/HasRequestHeaders.php +++ b/src/HasRequestHeaders.php @@ -5,7 +5,7 @@ trait HasRequestHeaders { /** - * @param array $headers + * @param array $headers * @return array */ protected function requestHeaders(string $host, ?string $port, int $contentLength, array $headers = []): array diff --git a/src/HttpStreamingTransport.php b/src/HttpStreamingTransport.php index de36811..8390316 100644 --- a/src/HttpStreamingTransport.php +++ b/src/HttpStreamingTransport.php @@ -42,11 +42,11 @@ public function send(Query $query): ?QueryResult : sprintf('http://%s:%d/%s', $this->config->getHost(), $this->config->getPort(), $path); if (! empty($this->config->getUsername()) || ! (empty($this->config->getPassword()))) { - $headers['Authorization'] = 'Basic ' . base64_encode($this->config->getUsername() . ':' . $this->config->getPassword()); + $headers['Authorization'] = 'Basic '.base64_encode($this->config->getUsername().':'.$this->config->getPassword()); } if (! empty($this->config->getAccessToken())) { - $headers['Authorization'] = 'Bearer ' . $this->config->getAccessToken(); + $headers['Authorization'] = 'Bearer '.$this->config->getAccessToken(); } if (! empty($this->config->getAccessKeyId())) { diff --git a/src/HttpTransport.php b/src/HttpTransport.php index 38434bc..90a7021 100644 --- a/src/HttpTransport.php +++ b/src/HttpTransport.php @@ -50,13 +50,13 @@ public function send(Query $query): ?QueryResult /** @var array> $rows */ $rows = array_values(array_map( - fn($row) => is_array($row) ? array_values($row) : (array) $row, + fn ($row) => is_array($row) ? array_values($row) : (array) $row, $firstResult->getRows() ?? [] )); return new QueryResult( changes: $firstResult->getChanges() ?? 0, - columns: array_values(array_map(fn($col) => [ + columns: array_values(array_map(fn ($col) => [ 'type' => ColumnType::from($col->getType() ?? 1), 'name' => $col->getName() ?? '', ], $firstResult->getColumns() ?? [])), diff --git a/src/LitebaseClient.php b/src/LitebaseClient.php index 3134341..bfcf8d2 100644 --- a/src/LitebaseClient.php +++ b/src/LitebaseClient.php @@ -4,7 +4,6 @@ use Exception; use GuzzleHttp\Client; -use Litebase\Generated\Model\Any; use Litebase\Generated\Model\StatementParameter; use Throwable; @@ -217,7 +216,7 @@ public function withTransport(string $transportType): LitebaseClient $this->transport = new HttpStreamingTransport($this->configuration); break; default: - throw new Exception('Invalid transport type: ' . $transportType); + throw new Exception('Invalid transport type: '.$transportType); } return $this; diff --git a/src/LitebasePDO.php b/src/LitebasePDO.php index 2e403b7..5b0d5cf 100644 --- a/src/LitebasePDO.php +++ b/src/LitebasePDO.php @@ -16,7 +16,7 @@ class LitebasePDO extends Sqlite /** * Create a new instance of the PDO connection. * - * @param array $config + * @param array $config */ public function __construct(array $config) { @@ -149,7 +149,7 @@ public function lastInsertId($name = null): string|false /** * Create a new prepared statement. * - * @param array|null $options Driver options. + * @param array|null $options Driver options. */ public function prepare(string $statement, $options = null): PDOStatement { diff --git a/src/LitebaseStatement.php b/src/LitebaseStatement.php index 72aff47..9b92dab 100644 --- a/src/LitebaseStatement.php +++ b/src/LitebaseStatement.php @@ -2,7 +2,6 @@ namespace Litebase; -use Iterator; use IteratorAggregate; use Litebase\Exceptions\QueryException; use PDO; @@ -72,14 +71,14 @@ public function bindValue(int|string $parameter, mixed $value, int $data_type = case PDO::PARAM_NULL: $type = 'NULL'; break; - // TODO: Test BLOB type + // TODO: Test BLOB type case PDO::PARAM_LOB: $type = 'BLOB'; break; - // TODO: Add a case for float type - // case PDO::PARAM_FLOAT: - // $type = "REAL"; - // break; + // TODO: Add a case for float type + // case PDO::PARAM_FLOAT: + // $type = "REAL"; + // break; default: $type = 'TEXT'; // Default to TEXT if no match break; @@ -105,7 +104,7 @@ public function bindValue(int|string $parameter, mixed $value, int $data_type = */ public function closeCursor(): bool { - if (!empty($this->result->rows)) { + if (! empty($this->result->rows)) { $this->result->rows = []; } @@ -151,7 +150,7 @@ public function errorInfo(): array /** * {@inheritDoc} * - * @param array|null $params + * @param array|null $params */ public function execute(?array $params = null): bool { @@ -209,8 +208,9 @@ public function execute(?array $params = null): bool if (isset($this->result->rows)) { $this->rows = array_map(function ($row) { $columns = $this->columns ?? []; + return array_combine( - array_map(fn($col) => $col['name'], $columns), + array_map(fn ($col) => $col['name'], $columns), $row ); }, $this->result->rows); @@ -285,7 +285,6 @@ public function rowCount(): int return $this->rowCount; } - /** * {@inheritDoc} */ diff --git a/src/Query.php b/src/Query.php index 7904e43..012f106 100644 --- a/src/Query.php +++ b/src/Query.php @@ -7,7 +7,7 @@ class Query { /** - * @param \Litebase\Generated\Model\StatementParameter[] $parameters + * @param \Litebase\Generated\Model\StatementParameter[] $parameters */ public function __construct( public string $id, @@ -21,10 +21,10 @@ public function __construct( */ public function toRequest(): CreateQueryRequest { - $request = new CreateQueryRequest(); + $request = new CreateQueryRequest; $request->setQueries([ - (new \Litebase\Generated\Model\QueryInput()) + (new \Litebase\Generated\Model\QueryInput) ->setId($this->id) ->setTransactionId($this->transactionId ?? '') ->setStatement($this->statement) diff --git a/src/QueryRequestEncoder.php b/src/QueryRequestEncoder.php index 7776011..3969073 100644 --- a/src/QueryRequestEncoder.php +++ b/src/QueryRequestEncoder.php @@ -9,7 +9,7 @@ public static function encode(Query $query): string $binaryData = ''; $id = $query->id; $idLength = pack('V', strlen($id)); - $binaryData .= $idLength . $id; + $binaryData .= $idLength.$id; $transactionIdLength = pack('V', strlen($query->transactionId ?? '')); $binaryData .= $transactionIdLength; @@ -20,7 +20,7 @@ public static function encode(Query $query): string $statement = $query->statement; $statementLength = pack('V', strlen($statement)); - $binaryData .= $statementLength . $statement; + $binaryData .= $statementLength.$statement; $parametersBinary = ''; @@ -72,14 +72,14 @@ public static function encode(Query $query): string $parameterType = pack('C', $parameterType); // Parameter value with length prefix (4 bytes little-endian + value) - $parameterValueWithLength = pack('V', $parameterValueLength) . $parameterValue; + $parameterValueWithLength = pack('V', $parameterValueLength).$parameterValue; - $parametersBinary .= $parameterType . $parameterValueWithLength; + $parametersBinary .= $parameterType.$parameterValueWithLength; } $parametersBinaryLength = pack('V', strlen($parametersBinary)); - $binaryData .= $parametersBinaryLength . $parametersBinary; - $queryBinary = pack('V', strlen($binaryData)) . $binaryData; + $binaryData .= $parametersBinaryLength.$parametersBinary; + $queryBinary = pack('V', strlen($binaryData)).$binaryData; return $queryBinary; } diff --git a/src/QueryResult.php b/src/QueryResult.php index daa0e9d..c3c9409 100644 --- a/src/QueryResult.php +++ b/src/QueryResult.php @@ -7,8 +7,8 @@ class QueryResult /** * Create a new QueryResult instance. * - * @param array $columns - * @param array> $rows + * @param array $columns + * @param array> $rows */ public function __construct( public int $changes = 0, diff --git a/src/RequestSigner.php b/src/RequestSigner.php index 1f945da..faa6d18 100644 --- a/src/RequestSigner.php +++ b/src/RequestSigner.php @@ -7,9 +7,9 @@ class RequestSigner /** * Sign a request and return the authorization token. * - * @param array $headers - * @param array $data - * @param array $queryParams + * @param array $headers + * @param array $data + * @param array $queryParams */ public static function handle( string $accessKeyID, @@ -24,7 +24,7 @@ public static function handle( ksort($headers); $headers = array_filter( $headers, - fn($value, $key) => in_array($key, ['content-type', 'host', 'x-litebase-date']), + fn ($value, $key) => in_array($key, ['content-type', 'host', 'x-litebase-date']), ARRAY_FILTER_USE_BOTH ); @@ -35,7 +35,7 @@ public static function handle( $requestString = implode('', [ $method, - '/' . ltrim($path, '/'), + '/'.ltrim($path, '/'), json_encode($headers, JSON_UNESCAPED_SLASHES), json_encode((empty($queryParams)) ? (object) [] : $queryParams, JSON_UNESCAPED_SLASHES), $bodyHash, diff --git a/src/SignsRequests.php b/src/SignsRequests.php index 580f742..c5aebbe 100644 --- a/src/SignsRequests.php +++ b/src/SignsRequests.php @@ -7,9 +7,9 @@ trait SignsRequests /** * Get an authorization token for a request. * - * @param array $headers - * @param array $data - * @param array $queryParams + * @param array $headers + * @param array $data + * @param array $queryParams */ public function getToken( string $accessKeyID, diff --git a/tests/LitebaseStatementTest.php b/tests/LitebaseStatementTest.php index 87256df..67b6e5a 100644 --- a/tests/LitebaseStatementTest.php +++ b/tests/LitebaseStatementTest.php @@ -3,7 +3,6 @@ uses(\Litebase\Tests\TestCase::class); use Litebase\ColumnType; -use Mockery\MockInterface; use Litebase\LitebaseClient; use Litebase\LitebaseStatement; use Litebase\QueryResult; From 3447f1cdfefd16dd4d597214ba9c8f8b58aa7fd4 Mon Sep 17 00:00:00 2001 From: Thiery Laverdure Date: Sat, 11 Oct 2025 14:50:44 -0400 Subject: [PATCH 9/9] Update Pint workflow triggers and steps --- .github/workflows/pint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml index e671c11..ea9420b 100644 --- a/.github/workflows/pint.yml +++ b/.github/workflows/pint.yml @@ -1,8 +1,9 @@ name: pint on: - pull_request: + push: branches: [main] + workflow_dispatch: jobs: lint: @@ -12,7 +13,6 @@ jobs: steps: - uses: actions/checkout@v5 with: - ref: ${{ github.head_ref }} fetch-depth: 0 - name: Setup PHP