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
34 changes: 18 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,51 @@
name: Tests

on: [push, pull_request]
on:
push:
branches: [3.x]
pull_request:

jobs:
tests:
name: Tests PHP ${{ matrix.php }}
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
php: [7.3, 7.4, 8.0]
experimental: [false]
php: ['8.1', '8.2', '8.3', '8.4', '8.5']
include:
- php: 8.0
analysis: true
- php: 8.1
experimental: true
- php: '8.5'
coverage: 'xdebug'

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
coverage: ${{ matrix.coverage || 'none' }}

- name: Install dependencies with Composer
uses: ramsey/composer-install@v1
uses: ramsey/composer-install@v3

- name: Coding standards
if: matrix.analysis
run: vendor/bin/phpcs

- name: Static analysis
if: matrix.analysis
run: vendor/bin/phpstan
run: vendor/bin/phpstan analyse --memory-limit=512M

- name: Tests
if: ${{ !matrix.coverage }}
run: vendor/bin/phpunit

- name: Tests with coverage
if: ${{ matrix.coverage }}
run: vendor/bin/phpunit --coverage-clover clover.xml

- name: Upload coverage results to Coveralls
if: matrix.analysis
if: ${{ matrix.coverage }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ coverage
vendor
.DS_Store
.idea
.phpunit.result.cache
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ It's recommended that you use [Composer](https://getcomposer.org/) to install Sl
$ composer require slim/slim "^3.0"
```

This will install Slim and all required dependencies. Slim requires PHP 5.5.0 or newer.
This will install Slim and all required dependencies.

## Version compatibility

- Slim version 3.13.0 requires PHP 8.1 or newer.
- Slim version 3.12.x and below requires PHP 5.5 – PHP 8.1.

## Usage

Expand Down
4 changes: 2 additions & 2 deletions Slim/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public function subRequest(
array $headers = [],
array $cookies = [],
$bodyContent = '',
ResponseInterface $response = null
?ResponseInterface $response = null
) {
$env = $this->container->get('environment');
$uri = Uri::createFromEnvironment($env)->withPath($path)->withQuery($query);
Expand Down Expand Up @@ -663,7 +663,7 @@ protected function isEmptyResponse(ResponseInterface $response)
*/
protected function isHeadRequest(RequestInterface $request)
{
return strtoupper($request->getMethod()) === 'HEAD';
return strtoupper((string)$request->getMethod()) === 'HEAD';
}

/**
Expand Down
8 changes: 8 additions & 0 deletions Slim/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* This class provides a common interface used by many other
* classes in a Slim application that manage "collections"
* of data that must be inspected and/or manipulated
*
* @phpstan-consistent-constructor
*/
class Collection implements CollectionInterface
{
Expand Down Expand Up @@ -109,6 +111,7 @@ public function clear()
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($key)
{
return $this->has($key);
Expand All @@ -121,6 +124,7 @@ public function offsetExists($key)
*
* @return mixed The key's value, or the default value
*/
#[\ReturnTypeWillChange]
public function offsetGet($key)
{
return $this->get($key);
Expand All @@ -132,6 +136,7 @@ public function offsetGet($key)
* @param string $key The data key
* @param mixed $value The data value
*/
#[\ReturnTypeWillChange]
public function offsetSet($key, $value)
{
$this->set($key, $value);
Expand All @@ -142,6 +147,7 @@ public function offsetSet($key, $value)
*
* @param string $key The data key
*/
#[\ReturnTypeWillChange]
public function offsetUnset($key)
{
$this->remove($key);
Expand All @@ -152,6 +158,7 @@ public function offsetUnset($key)
*
* @return int
*/
#[\ReturnTypeWillChange]
public function count()
{
return count($this->data);
Expand All @@ -162,6 +169,7 @@ public function count()
*
* @return ArrayIterator
*/
#[\ReturnTypeWillChange]
public function getIterator()
{
return new ArrayIterator($this->data);
Expand Down
2 changes: 1 addition & 1 deletion Slim/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function get($id)
if ($this->exceptionThrownByContainer($exception)) {
throw new SlimContainerException(
sprintf('Container error while retrieving "%s"', $id),
null,
0,
$exception
);
} else {
Expand Down
2 changes: 1 addition & 1 deletion Slim/DeferredCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DeferredCallable
* @param callable|string $callable
* @param ContainerInterface $container
*/
public function __construct($callable, ContainerInterface $container = null)
public function __construct($callable, ?ContainerInterface $container = null)
{
$this->callable = $callable;
$this->container = $container;
Expand Down
2 changes: 1 addition & 1 deletion Slim/Handlers/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ abstract class AbstractHandler
*/
protected function determineContentType(ServerRequestInterface $request)
{
$acceptHeader = $request->getHeaderLine('Accept');
$acceptHeader = (string)$request->getHeaderLine('Accept');
$selectedContentTypes = array_intersect(explode(',', $acceptHeader), $this->knownContentTypes);

if (count($selectedContentTypes)) {
Expand Down
8 changes: 5 additions & 3 deletions Slim/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
* @link https://github.com/php-fig/http-message/blob/master/src/MessageInterface.php
* @link https://github.com/php-fig/http-message/blob/master/src/RequestInterface.php
* @link https://github.com/php-fig/http-message/blob/master/src/ServerRequestInterface.php
*
* @phpstan-consistent-constructor
*/
class Request extends Message implements ServerRequestInterface
{
Expand Down Expand Up @@ -490,7 +492,7 @@ public function getRequestTarget()
} else {
$basePath = '';
}
$path = $this->uri->getPath();
$path = (string)$this->uri->getPath();
$path = $basePath . '/' . ltrim($path, '/');

$query = $this->uri->getQuery();
Expand Down Expand Up @@ -1011,7 +1013,7 @@ public function getParsedBody()
return null;
}

$mediaType = $this->getMediaType();
$mediaType = (string)$this->getMediaType();

// Check if this specific media type has a parser registered first
if (!isset($this->bodyParsers[$mediaType])) {
Expand Down Expand Up @@ -1188,7 +1190,7 @@ public function getQueryParam($key, $default = null)
*
* @return mixed[]
*/
public function getParams(array $only = null)
public function getParams(?array $only = null)
{
$params = $this->getQueryParams();
$postParams = $this->getParsedBody();
Expand Down
6 changes: 3 additions & 3 deletions Slim/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ class Response extends Message implements ResponseInterface
*/
public function __construct(
$status = StatusCode::HTTP_OK,
HeadersInterface $headers = null,
StreamInterface $body = null
?HeadersInterface $headers = null,
?StreamInterface $body = null
) {
$this->status = $this->filterStatus($status);
$this->headers = $headers ? $headers : new Headers();
Expand Down Expand Up @@ -190,7 +190,7 @@ public function withStatus($code, $reasonPhrase = '')
{
$code = $this->filterStatus($code);

if (!is_string($reasonPhrase) && !method_exists($reasonPhrase, '__toString')) {
if (!is_string($reasonPhrase) && !$reasonPhrase instanceof \Stringable) {
throw new InvalidArgumentException('ReasonPhrase must be a string');
}

Expand Down
2 changes: 2 additions & 0 deletions Slim/Http/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*
* @link https://github.com/php-fig/http-message/blob/master/src/UploadedFileInterface.php
* @link https://github.com/php-fig/http-message/blob/master/src/StreamInterface.php
*
* @phpstan-consistent-constructor
*/
class UploadedFile implements UploadedFileInterface
{
Expand Down
16 changes: 9 additions & 7 deletions Slim/Http/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* server parameters.
*
* @link http://tools.ietf.org/html/rfc3986 (the URI specification)
*
* @phpstan-consistent-constructor
*/
class Uri implements UriInterface
{
Expand Down Expand Up @@ -134,7 +136,7 @@ public function __construct(
*/
public static function createFromString($uri)
{
if (!is_string($uri) && !method_exists($uri, '__toString')) {
if (!is_string($uri) && !$uri instanceof \Stringable) {
throw new InvalidArgumentException('Uri must be a string');
}

Expand Down Expand Up @@ -170,11 +172,11 @@ public static function createFromEnvironment(Environment $env)

// Authority: Host and Port
if ($env->has('HTTP_HOST')) {
$host = $env->get('HTTP_HOST');
$host = (string)$env->get('HTTP_HOST');
// set a port default
$port = null;
} else {
$host = $env->get('SERVER_NAME');
$host = (string)$env->get('SERVER_NAME');
// set a port default
$port = (int)$env->get('SERVER_PORT', 80);
}
Expand Down Expand Up @@ -294,7 +296,7 @@ protected function filterScheme($scheme)
'http' => true,
];

if (!is_string($scheme) && !method_exists($scheme, '__toString')) {
if (!is_string($scheme) && !$scheme instanceof \Stringable) {
throw new InvalidArgumentException('Uri scheme must be a string');
}

Expand Down Expand Up @@ -694,7 +696,7 @@ public function getQuery()
*/
public function withQuery($query)
{
if (!is_string($query) && !method_exists($query, '__toString')) {
if (!is_string($query) && !$query instanceof \Stringable) {
throw new InvalidArgumentException('Uri query must be a string');
}
$query = ltrim((string)$query, '?');
Expand All @@ -718,7 +720,7 @@ protected function filterQuery($query)
function ($match) {
return rawurlencode($match[0]);
},
$query
(string)$query
);
}

Expand Down Expand Up @@ -761,7 +763,7 @@ public function getFragment()
*/
public function withFragment($fragment)
{
if (!is_string($fragment) && !method_exists($fragment, '__toString')) {
if (!is_string($fragment) && !$fragment instanceof \Stringable) {
throw new InvalidArgumentException('Uri fragment must be a string');
}
$fragment = ltrim((string)$fragment, '#');
Expand Down
2 changes: 1 addition & 1 deletion Slim/MiddlewareAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function addMiddleware(callable $callable)
*
* @throws RuntimeException if the stack is seeded more than once
*/
protected function seedMiddlewareStack(callable $kernel = null)
protected function seedMiddlewareStack(?callable $kernel = null)
{
if (!is_null($this->tip)) {
throw new RuntimeException('MiddlewareStack can only be seeded once.');
Expand Down
2 changes: 1 addition & 1 deletion Slim/RouteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RouteGroup extends Routable implements RouteGroupInterface
/**
* {@inheritdoc}
*/
public function __invoke(App $app = null)
public function __invoke(?App $app = null)
{
$callable = $this->resolveCallable($this->callable);
if ($callable instanceof Closure && $app !== null) {
Expand Down
2 changes: 1 addition & 1 deletion Slim/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Router implements RouterInterface
/**
* @param RouteParser $parser
*/
public function __construct(RouteParser $parser = null)
public function __construct(?RouteParser $parser = null)
{
$this->routeParser = $parser ?: new StdParser;
}
Expand Down
Loading
Loading