Skip to content

Upgrade PHP to 8.x #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: php
php:
- 7.0
- 7.1
- 7.2
- 8.0
- 8.1
- 8.2
install:
- pecl install swoole-1.10.3
- pecl install swoole-4.8.13
- composer update
script:
- vendor/bin/phpunit
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
}
],
"require": {
"php": ">=5.6.0",
"php": ">=7.4",
"nikic/fast-route": "1.2.*",
"monolog/monolog": "~1.0",
"monolog/monolog": "^1.27",
"psr/http-message": "^1.0",
"symfony/console": "^3.0 || ^4.0",
"psy/psysh": "^0.7.2 || ^0.8.0 || ^0.9.0",
"symfony/dotenv": "^3.3 || ^4.0"
"symfony/console": "^5.4",
"psy/psysh": "^0.11",
"symfony/dotenv": "^5.4"
},
"require-dev": {
"phpunit/phpunit": "~6.0"
"phpunit/phpunit": "^9.6"
},
"suggest": {
"ext-swoole": "Run blink application under Swoole with visible performance improvements"
Expand Down
15 changes: 8 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
Expand All @@ -8,17 +9,17 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">app/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">app/</directory>
</whitelist>
</filter>
<php>
</php>
</phpunit>
22 changes: 18 additions & 4 deletions src/core/ServiceLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace blink\core;

use blink\di\Container;
use ReflectionClass;
use ReflectionNamedType;
use ReflectionParameter;

/**
* Class ServiceLocator
Expand Down Expand Up @@ -57,17 +60,28 @@ public function get($id)
/**
* Call the given callback or class method with dependency injection.
*
* @param $callback
* @param callable $callback
* @param array $arguments
* @return mixed
*/
public function call($callback, $arguments = [])
public function call(callable $callback, array $arguments = [])
{
$dependencies = $this->getMethodDependencies($callback, $arguments);
$dependencies = $this->getMethodDependencies($callback, array_values($arguments));

return call_user_func_array($callback, $dependencies);
}

protected function getParameterClass(ReflectionParameter $parameter): ?ReflectionClass
{
$type = $parameter->getType();

if ($type instanceof ReflectionNamedType) {
return new ReflectionClass($type->getName());
} else {
return null;
}
}

protected function getMethodDependencies($callback, array $arguments = [])
{
$dependencies = $arguments;
Expand All @@ -76,7 +90,7 @@ protected function getMethodDependencies($callback, array $arguments = [])
foreach ($parameters as $key => $parameter) {
if ($parameter->isDefaultValueAvailable()) {
$dependencies[] = $parameter->getDefaultValue();
} elseif ($class = $parameter->getClass()) {
} elseif ($class = $this->getParameterClass($parameter)) {
$dependencies[] = $this->get($class->getName());
} else {
throw new InvalidParamException('Missing required argument: ' . $parameter->getName());
Expand Down
5 changes: 3 additions & 2 deletions src/di/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use ReflectionClass;
use blink\core\BaseObject;
use blink\core\InvalidConfigException;
use ReflectionNamedType;

/**
* Container implements a [dependency injection](http://en.wikipedia.org/wiki/Dependency_injection) container.
Expand Down Expand Up @@ -482,8 +483,8 @@ protected function getDependencies($class)
if ($param->isDefaultValueAvailable()) {
$dependencies[] = $param->getDefaultValue();
} else {
$c = $param->getClass();
$dependencies[] = Instance::of($c === null ? null : $c->getName());
$c = $param->getType();
$dependencies[] = Instance::of($c instanceof ReflectionNamedType ? $c->getName() : null);
}
}
}
Expand Down
23 changes: 12 additions & 11 deletions src/http/CookieBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use ArrayIterator;
use IteratorAggregate;
use blink\core\BaseObject;
use Traversable;

/**
* Class CookieBag
Expand All @@ -28,12 +29,12 @@ public function __construct(array $cookies = [], $config = [])
parent::__construct($config);
}

public function replace(array $cookies)
public function replace(array $cookies): void
{
$this->cookies = self::normalize($cookies);
}

public static function normalize(array $cookies)
public static function normalize(array $cookies): array
{
foreach ($cookies as $name => $value) {
if (!$value instanceof Cookie) {
Expand All @@ -50,15 +51,15 @@ public static function normalize(array $cookies)
* @return Cookie[]
* @since 0.3.0
*/
public function all()
public function all(): array
{
return $this->cookies;
}

/**
* Returns a cookie by name.
*
* @param $name
* @param string $name
* @return Cookie|null
*/
public function get($name)
Expand All @@ -71,38 +72,38 @@ public function get($name)
*
* @param Cookie $cookie
*/
public function add(Cookie $cookie)
public function add(Cookie $cookie): void
{
$this->cookies[$cookie->name] = $cookie;
}

/**
* Returns whether a cookie is exists.
*
* @param $name
* @param string $name
* @return bool
*/
public function has($name)
public function has(string $name): bool
{
return isset($this->cookies[$name]);
}

/**
* Remove a cookie by name.
*
* @param $name
* @param string $name
*/
public function remove($name)
public function remove(string $name)
{
unset($this->cookies[$name]);
}

public function count()
public function count(): int
{
return count($this->cookies);
}

public function getIterator()
public function getIterator(): Traversable
{
return new ArrayIterator($this->cookies);
}
Expand Down
5 changes: 3 additions & 2 deletions src/http/FileBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use ArrayIterator;
use blink\core\BaseObject;
use IteratorAggregate;
use Traversable;

/**
* FileBag represents a set of uploaded files.
Expand Down Expand Up @@ -90,12 +91,12 @@ public function first($name)
}
}

public function count()
public function count(): int
{
return count($this->files);
}

public function getIterator()
public function getIterator(): Traversable
{
return new ArrayIterator($this->files);
}
Expand Down
1 change: 1 addition & 0 deletions src/http/HeaderBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function first($key, $default = null)
return !empty($values) ? array_shift($values) : $default;
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
{
return $this->all();
Expand Down
2 changes: 2 additions & 0 deletions src/http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ private function parseBody($body)
$parsedBody = $this->parseQueryString($body);
} elseif ($contentType === 'multipart/form-data') {
// noop
} elseif ($contentType === 'application/xml' || $contentType === 'text/xml') {
$parsedBody = (array)simplexml_load_string($body, null, LIBXML_NOCDATA);
} else {
throw new NotSupportedException("The content type: '$contentType' does not supported");
}
Expand Down
18 changes: 11 additions & 7 deletions src/support/BagTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace blink\support;

use ArrayIterator;
use Traversable;

trait BagTrait
{
Expand Down Expand Up @@ -88,27 +89,29 @@ public function remove($key)
unset($this->data[$this->transformKey($key)]);
}

public function count()
public function count(): int
{
return count($this->data);
}

public function getIterator()
public function getIterator(): Traversable
{
return new ArrayIterator($this->data);
}

/**
* @inheritDoc
*/
public function offsetExists($offset)
#[\ReturnTypeWillChange]
public function offsetExists($offset): bool
{
return $this->has($offset);
}

/**
* @inheritDoc
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->get($offset);
Expand All @@ -117,16 +120,17 @@ public function offsetGet($offset)
/**
* @inheritDoc
*/
public function offsetSet($offset, $value)
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value): void
{
return $this->set($offset, $value);
$this->set($offset, $value);
}

/**
* @inheritDoc
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
return $this->remove($offset);
$this->remove($offset);
}
}
4 changes: 2 additions & 2 deletions src/testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class TestCase extends BaseTestCase

abstract public function createApplication();

public function setUp()
public function setUp(): void
{
if (!$this->app) {
$this->app = $this->createApplication()->bootstrapIfNeeded();
Expand All @@ -33,7 +33,7 @@ public function actor()
return new RequestActor($this, $this->createApplication()->bootstrapIfNeeded());
}

public function tearDown()
public function tearDown(): void
{
if ($this->app) {
$this->app->shutdown();
Expand Down
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?php

ini_set('log_errors', 1);

$loader = require __DIR__ . '/../vendor/autoload.php';
12 changes: 6 additions & 6 deletions tests/log/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class LoggerTest extends TestCase
{
protected $logFile;

public function setUp()
public function setUp(): void
{
parent::setUp();

$this->logFile = __DIR__ . '/test.log';
}

public function tearDown()
public function tearDown(): void
{
if (file_exists($this->logFile)) {
unlink($this->logFile);
Expand All @@ -47,7 +47,7 @@ protected function createLogger($logFile)
]);
}

public function testLogBasic()
public function testLogBasic(): void
{
$log = $this->createLogger($this->logFile);

Expand All @@ -58,11 +58,11 @@ public function testLogBasic()

$content = file_get_contents($this->logFile);

$this->assertContains('alert message', $content);
$this->assertNotContains('info message', $content);
$this->assertStringContainsString('alert message', $content);
$this->assertStringNotContainsString('info message', $content);
}

public function testLogException()
public function testLogException(): void
{
$log = $this->createLogger($this->logFile);

Expand Down
Loading