diff --git a/.github/workflows/pint.yml b/.github/workflows/pint.yml new file mode 100644 index 0000000..ea9420b --- /dev/null +++ b/.github/workflows/pint.yml @@ -0,0 +1,50 @@ +name: pint + +on: + push: + branches: [main] + workflow_dispatch: + +jobs: + lint: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - 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: composer run pint + + - 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 -u + git commit -m "Apply PHP Pint fixes" + git push 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" } 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"] +} 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;