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
306 changes: 0 additions & 306 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1770,312 +1770,6 @@ parameters:
count: 1
path: src/Phaseolies/Support/Facades/DB.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: array\)\: Unexpected token "\\n \* ", expected type at offset 2932 on line 58$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 1633 on line 30$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 1667 on line 31$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 1708 on line 32$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 1886 on line 36$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 1927 on line 37$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 2897 on line 57$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 3103 on line 61$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 3142 on line 62$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 3182 on line 63$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 3222 on line 64$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 3253 on line 65$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 3291 on line 66$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 3328 on line 67$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 661 on line 14$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 695 on line 15$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: int\)\: Unexpected token "\\n \* ", expected type at offset 2068 on line 40$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: int\)\: Unexpected token "\\n \* ", expected type at offset 433 on line 10$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 1020 on line 21$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 1747 on line 33$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 1785 on line 34$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 2103 on line 41$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 2863 on line 56$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: string\)\: Unexpected token "\\n \* ", expected type at offset 1252 on line 25$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: string\)\: Unexpected token "\\n \* ", expected type at offset 804 on line 17$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\?\\DateTimeInterface \$date\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 2219 on line 43$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\?string \$body\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 52 on line 2$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(HttpException \$exception\)\: void\)\: Unexpected token "\\n \* ", expected type at offset 1217 on line 24$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(Request \$request\)\: bool\)\: Unexpected token "\\n \* ", expected type at offset 3067 on line 60$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(Request \$request\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 856 on line 18$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\\DateTimeInterface \$date\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 2036 on line 39$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(array \$headers\)\: Response\)\: Unexpected token "\\n \* ", expected type at offset 573 on line 12$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(array \$options\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 2820 on line 55$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(int \$seconds\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 2553 on line 50$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(int \$seconds\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 2606 on line 51$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(int \$statusCode\)\: string\)\: Unexpected token "\\n \* ", expected type at offset 980 on line 20$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(int \$targetLevel, bool \$flush\)\: void\)\: Unexpected token "\\n \* ", expected type at offset 1145 on line 23$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(int \$value\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 2303 on line 45$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(int \$value\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 2357 on line 46$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(int \$value\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 2419 on line 47$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(int \$value\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 2473 on line 48$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(string \$charset\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 224 on line 6$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(string \$version\)\: static\)\: Unexpected token "\\n \* ", expected type at offset 757 on line 16$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(static getBody\(\)\: \?string\)\: Unexpected token "\\n \* ", expected type at offset 89 on line 3$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(static getCharset\(\)\: \?string\)\: Unexpected token "\\n \* ", expected type at offset 264 on line 7$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(static getDate\(\)\: \?\\DateTimeImmutable\)\: Unexpected token "\\n \* ", expected type at offset 1976 on line 38$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(static getEtag\(\)\: \?string\)\: Unexpected token "\\n \* ", expected type at offset 2700 on line 53$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(static getExpires\(\)\: \?\\DateTimeImmutable\)\: Unexpected token "\\n \* ", expected type at offset 2155 on line 42$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(static getLastModified\(\)\: \?\\DateTimeImmutable\)\: Unexpected token "\\n \* ", expected type at offset 2663 on line 52$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(static getMaxAge\(\)\: \?int\)\: Unexpected token "\\n \* ", expected type at offset 2255 on line 44$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(static getTtl\(\)\: \?int\)\: Unexpected token "\\n \* ", expected type at offset 2506 on line 49$#'
identifier: phpDoc.parseError
count: 1
path: src/Phaseolies/Support/Facades/Response.php

-
message: '#^PHPDoc tag @method has invalid value \(\(\)\: array\)\: Unexpected token "\\n \* ", expected type at offset 529 on line 12$#'
identifier: phpDoc.parseError
Expand Down
12 changes: 7 additions & 5 deletions src/Phaseolies/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Phaseolies\Http\Request;
use Phaseolies\Http\Contracts\GatewayInterface;
use Phaseolies\Http\Exceptions\HttpException;
use Phaseolies\Http\Exceptions\BadRequestHttpException;
use Phaseolies\Http\Exceptions\HttpResponseException;
use Phaseolies\Session\Contracts\CommittableSession;
use Phaseolies\Error\ErrorHandler;
Expand Down Expand Up @@ -1519,16 +1520,17 @@ protected function typeAllowsNull(\ReflectionType $type): bool
*
* @param Request $request
* @return Response
* @throws BadRequestHttpException
*/
public function handle(Request $request): Response
{
$response = $this->router->resolve($this, $request);

if (!$response instanceof Response) {
$response = $response->setBody((string) $response);
if ($error = $request->getMalformedRequestError()) {
throw $error instanceof BadRequestHttpException
? $error
: new BadRequestHttpException($error->getMessage(), $error);
}

return $response;
return $this->router->resolve($this, $request);
}

/**
Expand Down
30 changes: 27 additions & 3 deletions src/Phaseolies/Database/Entity/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,14 +706,38 @@ public function makeHidden(array $attributes): self
return $this;
}

/**
* Number of jsonSerialize() calls in progress (nested relations included).
*
* @var int
*/
private static int $jsonSerializationDepth = 0;

/**
* Serializes the model to an array for JSON representation.
*
* @return array
*/
public function jsonSerialize(): array
{
return $this->toArray();
self::$jsonSerializationDepth++;

try {
return $this->toArray();
} finally {
self::$jsonSerializationDepth--;
}
}

/**
* Serialize a related model for toArray(): through jsonSerialize() while
*
* @param Model $model
* @return array
*/
protected function serializeRelatedModel(Model $model): array
{
return self::$jsonSerializationDepth > 0 ? $model->jsonSerialize() : $model->toArray();
}

/**
Expand Down Expand Up @@ -1315,10 +1339,10 @@ public function toArray(): array
if ($relation === null) {
$attributes[$key] = null;
} elseif ($relation instanceof Model) {
$attributes[$key] = $relation->toArray();
$attributes[$key] = $this->serializeRelatedModel($relation);
} elseif ($relation instanceof Collection) {
$attributes[$key] = $relation->map(function ($item) {
$result = $item instanceof Model ? $item->toArray() : (array)$item;
$result = $item instanceof Model ? $this->serializeRelatedModel($item) : (array)$item;
if (isset($item->pivot)) {
$result['pivot'] = (array)$item->pivot;
}
Expand Down
Loading
Loading