Skip to content

Commit

Permalink
Renamed several classes
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Dec 19, 2016
1 parent a727136 commit 9ed38b8
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ CHANGED:
- Added `JsonApiResource::setToManyRelationship()` instead of `JsonApiResource::addToManyResourceIdentifier()`
- A `Links` member won't be present in the `data` member when it is empty when using `Document::toArray()`
- Renamed several methods of `ResourceObjects` (removed `get` prefixes)
- Renamed `JsonApiRelationshipInterface` class to `RelationshipInterface`
- Renamed `JsonApiResource` class to `ResourceObject`
- Renamed `JsonApiToManyRelationship` class to `ToManyRelationship`
- Renamed `JsonApiToOneRelationship` class to `ToOneRelationship`

FIXED:

Expand Down
4 changes: 2 additions & 2 deletions src/JsonApi/Request/JsonApiRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,14 @@ public function setJsonApiIncludes($includes)
}

/**
* @param \WoohooLabs\Yang\JsonApi\Request\JsonApiResource|array|object|string $body
* @param \WoohooLabs\Yang\JsonApi\Request\ResourceObject|array|object|string $body
* @return $this
*/
public function setJsonApiBody($body)
{
if (is_string($body)) {
$this->body = $body;
} elseif ($body instanceof JsonApiResource) {
} elseif ($body instanceof ResourceObject) {
$this->body = json_encode($body->toArray());
} elseif (is_array($body) || is_object($body)) {
$this->body = json_encode($body);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace WoohooLabs\Yang\JsonApi\Request;

interface JsonApiRelationshipInterface
interface RelationshipInterface
{
/**
* @return array
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace WoohooLabs\Yang\JsonApi\Request;

class JsonApiResource
class ResourceObject
{
/**
* @var string
Expand All @@ -19,7 +19,7 @@ class JsonApiResource
private $attributes;

/**
* @var JsonApiRelationshipInterface[]
* @var RelationshipInterface[]
*/
private $relationships;

Expand Down Expand Up @@ -70,30 +70,30 @@ public function setAttribute($name, $value)

/**
* @param string $name
* @param JsonApiToOneRelationship $relationship
* @param ToOneRelationship $relationship
* @return $this
*/
public function setToOneRelationship($name, JsonApiToOneRelationship $relationship)
public function setToOneRelationship($name, ToOneRelationship $relationship)
{
return $this->setRelationship($name, $relationship);
}

/**
* @param string $name
* @param JsonApiToManyRelationship $relationship
* @param ToManyRelationship $relationship
* @return $this
*/
public function setToManyRelationship($name, JsonApiToManyRelationship $relationship)
public function setToManyRelationship($name, ToManyRelationship $relationship)
{
return $this->setRelationship($name, $relationship);
}

/**
* @param string $name
* @param JsonApiRelationshipInterface $relationship
* @param RelationshipInterface $relationship
* @return $this
*/
public function setRelationship($name, JsonApiRelationshipInterface $relationship)
public function setRelationship($name, RelationshipInterface $relationship)
{
$this->relationships[$name] = $relationship;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace WoohooLabs\Yang\JsonApi\Request;

class JsonApiToManyRelationship implements JsonApiRelationshipInterface
class ToManyRelationship implements RelationshipInterface
{
/**
* @var array
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace WoohooLabs\Yang\JsonApi\Request;

class JsonApiToOneRelationship implements JsonApiRelationshipInterface
class ToOneRelationship implements RelationshipInterface
{
/**
* @var string
Expand Down
28 changes: 14 additions & 14 deletions tests/JsonApi/Request/JsonApiResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
namespace WoohooLabs\Yang\Tests\JsonApi\Request;

use PHPUnit\Framework\TestCase;
use WoohooLabs\Yang\JsonApi\Request\JsonApiResource;
use WoohooLabs\Yang\JsonApi\Request\JsonApiToManyRelationship;
use WoohooLabs\Yang\JsonApi\Request\JsonApiToOneRelationship;
use WoohooLabs\Yang\JsonApi\Request\ResourceObject;
use WoohooLabs\Yang\JsonApi\Request\ToManyRelationship;
use WoohooLabs\Yang\JsonApi\Request\ToOneRelationship;

class JsonApiResourceTest extends TestCase
{
Expand All @@ -13,17 +13,17 @@ class JsonApiResourceTest extends TestCase
*/
public function create()
{
$resource = JsonApiResource::create("", "");
$resource = ResourceObject::create("", "");

$this->assertInstanceOf(JsonApiResource::class, $resource);
$this->assertInstanceOf(ResourceObject::class, $resource);
}

/**
* @test
*/
public function getType()
{
$resource = new JsonApiResource("a");
$resource = new ResourceObject("a");

$this->assertEquals(
[
Expand All @@ -40,7 +40,7 @@ public function getType()
*/
public function getId()
{
$resource = new JsonApiResource("", "b");
$resource = new ResourceObject("", "b");

$this->assertEquals(
[
Expand All @@ -58,7 +58,7 @@ public function getId()
*/
public function setAttributes()
{
$resource = new JsonApiResource("", "");
$resource = new ResourceObject("", "");
$resource
->setAttributes(["a" => "b", "c" => "d"]);

Expand All @@ -81,7 +81,7 @@ public function setAttributes()
*/
public function setAttribute()
{
$resource = new JsonApiResource("", "");
$resource = new ResourceObject("", "");
$resource
->setAttribute("a", "b")
->setAttribute("c", "d");
Expand All @@ -105,9 +105,9 @@ public function setAttribute()
*/
public function setToOneRelationship()
{
$resource = new JsonApiResource("", "");
$resource = new ResourceObject("", "");
$resource
->setToOneRelationship("a", new JsonApiToOneRelationship("a", "a1"));
->setToOneRelationship("a", new ToOneRelationship("a", "a1"));

$this->assertEquals(
[
Expand All @@ -132,10 +132,10 @@ public function setToOneRelationship()
*/
public function setToManyRelationship()
{
$resource = new JsonApiResource("", "");
$resource = new ResourceObject("", "");
$resource
->setToManyRelationship("a", new JsonApiToManyRelationship())
->setToManyRelationship("b", new JsonApiToManyRelationship());
->setToManyRelationship("a", new ToManyRelationship())
->setToManyRelationship("b", new ToManyRelationship());

$this->assertEquals(
[
Expand Down

0 comments on commit 9ed38b8

Please sign in to comment.