Skip to content

Commit

Permalink
PHP 8.2, Framework 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kloor committed Dec 18, 2023
1 parent 755b213 commit b3f180f
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 77 deletions.
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@
}
],
"require": {
"php": "^7.4",
"php": "^8.2",
"ext-PDO": "*",
"bgsu-lits/framework": "^1.9.0",
"bgsu-lits/framework": "^2.0",
"latitude/latitude": "^4.2",
"lulco/phoenix": "^1.10",
"pagerfanta/pagerfanta": "^3.5",
"phpoffice/phpspreadsheet": "^1.20",
"slim/http": "^1.2",
"slim/slim": "^4.9"
"lulco/phoenix": "^2.5",
"pagerfanta/pagerfanta": "^4.2",
"phpoffice/phpspreadsheet": "^1.29",
"slim/http": "^1.1",
"slim/slim": "^4.12",
"thecodingmachine/safe": "^2.5"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.3",
Expand Down Expand Up @@ -49,7 +50,7 @@
"scripts-dev": {
"phpcbf": "phpcbf ./ --standard=phpcs.xml",
"phpcs": "phpcs ./ --standard=phpcs.xml",
"phplint": "phplint ./ --exclude=vendor",
"phplint": "phplint ./ -c phplint.yml",
"phpstan": "phpstan analyse -c phpstan.neon",
"phpunit": "phpunit -c phpunit.xml",
"psalm": "psalm --config=psalm.xml",
Expand Down
2 changes: 1 addition & 1 deletion migration.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare(strict_types=1);
###NAMESPACE###use Phoenix\Exception\InvalidArgumentValueException;
use Phoenix\Migration\AbstractMigration;

class ###CLASSNAME### extends AbstractMigration
final class ###CLASSNAME### extends AbstractMigration
{
###INDENT###/** @throws InvalidArgumentValueException */
###INDENT###protected function up(): void
Expand Down
5 changes: 3 additions & 2 deletions phoenix.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types=1);

use Lits\Database;
use Lits\Framework;

$path = getcwd();

Expand All @@ -14,10 +15,10 @@
return [];
}

/** @var \Lits\Framework $framework */
$framework = require $path;
assert($framework instanceof Framework);

/** @var \Lits\Database $database */
$database = $framework->container()->get(Database::class);
assert($database instanceof Database);

return $database->migration();
1 change: 1 addition & 0 deletions phplint.yml
3 changes: 2 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile="cache/phpunit.result"
>
<coverage processUncoveredFiles="true">
<include>
Expand Down
25 changes: 13 additions & 12 deletions src/Lits/Action/DatabaseFileTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

trait DatabaseFileTrait
{
/** @return mixed[][] */
/** @return array<array<mixed>> */
abstract protected function file(): array;

/**
Expand All @@ -26,14 +26,14 @@ abstract protected function file(): array;
public function csv(
ServerRequest $request,
Response $response,
array $data
array $data,
): Response {
return $this->writeFile(
$request,
$response,
$data,
'csv',
'text/csv; charset=UTF-8'
'text/csv; charset=UTF-8',
);
}

Expand All @@ -44,20 +44,21 @@ public function csv(
public function xlsx(
ServerRequest $request,
Response $response,
array $data
array $data,
): Response {
return $this->writeFile(
$request,
$response,
$data,
'xlsx',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
'application/vnd.openxmlformats-' .
'officedocument.spreadsheetml.sheet',
);
}

public static function addFileRoutes(
RouteCollectorProxy $router,
string $path
string $path,
): void {
$path = \trim($path, '/');

Expand All @@ -76,7 +77,7 @@ private function writeFile(
Response $response,
array $data,
string $extension,
string $contentType
string $contentType,
): Response {
$this->setup($request, $response, $data);

Expand All @@ -85,7 +86,7 @@ private function writeFile(
if ($stream === false) {
throw new HttpInternalServerErrorException(
$this->request,
'Could not open memory stream'
'Could not open memory stream',
);
}

Expand All @@ -99,13 +100,13 @@ private function writeFile(
throw new HttpInternalServerErrorException(
$this->request,
'Could not create download file',
$exception
$exception,
);
}

$name = \strtolower(
\implode('_', \array_slice($this->hierarchy(), 1)) . '.' .
$extension
$extension,
);

try {
Expand All @@ -116,7 +117,7 @@ private function writeFile(
throw new HttpInternalServerErrorException(
$this->request,
'Could not download file',
$exception
$exception,
);
}
}
Expand All @@ -140,7 +141,7 @@ private function writeFileSpreadsheet(): Spreadsheet
$col,
$row,
$file_col,
DataType::TYPE_STRING
DataType::TYPE_STRING,
);

$col++;
Expand Down
19 changes: 8 additions & 11 deletions src/Lits/Adapter/PaginationAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,20 @@
use function Latitude\QueryBuilder\func;

/** @implements Adapter<array<array-key, mixed>> */
class PaginationAdapter implements Adapter
final class PaginationAdapter implements Adapter
{
private Database $database;
private SelectQuery $query;

public function __construct(Database $database, SelectQuery $query)
{
$this->database = $database;
$this->query = $query;
public function __construct(
private Database $database,
private SelectQuery $query,
) {
}

public function getNbResults(): int
{
$statement = $this->database->execute(
$this->database->query
->select(func('count', '*'))
->from(alias(express('(%s)', $this->query), 'query'))
->from(alias(express('(%s)', $this->query), 'query')),
);

$count = (int) $statement->fetchColumn();
Expand All @@ -47,10 +44,10 @@ public function getSlice(int $offset, int $length): iterable
$statement = $this->database->execute(
$this->query
->offset($offset)
->limit($length)
->limit($length),
);

/** @var array<array-key, array<array-key, mixed>>|false */
/** @var array<array-key, array<array-key, mixed>>|false $slice */
$slice = $statement->fetchAll(\PDO::FETCH_ASSOC);

if (\is_array($slice)) {
Expand Down
10 changes: 5 additions & 5 deletions src/Lits/Config/DatabaseConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ public function testSettings(): void
{
if (!\in_array($this->type, ['mysql', 'pgsql'], true)) {
throw new InvalidConfigException(
'The database type must be mysql or pgsql'
'The database type must be mysql or pgsql',
);
}

if ($this->host === '') {
throw new InvalidConfigException(
'The database host must be specified'
'The database host must be specified',
);
}

if ($this->username === '') {
throw new InvalidConfigException(
'The database username must be specified'
'The database username must be specified',
);
}

if ($this->password === '') {
throw new InvalidConfigException(
'The database password must be specified'
'The database password must be specified',
);
}

if ($this->name === '') {
throw new InvalidConfigException(
'The database name must be specified'
'The database name must be specified',
);
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/Lits/Data/DatabaseData.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@

abstract class DatabaseData extends Data
{
protected Database $database;

public function __construct(Settings $settings, Database $database)
{
public function __construct(
Settings $settings,
protected Database $database,
) {
parent::__construct($settings);

$this->database = $database;
}

/**
Expand All @@ -27,7 +25,7 @@ public function __construct(Settings $settings, Database $database)
*/
protected static function findRowDatetime(
array $row,
string $key
string $key,
): ?DateTimeImmutable {
if (isset($row[$key])) {
try {
Expand All @@ -36,7 +34,7 @@ protected static function findRowDatetime(
throw new InvalidDataException(
'The string could not be parsed into a datetime',
0,
$exception
$exception,
);
}
}
Expand Down
Loading

0 comments on commit b3f180f

Please sign in to comment.