Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ build/
vendor/
composer.lock
perf/blackfire.io.env
.php-cs-fixer.cache
42 changes: 40 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,48 @@
declare(strict_types=1);

return (new PhpCsFixer\Config())
->setUsingCache(false)
->setRules([
'@Symfony' => true,
'array_syntax' => ['syntax' => 'short'],
'protected_to_private' => false,
'combine_consecutive_unsets' => true,
'combine_consecutive_issets' => true,
'compact_nullable_typehint' => true,
'declare_strict_types' => true,
'dir_constant' => true,
'ereg_to_preg' => true,
'explicit_indirect_variable' => true,
'explicit_string_variable' => true,
'function_to_constant' => true,
'is_null' => true,
'modernize_types_casting' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'mb_str_functions' => true,
'no_alias_functions' => true,
'no_homoglyph_names' => true,
'no_php4_constructor' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
'php_unit_expectation' => true,
'php_unit_mock' => true,
'php_unit_namespaced' => true,
'php_unit_method_casing' => ['case' => 'snake_case'],
'random_api_migration' => true,
'strict_comparison' => true,
'strict_param' => true,
'ternary_to_null_coalescing' => true,
'concat_space' => [
'spacing' => 'one',
],
'single_line_throw' => false,
'native_function_invocation' => [
'exclude' => [
'_'
'_',
],
'include' => ['@all'],
],
Expand All @@ -16,6 +53,7 @@
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->append([__FILE__])
)
;
77 changes: 9 additions & 68 deletions src/Contracts/Encoder/EncoderInterface.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace Neomerx\JsonApi\Contracts\Encoder;

/**
/*
* Copyright 2015-2020 info@neomerx.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,20 +24,13 @@
use Neomerx\JsonApi\Contracts\Schema\LinkInterface;
use Neomerx\JsonApi\Contracts\Schema\LinkWithAliasesInterface;

/**
* @package Neomerx\JsonApi
*/
interface EncoderInterface
{
/** JSON API version implemented by the encoder */
public const JSON_API_VERSION = '1.1';

/**
* This prefix will be used for URL links while encoding.
*
* @param string $prefix
*
* @return self
*/
public function withUrlPrefix(string $prefix): self;

Expand All @@ -47,10 +42,6 @@ public function withUrlPrefix(string $prefix): self;
* 'relationship1',
* 'relationship1.sub-relationship2',
* ]
*
* @param iterable $paths
*
* @return self
*/
public function withIncludedPaths(iterable $paths): self;

Expand All @@ -64,73 +55,47 @@ public function withIncludedPaths(iterable $paths): self;
*
* // 'type3' is not on the list so all its attributes and relationships will be in output.
* ]
*
* @param array $fieldSets
*
* @return self
*/
public function withFieldSets(array $fieldSets): self;

/**
* Set JSON encode options.
*
* @link http://php.net/manual/en/function.json-encode.php
*
* @param int $options
*
* @return self
* @see http://php.net/manual/en/function.json-encode.php
*/
public function withEncodeOptions(int $options): self;

/**
* Set JSON encode depth.
*
* @link http://php.net/manual/en/function.json-encode.php
*
* @param int $depth
*
* @return self
* @see http://php.net/manual/en/function.json-encode.php
*/
public function withEncodeDepth(int $depth): self;

/**
* Add links that will be encoded with data. Links must be in `$name => $link, ...` format.
*
* @param array $links
*
* @see LinkInterface
*
* @return self
*/
public function withLinks(array $links): self;

/**
* Add profile links that will be encoded with data. Links must be in `$link1, $link2, ...` format.
*
* @param iterable $links
*
* @see LinkWithAliasesInterface
*
* @return self
*/
public function withProfile(iterable $links): self;

/**
* Add meta information that will be encoded with data. If 'null' meta will not appear in a document.
*
* @param mixed|null $meta
*
* @return self
*/
public function withMeta($meta): self;

/**
* If called JSON API version information will be added to a document.
*
* @param string $version
*
* @return self
*
* @see http://jsonapi.org/format/#document-jsonapi-object
*/
public function withJsonApiVersion(string $version): self;
Expand All @@ -140,8 +105,6 @@ public function withJsonApiVersion(string $version): self;
*
* @param mixed $meta
*
* @return self
*
* @see http://jsonapi.org/format/#document-jsonapi-object
*/
public function withJsonApiMeta($meta): self;
Expand All @@ -150,77 +113,55 @@ public function withJsonApiMeta($meta): self;
* Add 'self' Link to top-level document's 'links' section for relationship specified.
*
* @param object $resource
* @param string $relationshipName
*
* @see http://jsonapi.org/format/#fetching-relationships
*
* @return self
*/
public function withRelationshipSelfLink($resource, string $relationshipName): self;

/**
* Add 'related' Link to top-level document's 'links' section for relationship specified.
*
* @param object $resource
* @param string $relationshipName
*
* @see http://jsonapi.org/format/#fetching-relationships
*
* @return self
*/
public function withRelationshipRelatedLink($resource, string $relationshipName): self;

/**
* Reset encoder settings to defaults.
*
* @return self
*/
public function reset(): self;

/**
* Encode input as JSON API string.
*
* @param object|iterable|null $data Data to encode.
*
* @return string
* @param object|iterable|null $data data to encode
*/
public function encodeData($data): string;

/**
* Encode input as JSON API string with a list of resource identifiers.
*
* @param object|iterable|null $data Data to encode.
*
* @return string
* @param object|iterable|null $data data to encode
*/
public function encodeIdentifiers($data): string;

/**
* Encode error as JSON API string.
*
* @param ErrorInterface $error
*
* @return string
*/
public function encodeError(ErrorInterface $error): string;

/**
* Encode errors as JSON API string.
*
* @see ErrorInterface
*
* @param iterable $errors
*
* @return string
*/
public function encodeErrors(iterable $errors): string;

/**
* Encode input meta as JSON API string.
*
* @param mixed $meta Meta information.
*
* @return string
* @param mixed $meta meta information
*/
public function encodeMeta($meta): string;
}
Loading