Skip to content

Commit

Permalink
Merge pull request #189 from netglue/php-8-syntax
Browse files Browse the repository at this point in the history
Apply PHP 8.0 Syntax
  • Loading branch information
gsteel committed Nov 4, 2022
2 parents 400a0cd + d411e83 commit 02f929a
Show file tree
Hide file tree
Showing 47 changed files with 207 additions and 378 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"psr/http-server-middleware": "^1.0.1"
},
"require-dev": {
"doctrine/coding-standard": "^9.0.2",
"doctrine/coding-standard": "^10.0.0",
"helmich/phpunit-psr7-assert": "^4.3",
"laminas/laminas-config-aggregator": "^1.11",
"laminas/laminas-servicemanager": "^3.19.0",
Expand Down
50 changes: 27 additions & 23 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
<file>test</file>

<!-- Inherit rules from Doctrine Coding Standard -->
<rule ref="Doctrine">
<!-- Whilst this lib is compatible with 7.3, exclude this sniff -->
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint" />
</rule>
<rule ref="Doctrine" />

<rule ref="Generic.Formatting.MultipleStatementAlignment.NotSame">
<severity>0</severity>
Expand Down
20 changes: 0 additions & 20 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
<code>new static($message, $code)</code>
</UnsafeInstantiation>
</file>
<file src="src/Exception/RoutingError.php">
<UnsafeInstantiation occurrences="2"/>
</file>
<file src="src/LinkResolver.php">
<MixedArrayAccess occurrences="1">
<code>$options['defaults'][$this-&gt;routeParams-&gt;reuseResultParams()]</code>
Expand Down Expand Up @@ -114,9 +111,6 @@
<MixedAssignment occurrences="1">
<code>$documentData</code>
</MixedAssignment>
<ParamNameMismatch occurrences="1">
<code>$data</code>
</ParamNameMismatch>
</file>
<file src="src/ResultSet/TypeMap.php">
<DocblockTypeContradiction occurrences="1">
Expand Down Expand Up @@ -304,23 +298,9 @@
</PossiblyUndefinedMethod>
</file>
<file src="test/Unit/Middleware/PrismicTemplateTest.php">
<MixedMethodCall occurrences="7">
<code>method</code>
<code>method</code>
<code>method</code>
<code>willReturn</code>
<code>willReturn</code>
<code>with</code>
<code>with</code>
</MixedMethodCall>
<NoInterfaceProperties occurrences="1">
<code>$this-&gt;handler-&gt;lastRequest</code>
</NoInterfaceProperties>
<PossiblyUndefinedMethod occurrences="3">
<code>expects</code>
<code>expects</code>
<code>expects</code>
</PossiblyUndefinedMethod>
</file>
<file src="test/Unit/Middleware/WebhookHandlerTest.php">
<MixedInferredReturnType occurrences="1">
Expand Down
4 changes: 2 additions & 2 deletions src/Container/ApiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __invoke(ContainerInterface $container): Api
if (empty($apiUrl) || ! is_string($apiUrl)) {
throw new ConfigurationError(
'An api url cannot be determined. Your content repository url should be available in ' .
'configuration under [prismic][api] and should be a non-empty string.'
'configuration under [prismic][api] and should be a non-empty string.',
);
}

Expand All @@ -43,7 +43,7 @@ public function __invoke(ContainerInterface $container): Api
$container->has(RequestFactoryInterface::class) ? $container->get(RequestFactoryInterface::class) : null,
$container->has(UriFactoryInterface::class) ? $container->get(UriFactoryInterface::class) : null,
$container->has(ResultSetFactory::class) ? $container->get(ResultSetFactory::class) : null,
$container->has(PrismicApiCache::class) ? $container->get(PrismicApiCache::class) : null
$container->has(PrismicApiCache::class) ? $container->get(PrismicApiCache::class) : null,
);
}
}
2 changes: 1 addition & 1 deletion src/Container/LinkResolverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __invoke(ContainerInterface $container): LinkResolver
$container->get(RouteParams::class),
$container->get(RouteMatcher::class),
$container->get(UrlHelper::class),
$container->get(ApiClient::class)->data()->bookmarks()
$container->get(ApiClient::class)->data()->bookmarks(),
);
}
}
20 changes: 5 additions & 15 deletions src/Event/WebhookEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@

final class WebhookEvent implements Serializable
{
/** @var int */
private $received;
/** @var object */
private $payload;
private int $received;

private function __construct(object $payload)
private function __construct(private object $payload)
{
$this->payload = $payload;
$this->received = time();
}

Expand All @@ -45,9 +41,7 @@ public function payload(): object
return $this->payload;
}

/**
* @deprecated
*/
/** @deprecated */
public function serialize(): string
{
return Json::encode([
Expand All @@ -70,9 +64,7 @@ public function unserialize($serialized): void
$this->received = $object->received;
}

/**
* @return array{received: int, payload: string}
*/
/** @return array{received: int, payload: string} */
public function __serialize(): array
{
return [
Expand All @@ -81,9 +73,7 @@ public function __serialize(): array
];
}

/**
* @param array{received: int, payload: string} $data
*/
/** @param array{received: int, payload: string} $data */
public function __unserialize(array $data): void
{
$this->received = $data['received'];
Expand Down
9 changes: 4 additions & 5 deletions src/Exception/RequestError.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

class RequestError extends RuntimeException implements PrimoError
{
/** @var RequestInterface|null */
private $request;
private RequestInterface|null $request = null;

public static function withRequest(RequestInterface $request, string $message, int $code): self
{
Expand All @@ -27,7 +26,7 @@ public static function withMissingRouteResult(RequestInterface $request): self
$message = sprintf(
'The request for %s failed because the route result was not available. This means that routing has ' .
'either not yet occurred or a route could not be matched.',
(string) $request->getUri()
(string) $request->getUri(),
);

return self::withRequest($request, $message, 500);
Expand All @@ -39,13 +38,13 @@ public static function withMissingTemplateAttribute(RequestInterface $request, s
'The request for "%s" failed because there was no template attribute found in the request. I was ' .
'expecting to find a template attribute named "%s"',
(string) $request->getUri(),
$expectedTemplateAttribute
$expectedTemplateAttribute,
);

return self::withRequest($request, $message, 500);
}

public function getRequest(): ?RequestInterface
public function getRequest(): RequestInterface|null
{
return $this->request;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Exception/RoutingError.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use const JSON_THROW_ON_ERROR;

/** @final */
class RoutingError extends RuntimeError
{
public static function uidMatchedWithoutType(RouteResult $routeResult): self
Expand All @@ -21,7 +22,7 @@ public static function uidMatchedWithoutType(RouteResult $routeResult): self
'The route named "%s" matches a Prismic UID, but the type cannot be resolved. You cannot resolve documents '
. 'by UID when the type is not known. Matched parameters: %s',
self::routeName($routeResult),
self::matchedParams($routeResult)
self::matchedParams($routeResult),
), 400);
}

Expand All @@ -31,7 +32,7 @@ public static function nonUniqueResult(RouteResult $routeResult, ResultSet $resu
'The route named "%s" matched %d documents when transformed into a query. Route parameters were: %s',
self::routeName($routeResult),
count($resultSet),
self::matchedParams($routeResult)
self::matchedParams($routeResult),
), 400);
}

Expand Down
Loading

0 comments on commit 02f929a

Please sign in to comment.