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

Commit

Permalink
chore: php 8 readiness, psalm and ea fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
leocavalcante committed Dec 29, 2020
1 parent 277e2c8 commit 58b0b2b
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 127 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"generate-facades": "php bin/generate-facades.php",
"fix": "phpcbf",
"lint": "phpcs",
"analyze": "psalm --shepherd",
"analyze": "psalm --shepherd --no-cache",
"test": "phpunit",
"ci": [
"@composer lint",
Expand Down
62 changes: 31 additions & 31 deletions composer.lock

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

59 changes: 30 additions & 29 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php" colors="true" verbose="true">
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>

<testsuite name="Integration">
<directory>tests/Integration</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
<exclude>
<directory>src/Grpc</directory>
<directory>src/Swoole</directory>
<file>src/facades.php</file>
</exclude>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="coverage-clover.xml"/>
<log type="coverage-html" target="coverage-html"/>
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
</logging>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
>
<coverage>
<include>
<directory>src</directory>
</include>
<exclude>
<directory>src/Grpc</directory>
<directory>src/Swoole</directory>
<file>src/facades.php</file>
</exclude>
<report>
<clover outputFile="coverage-clover.xml"/>
<html outputDirectory="coverage-html"/>
<text outputFile="php://stdout" showUncoveredFiles="true"/>
</report>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Integration">
<directory>tests/Integration</directory>
</testsuite>
</testsuites>
<logging/>
</phpunit>
8 changes: 4 additions & 4 deletions src/Dotenv/Dotenv.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function init(string $path): array
*
* @param string|null $key
* @param string|null $default A default when the key do not exists
* @return string|null|array<string, string>
* @return string|null|array<string, string|null>
*/
function env(?string $key = null, ?string $default = null)
{
Expand All @@ -50,7 +50,7 @@ function int_val(string $key, ?int $default = null): ?int
}

if (is_numeric($val)) {
return intval($val);
return (int) $val;
}

return $default;
Expand Down Expand Up @@ -83,7 +83,7 @@ function bool_val(string $key, ?bool $default = null): ?bool
return false;
}

return boolval($val);
return (bool) $val;
}

/**
Expand All @@ -94,7 +94,7 @@ function bool_val(string $key, ?bool $default = null): ?bool
*/
function requires(string $key): bool
{
if (array_key_exists($key, $_ENV)) {
if (\array_key_exists($key, $_ENV)) {
return true;
}

Expand Down
11 changes: 5 additions & 6 deletions src/Env/Env.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Siler\Env;

use UnexpectedValueException;
use function Siler\Functional\bool;

/**
* Gets a variable from the environment.
Expand Down Expand Up @@ -39,7 +38,7 @@ function env_var(string $key, ?string $default = null): string
*/
function env_int(string $key, ?int $default = null): int
{
return intval(env_var($key, $default === null ? $default : strval($default)));
return (int) env_var($key, $default === null ? $default : (string) $default);
}

/**
Expand All @@ -52,13 +51,13 @@ function env_int(string $key, ?int $default = null): int
*/
function env_bool(string $key, ?bool $default = null): bool
{
$value = env_var($key, $default === null ? $default : strval($default));
$value = env_var($key, $default === null ? $default : (string) $default);

if (in_array($value, ['false', '0', '{}', '[]', 'null', 'undefined'])) {
if (\in_array($value, ['false', '0', '{}', '[]', 'null', 'undefined'])) {
return false;
}

return boolval($value);
return (bool) $value;
}

/**
Expand All @@ -69,5 +68,5 @@ function env_bool(string $key, ?bool $default = null): bool
*/
function env_has(string $key): bool
{
return array_key_exists($key, $_ENV);
return \array_key_exists($key, $_ENV);
}
11 changes: 5 additions & 6 deletions src/GraphQL/DateScalar.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php declare(strict_types=1);


namespace Siler\GraphQL;

use DateTime;
Expand All @@ -25,7 +24,7 @@ class DateScalar extends ScalarType
public function serialize($value): string
{
if ($value instanceof DateTime) {
return $value->format((string)static::FORMAT);
return $value->format((string) static::FORMAT);
}

throw new Error('Don\'t know how to serialize non-DateTime');
Expand All @@ -37,13 +36,13 @@ public function serialize($value): string
* @return mixed
* @throws Error
*/
public function parseLiteral($valueNode, ?array $variables = null)
public function parseLiteral(Node $valueNode, ?array $variables = null)
{
if ($valueNode instanceof StringValueNode) {
return $this->parseValue($valueNode->value);
}

throw new Error(sprintf('Unable to parse non string literal as %', $this->name));
throw new Error(sprintf('Unable to parse non string literal as %s', $this->name));
}

/**
Expand All @@ -55,8 +54,8 @@ public function parseValue($value)
{
$date_time = false;

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

if ($date_time === false) {
Expand Down
Loading

0 comments on commit 58b0b2b

Please sign in to comment.