Skip to content

Commit 5979425

Browse files
authored
Make exceptions more precise (#72)
1 parent 7615a38 commit 5979425

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

src/Document.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ public function setApiMeta(iterable $meta): void
108108
public function setIncluded(ResourceObject ...$resources): void
109109
{
110110
if (null === $this->data) {
111-
throw new \LogicException('Document with no data cannot contain included resources');
111+
throw new \DomainException('Document with no data cannot contain included resources');
112112
}
113113
foreach ($resources as $resource) {
114114
if (isset($this->included[(string) $resource->toIdentifier()])) {
115-
throw new \LogicException("Resource {$resource->toIdentifier()} is already included");
115+
throw new \DomainException("Resource {$resource->toIdentifier()} is already included");
116116
}
117117
$this->included[(string) $resource->toIdentifier()] = $resource;
118118
}
@@ -150,7 +150,7 @@ private function enforceFullLinkage(): void
150150
continue 2;
151151
}
152152
}
153-
throw new \LogicException("Full linkage is required for {$included->toIdentifier()}");
153+
throw new \DomainException("Full linkage is required for {$included->toIdentifier()}");
154154
}
155155
}
156156
}

src/Document/Resource/ResourceObject.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,27 @@ public function setMeta(iterable $meta)
4040
public function setAttribute(string $name, $value)
4141
{
4242
if ($this->isReservedName($name)) {
43-
throw new \InvalidArgumentException("Can not use a reserved name '$name'");
43+
throw new \DomainException("Can not use a reserved name '$name'");
4444
}
4545
if (! isValidMemberName($name)) {
4646
throw new \OutOfBoundsException("Invalid member name '$name'");
4747
}
4848
if (isset($this->relationships[$name])) {
49-
throw new \LogicException("Field '$name' already exists in relationships");
49+
throw new \DomainException("Field '$name' already exists in relationships");
5050
}
5151
$this->attributes[$name] = $value;
5252
}
5353

5454
public function setRelationship(string $name, Relationship $relationship)
5555
{
5656
if ($this->isReservedName($name)) {
57-
throw new \InvalidArgumentException("Can not use a reserved name '$name'");
57+
throw new \DomainException("Can not use a reserved name '$name'");
5858
}
5959
if (! isValidMemberName($name)) {
6060
throw new \OutOfBoundsException("Invalid member name '$name'");
6161
}
6262
if (isset($this->attributes[$name])) {
63-
throw new \LogicException("Field '$name' already exists in attributes");
63+
throw new \DomainException("Field '$name' already exists in attributes");
6464
}
6565
$this->relationships[$name] = $relationship;
6666
}

test/Document/CompoundDocumentTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function testOfficialDocsExample()
164164
}
165165

166166
/**
167-
* @expectedException \LogicException
167+
* @expectedException \DomainException
168168
* @expectedExceptionMessage Full linkage is required for apples:1
169169
* @dataProvider documentsWithoutFullLinkage
170170
* @param Document $doc
@@ -269,7 +269,7 @@ public function testIncludedResourceMayBeIdentifiedByAnotherLinkedResource()
269269

270270
/**
271271
* A compound document MUST NOT include more than one resource object for each type and id pair.
272-
* @expectedException \LogicException
272+
* @expectedException \DomainException
273273
* @expectedExceptionMessage Resource apples:1 is already included
274274
*/
275275
public function testCanNotBeManyIncludedResourcesWithEqualIdentifiers()
@@ -283,7 +283,7 @@ public function testCanNotBeManyIncludedResourcesWithEqualIdentifiers()
283283

284284
/**
285285
* If a document does not contain a top-level data key, the included member MUST NOT be present either.
286-
* @expectedException \LogicException
286+
* @expectedException \DomainException
287287
* @expectedExceptionMessage Document with no data cannot contain included resources
288288
*/
289289
public function testIncludedMustOnlyBePresentWithData()

test/Document/Resource/ResourceFieldsTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class ResourceFieldsTest extends TestCase
2222
{
2323
/**
24-
* @expectedException \LogicException
24+
* @expectedException \DomainException
2525
* @expectedExceptionMessage Field 'foo' already exists in attributes
2626
*/
2727
public function testCanNotSetRelationshipIfAttributeExists()
@@ -32,7 +32,7 @@ public function testCanNotSetRelationshipIfAttributeExists()
3232
}
3333

3434
/**
35-
* @expectedException \LogicException
35+
* @expectedException \DomainException
3636
* @expectedExceptionMessage Field 'foo' already exists in relationships
3737
*/
3838
public function testCanNotSetAttributeIfRelationshipExists()
@@ -44,7 +44,7 @@ public function testCanNotSetAttributeIfRelationshipExists()
4444

4545
/**
4646
* @param string $name
47-
* @expectedException \InvalidArgumentException
47+
* @expectedException \DomainException
4848
* @expectedExceptionMessage Can not use a reserved name
4949
* @dataProvider reservedAttributeNames
5050
*/
@@ -56,7 +56,7 @@ public function testAttributeCanNotHaveReservedNames(string $name)
5656

5757
/**
5858
* @param string $name
59-
* @expectedException \InvalidArgumentException
59+
* @expectedException \DomainException
6060
* @expectedExceptionMessage Can not use a reserved name
6161
* @dataProvider reservedAttributeNames
6262
*/

0 commit comments

Comments
 (0)