Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Commit

Permalink
Fix new Psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
leocavalcante committed Jul 31, 2020
1 parent 6ebadd1 commit 855c688
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 55 deletions.
6 changes: 3 additions & 3 deletions src/GraphQL/DateScalar.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DateScalar extends ScalarType
public function serialize($value): string
{
if ($value instanceof DateTime) {
return $value->format(strval(static::FORMAT));
return $value->format((string)static::FORMAT);
}

throw new Error('Don\'t know how to serialize non-DateTime');
Expand Down Expand Up @@ -56,11 +56,11 @@ public function parseValue($value)
$date_time = false;

if (is_string($value)) {
$date_time = DateTime::createFromFormat(strval(static::FORMAT), $value);
$date_time = DateTime::createFromFormat((string)static::FORMAT, $value);
}

if ($date_time === false) {
throw new Error(sprintf("Error parsing $value as %s. Is it in %s format?", $this->name, strval(static::FORMAT)));
throw new Error(sprintf("Error parsing $value as %s. Is it in %s format?", $this->name, (string)static::FORMAT));
}

return $date_time;
Expand Down
41 changes: 2 additions & 39 deletions src/GraphQL/SubscriptionsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function handleStart(SubscriptionsConnection $conn, array $data): void
$conn_subs = array_key_exists($conn->key(), $this->connStorage)
? $this->connStorage[$conn->key()]
: [];
$conn_subs[strval($data['id'])] = $data;
$conn_subs[(string)$data['id']] = $data;
$this->connStorage[$conn->key()] = $conn_subs;

$this->callListener(ON_OPERATION, [$data, $this->rootValue, $this->context]);
Expand Down Expand Up @@ -200,50 +200,13 @@ public function handleStart(SubscriptionsConnection $conn, array $data): void
* @param string $query
* @param mixed $payload
* @param array|null $variables
*
* @return array
*/
private function execute(string $query, $payload = null, ?array $variables = null): array
{
return GraphQL::executeQuery($this->schema, $query, $payload, $this->context, $variables)->toArray(debugging());
}

/**
* @param DocumentNode $document
* @return string
*/
/**
* @param DocumentNode $document
* @return string
*/
/**
* @param DocumentNode $document
* @return string
*/
/**
* @param DocumentNode $document
* @return string
*/
/**
* @param DocumentNode $document
* @return string
*/
/**
* @param DocumentNode $document
* @return string
*/
/**
* @param DocumentNode $document
* @return string
*/
/**
* @param DocumentNode $document
* @return string
*/
/**
* @param DocumentNode $document
* @return string
*/
/**
* @param DocumentNode $document
* @return string
Expand Down Expand Up @@ -331,7 +294,7 @@ public function handleStop(SubscriptionsConnection $conn, array $data)
/** @var array<string, mixed> $conn_subs */
$conn_subs = $this->connStorage[$conn->key()];
/** @var array|null $subscription */
$subscription = array_get($conn_subs, strval($data['id']));
$subscription = array_get($conn_subs, (string)$data['id']);

if (!is_null($subscription)) {
/** @var string subscription_name */
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function session(?string $key = null, ?string $default = null)
*/
function setsession(string $key, $value): void
{
$_SESSION[$key] = strval($value);
$_SESSION[$key] = (string)$value;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
function raw(string $input = 'php://input'): string
{
if (Container\has(SWOOLE_HTTP_REQUEST)) {
return strval(\Siler\Swoole\request()->rawContent());
return (string)\Siler\Swoole\request()->rawContent();
}

$contents = file_get_contents($input);
Expand Down Expand Up @@ -148,7 +148,7 @@ function (array $headers, string $key): array {
);

$values = array_map(function (string $header): string {
return strval($_SERVER[$header]);
return (string)$_SERVER[$header];
}, $http_headers);

$headers = array_map(function (string $header) {
Expand Down Expand Up @@ -329,7 +329,7 @@ function accepted_locales(): array
// break up string into pieces (languages and q factors)
preg_match_all(
'/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i',
strval($_SERVER['HTTP_ACCEPT_LANGUAGE']),
(string)$_SERVER['HTTP_ACCEPT_LANGUAGE'],
$lang_parse
);

Expand Down Expand Up @@ -377,12 +377,12 @@ function accepted_locales(): array
*/
function recommended_locale(string $default = ''): string
{
/** @var array<string, string> $_GET */
$locale = strval(array_get($_GET, 'lang', ''));
/** @psalm-var array<string, string> $_GET */
$locale = array_get_str($_GET, 'lang', '');

if (empty($locale)) {
/** @var array<string, string> $_SESSION */
$locale = strval(array_get($_SESSION, 'lang', ''));
/** @psalm-var array<string, string> $_SESSION */
$locale = array_get_str($_SESSION, 'lang', '');
}

if (empty($locale)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Prelude/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ public function sameAs(Enum $other): bool
*/
public function __toString(): string
{
return strval($this->value);
return (string)$this->value;
}
}
3 changes: 2 additions & 1 deletion src/Siler.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function array_get(?array $array, $key = null, $default = null, bool $caseInsens
*/
function array_get_str(array $array, string $key, ?string $default = null): string
{
/** @var mixed|null $value */
$value = array_get($array, $key);

if ($value === null && $default === null) {
Expand All @@ -65,7 +66,7 @@ function array_get_str(array $array, string $key, ?string $default = null): stri
return $default;
}

return strval($value);
return (string)$value;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Swoole/Swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function raw(): ?string
return null;
}

return strval($content);
return (string)$content;
}

/**
Expand Down Expand Up @@ -375,9 +375,9 @@ static function (array $message, int $fd) use ($manager): void {
* @psalm-suppress MissingPropertyType
* @var array<string, string> $message
*/
$message = Json\decode(strval($frame->data));
$message = Json\decode((string)$frame->data);
/** @psalm-suppress MissingPropertyType */
$handle($message, intval($frame->fd));
$handle($message, (int)$frame->fd);

if ($message['type'] === GQL_DATA) {
/** @var array{id: int} $worker */
Expand Down

0 comments on commit 855c688

Please sign in to comment.