Skip to content

Commit

Permalink
Reduce dependency on getdkan/contracts (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-m authored Dec 13, 2024
1 parent 4de38fb commit e77c409
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 12 deletions.
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": "^1.2"
},
"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

0 comments on commit e77c409

Please sign in to comment.