Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php 8.4 #325

Merged
merged 17 commits into from
Dec 20, 2024
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.3"
- "8.4"
steps:
- name: "Checkout code"
uses: "actions/checkout@v4"
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ jobs:
fail-fast: false
matrix:
include:
- php-version: "8.3"
experimental: false
#composer-options: "--ignore-platform-reqs"
- php-version: "8.4"
experimental: true
composer-options: "--ignore-platform-reqs"
#composer-options: "--ignore-platform-reqs"
steps:
- name: "Checkout code"
uses: "actions/checkout@v4"
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
}
},
"require": {
"php": ">=8.3.0",
"php": ">=8.4.1",
"ext-json": "*",
"ext-mbstring": "*",
"monolog/monolog": "^3.8",
"symfony/var-dumper": "^7.1",
"symfony/var-dumper": "^7.2",
"doctrine/sql-formatter": "^1.5",
"psr/log": "^2.0|^3.0"
},
"require-dev": {
"phpunit/phpunit": "^11.4",
"phpunit/phpunit": "^11.5",
"mockery/mockery": "^1.6.12",
"phpstan/phpstan": "^2.0.0"
"phpstan/phpstan": "^2.0.3"
},
"prefer-stable": true,
"minimum-stability": "dev",
Expand Down
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ parameters:
message: "#^PHPDoc tag @return with type mako\\\\utility\\\\Collection<TKey of \\(int\\|string\\), TValue> is not subtype of native type static\\(mako\\\\utility\\\\Collection<TKey of \\(int\\|string\\), TValue>\\)\\.$#"
count: 5
path: src/mako/utility/Collection.php
-
message: "#^Call to an undefined static method DateTime::createFromTimestamp\\(\\)\\.$#"
count: 1
path: src/mako/chrono/traits/TimeTrait.php
-
message: "#^Call to an undefined static method DateTimeImmutable::createFromTimestamp\\(\\)\\.$#"
count: 1
path: src/mako/chrono/traits/TimeTrait.php
-
message: "#^Call to an undefined static method PDO::connect\\(\\)\\.$#"
count: 1
path: src/mako/database/connections/Connection.php
-
message: "#^Call to protected method orderMiddlewareByPriority\\(\\) of class mako\\\\http\\\\routing\\\\Dispatcher\\.$#"
count: 1
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ parameters:
reportUnmatchedIgnoredErrors: false
universalObjectCratesClasses:
- mako\database\query\Result
ignoreErrors:
- identifier: trait.unused
6 changes: 3 additions & 3 deletions src/mako/application/cli/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function loadLogo(): string
*/
protected function registerAndhandleGlobalArguments(): void
{
$arguments = $this->reactor->getInput()->getArgumentParser();
$arguments = $this->reactor->input->argumentParser;

// Register global arguments

Expand All @@ -153,7 +153,7 @@ protected function registerAndhandleGlobalArguments(): void
$arguments = $arguments->parse(true);
}
catch (ArgumentException|UnexpectedValueException $e) {
$this->reactor->getOutput()->errorLn("<red>{$e->getMessage()}</red>");
$this->reactor->output->errorLn("<red>{$e->getMessage()}</red>");

exit(CommandInterface::STATUS_ERROR);
}
Expand Down Expand Up @@ -193,7 +193,7 @@ protected function startReactor(): void
if ($signalHandler->canHandleSignals()) {
$signalHandler->addHandler([SIGINT, SIGTERM], static function ($signal, $isLast) use ($output): void {
$output->restoreCursor();
$output->getEnvironment()->restoreStty();
$output->environment->restoreStty();

// If we're the last handler then we exit with status code 130 (SIGINT) or 143 (SIGTERM)

Expand Down
2 changes: 1 addition & 1 deletion src/mako/application/cli/commands/app/ListRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function execute(Routes $routes, Dispatcher $dispatcher, Router $router,
}

if ($detailed) {
$labelAndValues['Pattern'] = $this->output->getFormatter()->escape($route->getRegex());
$labelAndValues['Pattern'] = $this->output->formatter->escape($route->getRegex());
}

$maxLabelLength = max(array_map(mb_strwidth(...), array_keys($labelAndValues)));
Expand Down
7 changes: 1 addition & 6 deletions src/mako/chrono/traits/TimeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use DateTimeZone;

use function getdate;
use function is_int;
use function min;
use function mktime;

Expand Down Expand Up @@ -58,11 +57,7 @@ public static function createFromDate(int $year, ?int $month = null, ?int $day =
*/
public static function createFromTimestamp(float|int $timestamp, null|DateTimeZone|string $timeZone = null): static
{
if (PHP_VERSION_ID >= 80400) {
return new static(parent::createFromTimestamp($timestamp)->format('Y-m-d\TH:i:s.u'), $timeZone);
}

return static::createFromFormat(is_int($timestamp) ? 'U' : 'U.u', (string) $timestamp, $timeZone);
return new static(parent::createFromTimestamp($timestamp)->format('Y-m-d\TH:i:s.u'), $timeZone);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/mako/cli/input/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Input
*/
public function __construct(
protected ReaderInterface $reader,
protected ArgvParser $arguments
public protected(set) ArgvParser $argumentParser
) {
}

Expand All @@ -45,22 +45,22 @@ public function readCharacter(): string
*/
public function getArgumentParser(): ArgvParser
{
return $this->arguments;
return $this->argumentParser;
}

/**
* Returns all the arguments passed to the script.
*/
public function getArguments(): array
{
return $this->arguments->parse();
return $this->argumentParser->parse();
}

/**
* Returns the argument associated with the given name.
*/
public function getArgument(int|string $name, mixed $default = null): mixed
{
return $this->arguments->getArgumentValue($name, $default);
return $this->argumentParser->getArgumentValue($name, $default);
}
}
2 changes: 1 addition & 1 deletion src/mako/cli/input/helpers/Secret.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Secret extends Question
*/
public function ask(string $question, mixed $default = null, bool $fallback = false): mixed
{
$hasStty = $this->output->getEnvironment()->hasStty();
$hasStty = $this->output->environment->hasStty();

if (PHP_OS_FAMILY === 'Windows' || $hasStty) {
$this->displayPrompt($question);
Expand Down
10 changes: 5 additions & 5 deletions src/mako/cli/output/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class Output
* Constructor.
*/
public function __construct(
protected WriterInterface $standard = new Standard,
protected WriterInterface $error = new Error,
protected Environment $environment = new Environment,
protected ?FormatterInterface $formatter = null,
protected ?Cursor $cursor = null
public protected(set) WriterInterface $standard = new Standard,
public protected(set) WriterInterface $error = new Error,
public protected(set) Environment $environment = new Environment,
public protected(set) ?FormatterInterface $formatter = null,
public protected(set) ?Cursor $cursor = null
) {
}

Expand Down
9 changes: 1 addition & 8 deletions src/mako/cli/output/components/Alert.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,14 @@ class Alert
*/
protected int $width;

/**
* Formatter.
*/
protected ?FormatterInterface $formatter = null;

/**
* Constructor.
*/
public function __construct(
protected Output $output,
?int $width = null
) {
$this->width = $width ?? $output->getEnvironment()->getWidth();

$this->formatter = $output->getFormatter();
$this->width = $width ?? $output->environment->getWidth();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/mako/cli/output/components/Hyperlink.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
*/
protected function hasHyperlinkSupport(): bool
{
return $this->output->getEnvironment()->hasAnsiSupport() && !in_array(env('TERM_PROGRAM'), static::UNSUPPORTED_TERMINALS);
return $this->output->environment->hasAnsiSupport() && !in_array(env('TERM_PROGRAM'), static::UNSUPPORTED_TERMINALS);
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/mako/cli/output/components/OrderedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,12 @@ class OrderedList
*/
protected string $padding = ' ';

/**
* Formatter instance.
*/
protected ?FormatterInterface $formatter = null;

/**
* Constructor.
*/
public function __construct(
protected Output $output
) {
$this->formatter = $output->getFormatter();
}

/**
Expand All @@ -56,7 +50,7 @@ protected function calculateWidth(array $items, string $marker): array

$number = strlen((string) $count);

$marker = strlen(sprintf($this->formatter === null ? $marker : $this->formatter->stripTags($marker), '')) + $number;
$marker = strlen(sprintf($this->output->formatter === null ? $marker : $this->output->formatter->stripTags($marker), '')) + $number;

return ['number' => $number, 'marker' => $marker];
}
Expand Down
6 changes: 0 additions & 6 deletions src/mako/cli/output/components/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@ class Table
{
use HelperTrait;

/**
* Formatter.
*/
protected ?FormatterInterface $formatter = null;

/**
* Constructor.
*/
public function __construct(
protected Output $output,
protected Border $borderStyle = new Border
) {
$this->formatter = $output->getFormatter();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/mako/cli/output/components/traits/HelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Helper trait.
*
* @property \mako\cli\output\formatter\FormatterInterface|null $formatter
* @property \mako\cli\output\Output $output
*/
trait HelperTrait
{
Expand All @@ -28,7 +28,7 @@ protected function getVisibleStringWidth(string $string): int
{
// Strip tags if a formatter is set

$string = $this->formatter !== null ? $this->formatter->stripTags($string) : $string;
$string = $this->output->formatter !== null ? $this->output->formatter->stripTags($string) : $string;

// Strip ANSI codes and OSC sequences

Expand Down
7 changes: 1 addition & 6 deletions src/mako/database/connections/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,7 @@ protected function connect(): PDO
// Connect to the database

try {
if (PHP_VERSION_ID >= 80400) {
$pdo = PDO::connect($this->dsn, $this->username, $this->password, $this->getConnectionOptions());
}
else {
$pdo = new PDO($this->dsn, $this->username, $this->password, $this->getConnectionOptions());
}
$pdo = PDO::connect($this->dsn, $this->username, $this->password, $this->getConnectionOptions());
}
catch (PDOException $e) {
throw new DatabaseException(sprintf('Failed to connect to the [ %s ] database. %s', $this->name, $e->getMessage()), previous: $e);
Expand Down
1 change: 1 addition & 0 deletions src/mako/database/midgard/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ protected function insertRecord(Query $query): void
$this->columns[$this->primaryKey] = match ($this->primaryKeyType) {
static::PRIMARY_KEY_TYPE_UUID => UUID::v4Sequential(),
static::PRIMARY_KEY_TYPE_CUSTOM => $this->generatePrimaryKey(),
default => throw new DatabaseException('Invalid primary key type.'),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/mako/error/handlers/cli/DevelopmentHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
*/
protected function escape(string $string): string
{
if (($formatter = $this->output->getFormatter()) === null) {
if (($formatter = $this->output->formatter) === null) {
return $string;
}

Expand Down
Loading
Loading