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

Factor out getdkan/contracts #23

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"require": {
"php": ">7.3 <8.4",
"ext-json": "*",
"getdkan/contracts": "^1.1.3"
"getdkan/contracts": "dev-no-contracts"
},
"require-dev": {
"phpunit/phpunit": ">8.5.14 <10.0.0",
"rector/rector": "@stable",
"rector/rector": "^1@stable",
"squizlabs/php_codesniffer": "^3.7",
"symfony/phpunit-bridge": "^7.0"
},
Expand Down
7 changes: 2 additions & 5 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Set\ValueObject\SetList;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/test',
__DIR__ . '/rector.php',
]);

$rectorConfig->sets([
Expand All @@ -24,9 +24,6 @@
]);

$rectorConfig->skip([
// Don't throw errors on JSON parse problems. Yet.
// @todo Throw errors and deal with them appropriately.
JsonThrowOnErrorRector::class,
// We like our tags. Please don't remove them.
RemoveUselessParamTagRector::class,
RemoveUselessReturnTagRector::class,
Expand Down
28 changes: 28 additions & 0 deletions src/HydratableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Procrastinator;

/**
* Interface to hydrate JSON into PHP variables.
*
* This interface is similar to \JsonSerializable in that we can 'hydrate' JSON
* into PHP structures.
*
* @see \Procrastinator\HydratableTrait
* @see \JsonSerializable
*/
interface HydratableInterface extends \JsonSerializable
{
/**
* Hydrate some JSON into a PHP object or array or other variable.
*
* @param string $json
* The JSON to process.
* @param $instance
* (Optional) Create a new instance without invoking the constructor.
*
* @return mixed
* The hydrated data structure.
*/
public static function hydrate(string $json, $instance = null);
}
7 changes: 5 additions & 2 deletions src/Job/AbstractPersistentJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Procrastinator\Job;

use Contracts\StorerInterface;
use Contracts\RetrieverInterface;
use Contracts\HydratableInterface;
use Contracts\StorerInterface;
use Procrastinator\HydratableInterface;
use Procrastinator\HydratableTrait;
use Procrastinator\Result;

Expand All @@ -25,6 +25,9 @@ public function run(): Result

public static function get(string $identifier, $storage, array $config = null)
{
// @todo We need to somehow change these references to StorerInterface
// and RetrieverInterface, in order to decouple from
// getdkan/contracts.
if ($storage instanceof StorerInterface && $storage instanceof RetrieverInterface) {
$new = new static($identifier, $storage, $config);

Expand Down
2 changes: 0 additions & 2 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Procrastinator;

use Contracts\HydratableInterface;

class Result implements HydratableInterface
{
use HydratableTrait;
Expand Down
2 changes: 1 addition & 1 deletion test/Mock/Complex.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ProcrastinatorTest\Mock;

use Contracts\HydratableInterface;
use Procrastinator\HydratableInterface;
use Procrastinator\HydratableTrait;
use Procrastinator\JsonSerializeTrait;

Expand Down