Skip to content

Commit

Permalink
Merge pull request #83 from thefrosty/feature/php-81-enhancements
Browse files Browse the repository at this point in the history
PHP 81 Enhancements
  • Loading branch information
thefrosty authored Mar 22, 2024
2 parents 15703ee + dbde3d6 commit 81b093a
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 68 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
strategy:
matrix:
operating-system: [ ubuntu-latest ]
php-versions: [ '8.0', '8.1' ]
wp-versions: [ '6.3', 'latest' ]
php-versions: [ '8.1', '8.2', '8.3' ]
wp-versions: [ '6.4', 'latest' ]
coverage: [ true ]
services:
mysql:
Expand Down Expand Up @@ -72,6 +72,6 @@ jobs:
run: cs2pr ./phpcs-report.xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Register custom migration tasks that can be triggered from a dashboard in the ad
### Requirements

```
PHP >= 7.4
WordPress >= 5.4
PHP >= 8.1
WordPress >= 6.2
```

The required WordPress version will always be the most recent point release of
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
},
"optimize-autoloader": true,
"platform": {
"php": "8.0"
"php": "8.1"
},
"process-timeout": 600,
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^8.0",
"pimple/pimple": "^3.2",
"symfony/http-foundation": "^5.2 || ~6.0",
"thefrosty/wp-utilities": "^3.0"
"php": "^8.1",
"pimple/pimple": "^3.5",
"symfony/http-foundation": "~6.0 || ^7.0",
"thefrosty/wp-utilities": "^3.3"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
restart: always

phpfpm:
image: php:8.0-fpm-alpine
image: php:8.1-fpm-alpine
depends_on:
- db
deploy:
Expand Down
6 changes: 3 additions & 3 deletions phpcs-ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<!-- For CI, don't fail on warnings -->
<config name="ignore_warnings_on_exit" value="1"/>
<!-- Sets the minimum supported WP version -->
<config name="minimum_supported_wp_version" value="6.1"/>
<!-- Check for cross-version support for PHP 8.0 and higher. -->
<config name="testVersion" value="8.0-"/>
<config name="minimum_supported_wp_version" value="6.2"/>
<!-- Check for cross-version support for PHP 8.1 and higher. -->
<config name="testVersion" value="8.1-"/>

<rule ref="WordPress-Docs">
<exclude name="Generic.Commenting.DocComment.SpacingBeforeTags"/>
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</php>
<testsuites>
<testsuite name="unit">
<directory phpVersion="7.4" phpVersionOperator=">=" suffix="Test.php">./tests/unit</directory>
<directory phpVersion="8.1" phpVersionOperator=">=" suffix="Test.php">./tests/unit</directory>
</testsuite>
</testsuites>

Expand Down
33 changes: 28 additions & 5 deletions src/Api/AbstractTaskRunner.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace TheFrosty\WpUpgradeTaskRunner\Api;

use cli\progress\Bar;
use DateTimeInterface;
use TheFrosty\WpUpgradeTaskRunner\Models\UpgradeModel;
use TheFrosty\WpUpgradeTaskRunner\Option;
use WP_CLI\NoOp;
use function defined;
use function function_exists;
use function WP_CLI\Utils\make_progress_bar;
use const WP_CLI;

/**
* Class TaskRunner
*
* Class AbstractTaskRunner
* @package TheFrosty\WpUpgradeTaskRunner\Api
* phpcs:disable SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix
*/
Expand Down Expand Up @@ -82,6 +90,21 @@ public function clearScheduledEvent(string $class, UpgradeModel $model): void
}
}

/**
* Create a new CLI Progress Bar.
* @param string $message
* @param int $count
* @return Bar|NoOp|null
*/
protected function makeProgressBar(string $message, int $count): Bar|NoOp|null
{
$cli = defined('WP_CLI') && WP_CLI;
return !$cli || !function_exists('\WP_CLI\Utils\make_progress_bar') ? null : make_progress_bar(
$message,
$count
);
}

/**
* Get a date formatted string.
*
Expand All @@ -90,9 +113,9 @@ public function clearScheduledEvent(string $class, UpgradeModel $model): void
private function getDate(): string
{
try {
return (new \DateTime('now', new \DateTimeZone('UTC')))->format(\DateTime::RFC850);
return (new \DateTime('now', new \DateTimeZone('UTC')))->format(DateTimeInterface::RFC850);
} catch (\Throwable $exception) {
return \date_create('now', new \DateTimeZone('UTC'))->format(\DateTime::RFC850);
return \date_create('now', new \DateTimeZone('UTC'))->format(DateTimeInterface::RFC850);
}
}
}
56 changes: 29 additions & 27 deletions src/Models/UpgradeModel.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace TheFrosty\WpUpgradeTaskRunner\Models;

use Countable;
use DateTime;
use DateTimeInterface;
use TheFrosty\WpUpgradeTaskRunner\Api\TaskRunnerInterface;
use TheFrosty\WpUpgradeTaskRunner\Exceptions\Exception;
use TheFrosty\WpUtilities\Models\BaseModel;
use function sprintf;

/**
* Class UpgradeModel
Expand All @@ -30,54 +36,54 @@ class UpgradeModel extends BaseModel implements Countable, UpgradeModelInterface
* Model count.
* @var array $model
*/
private $model;
private array $model;

/**
* DateTime object of the creation date.
*
* @var \DateTime $date
* @var DateTime $date
*/
private $date;
private DateTime $date;

/**
* The title of the migration/upgrade.
*
* @var string $title
*/
private $title;
private string $title;

/**
* The user ID who initiated the task.
*
* @var int $user_id
*/
private $user_id;
private int $user_id;

