Skip to content

Commit

Permalink
v3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fenric committed Oct 30, 2024
1 parent 9914570 commit 76c8c41
Show file tree
Hide file tree
Showing 51 changed files with 535 additions and 1,470 deletions.
10 changes: 8 additions & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@ build:
nodes:
analysis:
environment:
php: 8.2
php: 8.3
tests:
override:
- php-scrutinizer-run
coverage:
environment:
php: 8.2
php: 8.3
tests:
override:
- command: XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-clover coverage.xml
coverage:
file: coverage.xml
format: clover
php82:
environment:
php: 8.2
tests:
override:
- command: php vendor/bin/phpunit
php81:
environment:
php: 8.1
Expand Down
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
"psr/http-message": "^1.0"
},
"require-dev": {
"sunrise/coding-standard": "~1.0.0",
"phpunit/phpunit": "~9.5.0",
"php-http/psr7-integration-tests": "^1.1"
"php-http/psr7-integration-tests": "^1.4",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^9.6",
"sunrise/coding-standard": "^1.0",
"vimeo/psalm": "^5.26"
},
"autoload": {
"files": [
Expand All @@ -59,9 +61,9 @@
},
"scripts": {
"test": [
"phpcs",
"phpcs --colors",
"psalm --no-cache",
"phpstan analyse src --level=9",
"phpstan analyse src --level=9 --memory-limit=-1",
"XDEBUG_MODE=coverage phpunit --coverage-text --colors=always"
],
"build": [
Expand All @@ -76,5 +78,8 @@
"sunrise/http-server-request": "*",
"sunrise/stream": "*",
"sunrise/uri": "*"
},
"config": {
"sort-packages": true
}
}
31 changes: 5 additions & 26 deletions functions/server_request_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,14 @@

namespace Sunrise\Http\Message;

/**
* Import classes
*/
use Sunrise\Http\Message\Stream\FileStream;

/**
* Import functions
*/
use function is_array;

/**
* Import constants
*/
use const UPLOAD_ERR_OK;
use const UPLOAD_ERR_NO_FILE;

/**
* Gets the request's uploaded files
*
* Please note that unsent files will not be handled,
* also note that if a file fails to upload successfully,
* a stream will not be created for it.
*
* @param array|null $files
*
* @return array
*
* @link http://php.net/manual/en/reserved.variables.files.php
* @link https://www.php.net/manual/ru/features.file-upload.post-method.php
* @link https://www.php.net/manual/ru/features.file-upload.multiple.php
Expand All @@ -49,22 +30,20 @@ function server_request_files(?array $files = null): array

$walker = static function ($path, $size, $error, $name, $type) use (&$walker) {
if (!is_array($path)) {
// It makes no sense to create a stream
// if the file has not been successfully uploaded.
$stream = UPLOAD_ERR_OK <> $error ? null : new FileStream($path, 'rb');
$stream = $error === UPLOAD_ERR_OK ? new FileStream($path, 'rb') : null;

return new UploadedFile($stream, $size, $error, $name, $type);
}

$result = [];
foreach ($path as $key => $_) {
if (UPLOAD_ERR_NO_FILE <> $error[$key]) {
if ($error[$key] !== UPLOAD_ERR_NO_FILE) {
$result[$key] = $walker(
$path[$key],
$size[$key],
$error[$key],
$name[$key],
$type[$key]
$type[$key],
);
}
}
Expand All @@ -74,13 +53,13 @@ function server_request_files(?array $files = null): array

$result = [];
foreach ($files as $key => $file) {
if (UPLOAD_ERR_NO_FILE <> $file['error']) {
if ($file['error'] !== UPLOAD_ERR_NO_FILE) {
$result[$key] = $walker(
$file['tmp_name'],
$file['size'],
$file['error'],
$file['name'],
$file['type']
$file['type'],
);
}
}
Expand Down
9 changes: 1 addition & 8 deletions functions/server_request_headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,13 @@

namespace Sunrise\Http\Message;

/**
* Import functions
*/
use function strncmp;
use function strtolower;
use function strtr;
use function substr;
use function ucwords;

/**
* Gets the request headers
*
* @param array|null $serverParams
*
* @return array<string, string>
*
* @link http://php.net/manual/en/reserved.variables.server.php
Expand All @@ -46,7 +39,7 @@ function server_request_headers(?array $serverParams = null): array

$result = [];
foreach ($serverParams as $key => $value) {
if (0 <> strncmp('HTTP_', $key, 5)) {
if (strncmp('HTTP_', $key, 5) !== 0) {
continue;
}

Expand Down
14 changes: 1 addition & 13 deletions functions/server_request_method.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,11 @@
namespace Sunrise\Http\Message;

/**
* Import classes
*/
use Fig\Http\Message\RequestMethodInterface;

/**
* Gets the request method
*
* @param array|null $serverParams
*
* @return string
*
* @link http://php.net/manual/en/reserved.variables.server.php
* @link https://datatracker.ietf.org/doc/html/rfc3875#section-4.1.12
*/
function server_request_method(?array $serverParams = null): string
{
$serverParams ??= $_SERVER;

return $serverParams['REQUEST_METHOD'] ?? RequestMethodInterface::METHOD_GET;
return $serverParams['REQUEST_METHOD'] ?? 'GET';
}
10 changes: 0 additions & 10 deletions functions/server_request_protocol_version.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,10 @@

namespace Sunrise\Http\Message;

/**
* Import functions
*/
use function sprintf;
use function sscanf;

/**
* Gets the request's protocol version
*
* @param array|null $serverParams
*
* @return string
*
* @link http://php.net/manual/en/reserved.variables.server.php
* @link https://datatracker.ietf.org/doc/html/rfc3875#section-4.1.16
*/
function server_request_protocol_version(?array $serverParams = null): string
Expand Down
17 changes: 1 addition & 16 deletions functions/server_request_uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,16 @@

namespace Sunrise\Http\Message;

/**
* Import classes
*/
use Psr\Http\Message\UriInterface;

/**
* Import functions
*/
use function array_key_exists;

/**
* Gets the request URI
*
* @param array|null $serverParams
*
* @return UriInterface
*
* @link http://php.net/manual/en/reserved.variables.server.php
*/
function server_request_uri(?array $serverParams = null): UriInterface
{
$serverParams ??= $_SERVER;

if (array_key_exists('HTTPS', $serverParams)) {
if (! ('off' === $serverParams['HTTPS'])) {
if ('off' !== $serverParams['HTTPS']) {
$scheme = 'https://';
}
}
Expand Down
1 change: 1 addition & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
phpVersion="7.4"
>
<projectFiles>
<directory name="src" />
Expand Down
6 changes: 0 additions & 6 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,8 @@

namespace Sunrise\Http\Message\Exception;

/**
* Import classes
*/
use Throwable;

/**
* ExceptionInterface
*/
interface ExceptionInterface extends Throwable
{
}
10 changes: 1 addition & 9 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@

namespace Sunrise\Http\Message\Exception;

/**
* Import classes
*/
use InvalidArgumentException as BaseInvalidArgumentException;

/**
* InvalidArgumentException
*/
class InvalidArgumentException extends BaseInvalidArgumentException implements ExceptionInterface
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
10 changes: 1 addition & 9 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@

namespace Sunrise\Http\Message\Exception;

/**
* Import classes
*/
use RuntimeException as BaseRuntimeException;

/**
* RuntimeException
*/
class RuntimeException extends BaseRuntimeException implements ExceptionInterface
class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}
39 changes: 0 additions & 39 deletions src/HeaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,24 @@

namespace Sunrise\Http\Message;

/**
* Import classes
*/
use IteratorAggregate;

/**
* @extends IteratorAggregate<int, string>
*/
interface HeaderInterface extends IteratorAggregate
{

/**
* Date format according to RFC-822
*
* @var string
*/
public const RFC822_DATE_FORMAT = 'D, d M y H:i:s O';

/**
* Regular Expression used for a token validation according to RFC-7230
*
* @var string
*/
public const RFC7230_TOKEN_REGEX = '/^[\x21\x23-\x27\x2A\x2B\x2D\x2E\x30-\x39\x41-\x5A\x5E-\x7A\x7C\x7E]+$/';

/**
* Regular Expression used for a field-value validation according to RFC-7230
*
* @var string
*/
public const RFC7230_FIELD_VALUE_REGEX = '/^[\x09\x20-\x7E\x80-\xFF]*$/';

/**
* Regular Expression used for a quoted-string validation according to RFC-7230
*
* @var string
*/
public const RFC7230_QUOTED_STRING_REGEX = '/^(?:[\x5C][\x22]|[\x09\x20\x21\x23-\x5B\x5D-\x7E\x80-\xFF])*$/';

/**
* Gets the header field name
*
* @return string
*/
public function getFieldName(): string;

/**
* Gets the header field value
*
* @return string
*/
public function getFieldValue(): string;

/**
* Converts the header to a field
*
* @return string
*/
public function __toString(): string;
}
Loading

0 comments on commit 76c8c41

Please sign in to comment.