Browse Source

will now throw an Exception if the Name isn't set

pull/2/head
Cerys 6 months ago
parent
commit
be7423882d
  1. 17
      src/Exceptions/SchemaNameUnsetException.php
  2. 6
      src/SchemaBuilder/SchemaBuilder.php

17
src/Exceptions/SchemaNameUnsetException.php

@ -0,0 +1,17 @@
<?php
namespace Darksparrow\DeegraphPHP\Exceptions;
use Exception;
class SchemaNameUnsetException extends Exception
{
public function __construct(
string $message = "The Name field is required.",
int $code = 422
) {
parent::__construct($message, $code);
$this->message = "$message";
$this->code = $code;
}
}

6
src/SchemaBuilder/SchemaBuilder.php

@ -2,11 +2,15 @@
namespace Darksparrow\DeegraphPHP\SchemaBuilder;
use Darksparrow\DeegraphPHP\Exceptions\SchemaNameUnsetException;
use Darksparrow\DeegraphPHP\SchemaBuilder\Attributes\SchemaDocumentField;
use ReflectionClass;
class SchemaBuilder
{
/**
* @throws SchemaNameUnsetException
*/
public static function GenerateSchema(object $targetSchema): array
{
$validAttributeNames = [];
@ -57,7 +61,7 @@ class SchemaBuilder
}
}
if($propertyName == "")
throw new \Exception();
throw new SchemaNameUnsetException();
$schema["$propertyName"] = $propertySchema;
}

Loading…
Cancel
Save