/**
* The description of the migration/upgrade.
*
* @var string $description
*/
private $description;
private string $description;

/**
* The TaskRunnerInterface object.
*
* @var TaskRunnerInterface $task_runner
*/
private $task_runner;
private TaskRunnerInterface $task_runner;

/**
* UpgradeModel constructor.
*
* @param array $fields Incoming fields.
* @throws \TheFrosty\WpUpgradeTaskRunner\Exceptions\Exception When the $fields array is missing required fields.
* @throws Exception When the $fields array is missing required fields.
*/
public function __construct(array $fields)
{
if (!$this->hasRequiredFields($fields)) {
throw new \TheFrosty\WpUpgradeTaskRunner\Exceptions\Exception(
\sprintf('Required fields are missing: `%s`', \join(', ', $this->getRequiredFields()))
throw new Exception(
sprintf('Required fields are missing: `%s`', \join(', ', $this->getRequiredFields()))
);
}

Expand All @@ -95,7 +101,7 @@ public function count(): int
}

/**
* Wh description of the migration/upgrade.
* Set the date/time field.
*
* @return array
*/
Expand All @@ -104,17 +110,17 @@ public function getDateTimeFields(): array
return ['date'];
}

public function getDate(): \DateTime
public function getDateFormat(?string $format = DateTimeInterface::ATOM): string
{
return $this->date;
return $this->date->format($format ?? \get_option('date_format'));
}

public function getDateFormat(string $format = \DATE_ISO8601): string
public function getDate(): DateTime
{
return $this->date->format($format ?? \get_option('date_format'));
return $this->date;
}

public function setDate(\DateTime $date): void
public function setDate(DateTime $date): void
{
$this->date = $date;
}
Expand Down Expand Up @@ -192,17 +198,13 @@ private function getRequiredFields(): array
static $fields;

if (empty($fields)) {
try {
$constants = (new \ReflectionClass($this))->getConstants();
foreach ($constants as $constant => $value) {
if (!\in_array($value, self::REQUIRED_FIELDS, true)) {
continue;
}

$fields[] = $value;
$constants = (new \ReflectionClass($this))->getConstants();
foreach ($constants as $value) {
if (!\in_array($value, self::REQUIRED_FIELDS, true)) {
continue;
}
} catch (\ReflectionException $exception) {
$fields = [];

$fields[] = $value;
}
}

Expand Down
26 changes: 14 additions & 12 deletions src/Models/UpgradeModelInterface.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace TheFrosty\WpUpgradeTaskRunner\Models;

use DateTimeInterface;
use TheFrosty\WpUpgradeTaskRunner\Api\TaskRunnerInterface;

/**
* Interface UpgradeModelInterface
*
* @package TheFrosty\WpUpgradeTaskRunner
*/
interface UpgradeModelInterface
{

/**
* Get the DateTime object of the upgrade date.
* This is the date the upgrade was created (not run).
* Returns date formatted according to given format.
*
* @return \DateTime
* @link http://php.net/manual/en/datetime.format.php
* @param string|null $format Defaults to `DateTimeInterface::ATOM`.
* @return string
*/
public function getDate(): \DateTime;
public function getDateFormat(?string $format = DateTimeInterface::ATOM): string;

/**
* Returns date formatted according to given format.
* Get the DateTime object of the upgrade date.
* This is the date the upgrade was created (not run).
*
* @link http://php.net/manual/en/datetime.format.php
* @param string $format Defaults to `DATE_ISO8601`.
* @return string
* @return \DateTime
*/
public function getDateFormat(string $format = \DATE_ISO8601): string;
public function getDate(): \DateTime;

/**
* Sets the the upgrade was created (not run). When passing the value from the array, use a
* Sets the date tge upgrade was created (not run). When passing the value from the array, use a
* string value like `'YYYY-MM-DD'`.
*
* @param \DateTime $date Date in the format of a string value that the `AbstractBaseModel` will convert
Expand Down
10 changes: 6 additions & 4 deletions src/Tasks/TaskLoader.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace TheFrosty\WpUpgradeTaskRunner\Tasks;

Expand Down Expand Up @@ -26,19 +28,19 @@ class TaskLoader implements \IteratorAggregate, WpHooksInterface
* Upgrade screen ID.
* @var string $screen_id
*/
private $screen_id;
private string $screen_id = '';

/**
* UpdateModel fields.
* @var UpgradeModel[] $fields
*/
private $fields = [];
private array $fields = [];

/**
* Task Runners.
* @var TaskRunnerInterface[] $tasks
*/
private $tasks = [];
private array $tasks = [];

/**
* Create the actions.
Expand Down
10 changes: 5 additions & 5 deletions upgrade-task-runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
* Plugin Name: Upgrade Task Runner
* Plugin URI: https://github.com/thefrosty/wp-upgrade-task-runner
* Description: A WordPress plugin for developers to write custom migration tasks.
* Version: 2.7.0
* Version: 2.8.0
* Author: Austin Passy
* Author URI: https://github.com/thefrosty
* Requires at least: 6.0
* Tested up to: 6.2.0
* Requires PHP: 8.0
* Requires at least: 6.2
* Tested up to: 6.5.0
* Requires PHP: 8.1
*/

namespace TheFrosty\WpUpgradeTaskRunner;

const SLUG = 'wp-upgrade-task-runner';
const VERSION = '2.7.0';
const VERSION = '2.8.0';

use TheFrosty\WpUpgradeTaskRunner\Cli\DispatchTasks;
use TheFrosty\WpUpgradeTaskRunner\Upgrade\DbUpgrade;
Expand Down

0 comments on commit 81b093a

Please sign in to comment.