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

Loading…
Cancel
Save