Skip to content
Merged
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
16 changes: 9 additions & 7 deletions src/WordPress/Blueprints/BlueprintParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use InvalidArgumentException;
use Opis\JsonSchema\Errors\ErrorFormatter;
use stdClass;
use WordPress\Blueprints\Model\BlueprintBuilder;
use WordPress\Blueprints\Model\DataClass\Blueprint;

Expand All @@ -27,8 +28,13 @@ public function __construct(
$this->mapper = $mapper;
}

/**
* @param Blueprint|string|stdClass $raw_blueprint
* @return Blueprint
* @throws InvalidArgumentException if unsupported input type or json string can not be decoded
*/
public function parse( $raw_blueprint ) {
if ( $raw_blueprint instanceof \stdClass ) {
if ( $raw_blueprint instanceof stdClass ) {
return $this->fromObject( $raw_blueprint );
}

Expand All @@ -46,17 +52,13 @@ public function parse( $raw_blueprint ) {
return $this->fromBlueprint( $raw_blueprint );
}

if ( $raw_blueprint instanceof BlueprintBuilder ) {
return $this->fromBlueprint( $raw_blueprint->toBlueprint() );
}

throw new InvalidArgumentException(
'Unsupported $rawBlueprint type. Use a JSON string, a parsed JSON object, or a BlueprintBuilder instance.'
'Unsupported $rawBlueprint type. Use a JSON string, a parsed JSON object, or a Blueprint instance.'
);
}

/**
* @param \stdClass $data
* @param stdClass $data
*/
public function fromObject( $data ) {
$result = $this->validator->validate( $data );
Expand Down