Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor parser and hydrator #54

Merged
merged 8 commits into from
Jul 10, 2019
Merged

Conversation

JaZo
Copy link
Member

@JaZo JaZo commented Jul 9, 2019

Description

I refactored the Parser and Hydrator into several smaller classes similar to the existing parsers. This should improve the code quality and lower the complexity. Besides that, I made sure everything is properly tested. This is a breaking change if you use one of the parsers yourself instead of the repository.

An important change to note is that relationships with data that is not included in the document are now also hydrated as empty Item.

Given

{
	"data": {
		"type": "foo",
		"id": "1",
		"attributes": {
			"Foo": "bar"
		},
		"relationships": {
			"child": {
				"data": {
					"type": "child",
					"id": "1"
				}
			}
		}
	}
}

Before

$item->child // null

After

$item->child // \Swis\JsonApi\Client\Item

Motivation and context

The Parser and Hydrator are fairly complex and tightly coupled. Besides that, test coverage was poor.

How has this been tested?

Test using new and existing unit tests.

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • I have read the CONTRIBUTING document.
  • My pull request addresses exactly one patch/feature.
  • I have created a branch for this patch/feature.
  • Each individual commit in the pull request is meaningful.
  • I have added tests to cover my changes.
  • If my change requires a change to the documentation, I have updated it accordingly.

@JaZo JaZo requested a review from vblinden July 9, 2019 13:13
@JaZo JaZo force-pushed the feature/refactor-parser-hydrator branch from 10718cb to 9719ff9 Compare July 9, 2019 14:59
Copy link

@vblinden vblinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small inconsistency with the naming of Jsonapi and jsonapi.

src/Document.php Show resolved Hide resolved
@JaZo JaZo dismissed vblinden’s stale review July 10, 2019 13:34

We leave it like it is

@JaZo JaZo merged commit e7017e8 into master Jul 10, 2019
@JaZo JaZo deleted the feature/refactor-parser-hydrator branch July 10, 2019 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants