| @@ -25,7 +25,7 @@ discard block | ||
| 25 | 25 | $this->metadata ??= new Repository(); | 
| 26 | 26 | } | 
| 27 | 27 | |
| 28 | - public function serialize(object|array $resource): array | |
| 28 | + public function serialize(object | array $resource): array | |
| 29 | 29 |      { | 
| 30 | 30 | return is_array($resource) | 
| 31 | 31 | ? array_map(fn($resource) => $this->serializeResource($resource), $resource) | 
| @@ -65,7 +65,7 @@ discard block | ||
| 65 | 65 | return $data; | 
| 66 | 66 | } | 
| 67 | 67 | |
| 68 | - protected function serializeAttributes(object $resource, array|null $fields): array|null | |
| 68 | + protected function serializeAttributes(object $resource, array | null $fields): array | null | |
| 69 | 69 |      { | 
| 70 | 70 | if (($this->options[static::OPTIONS_NO_ATTRIBUTES] ?? false) === true) return null; | 
| 71 | 71 | |
| @@ -73,7 +73,7 @@ discard block | ||
| 73 | 73 | |
| 74 | 74 | $attributes = array_filter( | 
| 75 | 75 | $this->metadata->getResourceAttributes($resource), | 
| 76 | - fn ($key) => is_null($fields) || in_array($key, $fields) | |
| 76 | + fn($key) => is_null($fields) || in_array($key, $fields) | |
| 77 | 77 | ); | 
| 78 | 78 | |
| 79 | 79 |          foreach ($attributes as $key => $attribute) { | 
| @@ -83,7 +83,7 @@ discard block | ||
| 83 | 83 | return $result; | 
| 84 | 84 | } | 
| 85 | 85 | |
| 86 | - protected function serializeRelationships(object $resource): array|null | |
| 86 | + protected function serializeRelationships(object $resource): array | null | |
| 87 | 87 |      { | 
| 88 | 88 | if ($this->includeset === null || count($this->includeset) === 0) return null; | 
| 89 | 89 | |
| @@ -67,7 +67,9 @@ discard block | ||
| 67 | 67 | |
| 68 | 68 | protected function serializeAttributes(object $resource, array|null $fields): array|null | 
| 69 | 69 |      { | 
| 70 | - if (($this->options[static::OPTIONS_NO_ATTRIBUTES] ?? false) === true) return null; | |
| 70 | +        if (($this->options[static::OPTIONS_NO_ATTRIBUTES] ?? false) === true) { | |
| 71 | + return null; | |
| 72 | + } | |
| 71 | 73 | |
| 72 | 74 | $result = []; | 
| 73 | 75 | |
| @@ -85,14 +87,18 @@ discard block | ||
| 85 | 87 | |
| 86 | 88 | protected function serializeRelationships(object $resource): array|null | 
| 87 | 89 |      { | 
| 88 | - if ($this->includeset === null || count($this->includeset) === 0) return null; | |
| 90 | +        if ($this->includeset === null || count($this->includeset) === 0) { | |
| 91 | + return null; | |
| 92 | + } | |
| 89 | 93 | |
| 90 | 94 | $relationships = []; | 
| 91 | 95 | $relationshipsMap = $this->metadata->getResourceRelationships($resource); | 
| 92 | 96 | |
| 93 | 97 |          foreach ($this->includeset as $relation => $childIncludeset) { | 
| 94 | 98 | // TODO: Maybe we should throw an exception here | 
| 95 | - if (!isset($relationshipsMap[$relation])) continue; | |
| 99 | +            if (!isset($relationshipsMap[$relation])) { | |
| 100 | + continue; | |
| 101 | + } | |
| 96 | 102 | |
| 97 | 103 | $value = $relationshipsMap[$relation]->getValue($resource); | 
| 98 | 104 | |
| @@ -19,7 +19,9 @@ | ||
| 19 | 19 | $parserInclude = explode(static::RELATION_SEPARATOR, $item, 2); | 
| 20 | 20 | $relation = array_shift($parserInclude); | 
| 21 | 21 | |
| 22 | - if (empty($relation)) continue; | |
| 22 | +            if (empty($relation)) { | |
| 23 | + continue; | |
| 24 | + } | |
| 23 | 25 | |
| 24 | 26 | $rawChildren = array_shift($parserInclude) ?? ''; | 
| 25 | 27 | |
| @@ -34,7 +34,7 @@ discard block | ||
| 34 | 34 | |
| 35 | 35 | return array_reduce( | 
| 36 | 36 | array_keys($values), | 
| 37 | - fn ($result, $key) => $result && $this->set($key, $values[$key], $ttl), | |
| 37 | + fn($result, $key) => $result && $this->set($key, $values[$key], $ttl), | |
| 38 | 38 | true | 
| 39 | 39 | ); | 
| 40 | 40 | } | 
| @@ -57,7 +57,7 @@ discard block | ||
| 57 | 57 |              throw new InvalidKeyException('Keys must be an array', 3); | 
| 58 | 58 | } | 
| 59 | 59 | |
| 60 | - return array_map(fn ($key) => $this->get($key, $default), $keys); | |
| 60 | + return array_map(fn($key) => $this->get($key, $default), $keys); | |
| 61 | 61 | } | 
| 62 | 62 | |
| 63 | 63 | public function has($key) | 
| @@ -86,7 +86,7 @@ discard block | ||
| 86 | 86 | |
| 87 | 87 | return array_reduce( | 
| 88 | 88 | $keys, | 
| 89 | - fn ($result, $key) => $result && $this->delete($key), | |
| 89 | + fn($result, $key) => $result && $this->delete($key), | |
| 90 | 90 | true | 
| 91 | 91 | ); | 
| 92 | 92 | } | 
| @@ -109,7 +109,7 @@ discard block | ||
| 109 | 109 |      { | 
| 110 | 110 |          try { | 
| 111 | 111 |              if (!is_null($ttl) && is_numeric($ttl)) { | 
| 112 | -                $ttl = new DateInterval(sprintf('%sS', (int)$ttl)); | |
| 112 | +                $ttl = new DateInterval(sprintf('%sS', (int) $ttl)); | |
| 113 | 113 | } | 
| 114 | 114 |          } catch (\Exception $e) { | 
| 115 | 115 |              throw new InvalidTTLException('Failed to parse provided ttl', 1, $e); | 
| @@ -18,7 +18,7 @@ discard block | ||
| 18 | 18 | * | 
| 19 | 19 | * @return array|null | 
| 20 | 20 | */ | 
| 21 | - public function resourceLinks(object $resource): array|null; | |
| 21 | + public function resourceLinks(object $resource): array | null; | |
| 22 | 22 | |
| 23 | 23 | /** | 
| 24 | 24 | * Provides links data for resource relation. | 
| @@ -36,5 +36,5 @@ discard block | ||
| 36 | 36 | * | 
| 37 | 37 | * @return array|null | 
| 38 | 38 | */ | 
| 39 | - public function relationshipLinks(object $resource, string $relationship): array|null; | |
| 39 | + public function relationshipLinks(object $resource, string $relationship): array | null; | |
| 40 | 40 | } | 
| 41 | 41 | \ No newline at end of file | 
| @@ -12,7 +12,7 @@ discard block | ||
| 12 | 12 | $this->metadata ??= new Repository(); | 
| 13 | 13 | } | 
| 14 | 14 | |
| 15 | - public function resourceLinks(object $resource): array|null | |
| 15 | + public function resourceLinks(object $resource): array | null | |
| 16 | 16 |      { | 
| 17 | 17 | $meta = $this->metadata->getResourceMeta($resource); | 
| 18 | 18 | $type = $meta->getType(); | 
| @@ -23,7 +23,7 @@ discard block | ||
| 23 | 23 | ]; | 
| 24 | 24 | } | 
| 25 | 25 | |
| 26 | - public function relationshipLinks(object $resource, string $relationship): array|null | |
| 26 | + public function relationshipLinks(object $resource, string $relationship): array | null | |
| 27 | 27 |      { | 
| 28 | 28 | $links = []; | 
| 29 | 29 | |
| @@ -49,11 +49,11 @@ discard block | ||
| 49 | 49 |          foreach ($this->possibleFieldsReflections($resource) as $ref) { | 
| 50 | 50 | $attributes = array_merge($attributes, array_map( | 
| 51 | 51 | // Create meta field | 
| 52 | - fn (AbstractField $field) => new Field($field, $ref), | |
| 52 | + fn(AbstractField $field) => new Field($field, $ref), | |
| 53 | 53 | |
| 54 | 54 | // Find and convert reflection attribute to attribute instance. | 
| 55 | 55 | array_map( | 
| 56 | - fn ($attr) => $attr->newInstance(), | |
| 56 | + fn($attr) => $attr->newInstance(), | |
| 57 | 57 | $ref->getAttributes(Attribute::class, ReflectionAttribute::IS_INSTANCEOF) | 
| 58 | 58 | ) | 
| 59 | 59 | )); | 
| @@ -73,11 +73,11 @@ discard block | ||
| 73 | 73 |          foreach ($this->possibleFieldsReflections($resource) as $ref) { | 
| 74 | 74 | $relationships = array_merge($relationships, array_map( | 
| 75 | 75 | // Create meta field | 
| 76 | - fn (AbstractField $field) => new Field($field, $ref), | |
| 76 | + fn(AbstractField $field) => new Field($field, $ref), | |
| 77 | 77 | |
| 78 | 78 | // Find and convert reflection attribute to attribute instance. | 
| 79 | 79 | array_map( | 
| 80 | - fn ($attr) => $attr->newInstance(), | |
| 80 | + fn($attr) => $attr->newInstance(), | |
| 81 | 81 | $ref->getAttributes(Relationship::class, ReflectionAttribute::IS_INSTANCEOF) | 
| 82 | 82 | ) | 
| 83 | 83 | )); | 
| @@ -1,6 +1,6 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | -include_once __DIR__ . '/vendor/autoload.php'; | |
| 3 | +include_once __DIR__.'/vendor/autoload.php'; | |
| 4 | 4 | |
| 5 | 5 | use JSONAPI\Resource\Includeset; | 
| 6 | 6 | use JSONAPI\Resource\Serializer; | 
| @@ -15,8 +15,8 @@ discard block | ||
| 15 | 15 | |
| 16 | 16 | function convert($size) | 
| 17 | 17 |  { | 
| 18 | -    $unit=array('b','kb','mb','gb','tb','pb'); | |
| 19 | - return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i]; | |
| 18 | +    $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); | |
| 19 | + return @round($size/pow(1024, ($i = floor(log($size, 1024)))), 2).' '.$unit[$i]; | |
| 20 | 20 | } | 
| 21 | 21 | |
| 22 | 22 | $articles = [ |