Skip to content

Commit

Permalink
Merge pull request #13 from php-middleware/psr-15
Browse files Browse the repository at this point in the history
Full psr-15 support, php 7.1 as minimum
  • Loading branch information
snapshotpl authored Jun 19, 2019
2 parents 3936e46 + 0c1dbf1 commit f466aed
Show file tree
Hide file tree
Showing 23 changed files with 71 additions and 259 deletions.
6 changes: 3 additions & 3 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ checks:
build:
environment:
php:
version: 5.6.16
version: 7.3
tests:
override:
-
command: 'phpunit'
command: 'vendor/bin/phpunit --coverage-clover=phpunit-coverage-clover'
coverage:
file: 'tmp/phpunit-coverage-clover.xml'
file: 'phpunit-coverage-clover'
format: 'php-clover'
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3

env:
- DEPS=lowest
- DEPS=latest

before_script:
- phpenv config-rm xdebug.ini
- composer self-update
- if [[ $DEPS == 'lowest' ]]; then composer update --prefer-stable --no-interaction --prefer-lowest ; fi
- if [[ $DEPS == 'latest' ]]; then composer update --prefer-stable --no-interaction ; fi

Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ This middleware provide framework-agnostic possibility to generate and add to re

## Installation

```json
{
"require": {
"php-middleware/request-id": "^3.0.0"
}
}
```bash
composer require php-middleware/request-id
```

## Usage
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
"request-id"
],
"require": {
"php": "^5.6 || ^7.0",
"php": "^7.1",
"psr/http-message": "^1.0",
"php-middleware/double-pass-compatibility": "^1.0",
"http-interop/http-middleware": "^0.4.1"
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6.1.3",
"ramsey/uuid": "^3.0",
"zendframework/zend-diactoros": "^1.1.3"
"zendframework/zend-diactoros": "^2.0",
"phpunit/phpunit": "^7.5.13"
},
"suggest": {
"ramsey/uuid": "To use Ramsey\\Uuid 3.0 generator"
Expand Down
5 changes: 1 addition & 4 deletions src/Generator/GeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@

interface GeneratorInterface
{
/**
* @return string unique value
*/
public function generateRequestId();
public function generateRequestId(): string;
}
2 changes: 1 addition & 1 deletion src/Generator/Md5Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function __construct(GeneratorInterface $generator)
$this->generator = $generator;
}

public function generateRequestId()
public function generateRequestId(): string
{
return md5($this->generator->generateRequestId());
}
Expand Down
21 changes: 4 additions & 17 deletions src/Generator/PhpUniqidGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,19 @@

final class PhpUniqidGenerator implements GeneratorInterface
{
/**
* @var string
*/
protected $prefix;

/**
* @var bool
*/
protected $moreEntropy;

/**
* @param string $prefix
* @param bool $moreEntropy
*
* @link http://php.net/manual/en/function.uniqid.php
*/
public function __construct($prefix = '', $moreEntropy = false)
public function __construct(string $prefix = '', bool $moreEntropy = false)
{
$this->prefix = (string) $prefix;
$this->moreEntropy = (bool) $moreEntropy;
$this->prefix = $prefix;
$this->moreEntropy = $moreEntropy;
}

/**
* @return string
*/
public function generateRequestId()
public function generateRequestId(): string
{
return uniqid($this->prefix, $this->moreEntropy);
}
Expand Down
13 changes: 3 additions & 10 deletions src/Generator/PrefixedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,13 @@ final class PrefixedGenerator implements GeneratorInterface
private $prefix;
private $generator;

/**
* @param string $prefix
* @param GeneratorInterface $generator
*/
public function __construct($prefix, GeneratorInterface $generator)
public function __construct(string $prefix, GeneratorInterface $generator)
{
$this->prefix = (string) $prefix;
$this->prefix = $prefix;
$this->generator = $generator;
}

/**
* @return string
*/
public function generateRequestId()
public function generateRequestId(): string
{
return $this->prefix . $this->generator->generateRequestId();
}
Expand Down
11 changes: 2 additions & 9 deletions src/Generator/RamseyUuid1Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,20 @@
final class RamseyUuid1Generator implements GeneratorInterface
{
private $node;

private $clockSeq;

private $factory;

/**
* @param UuidFactoryInterface $factory
* @param int|string $node
* @param int $clockSeq
*/
public function __construct(UuidFactoryInterface $factory, $node = null, $clockSeq = null)
public function __construct(UuidFactoryInterface $factory, $node = null, int $clockSeq = null)
{
$this->factory = $factory;
$this->node = $node;
$this->clockSeq = $clockSeq;
}

/**
* @return string
*/
public function generateRequestId()
public function generateRequestId(): string
{
return $this->factory->uuid1($this->node, $this->clockSeq)->toString();
}
Expand Down
14 changes: 2 additions & 12 deletions src/Generator/RamseyUuid3Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,17 @@
final class RamseyUuid3Generator implements GeneratorInterface
{
private $ns;

private $name;

private $factory;

/**
* @param UuidFactoryInterface $factory
* @param string $ns
* @param string $name
*/
public function __construct(UuidFactoryInterface $factory, $ns, $name)
public function __construct(UuidFactoryInterface $factory, string $ns, string $name)
{
$this->factory = $factory;
$this->ns = $ns;
$this->name = $name;
}

/**
* @return string
*/
public function generateRequestId()
public function generateRequestId(): string
{
return $this->factory->uuid3($this->ns, $this->name)->toString();
}
Expand Down
5 changes: 1 addition & 4 deletions src/Generator/RamseyUuid4Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ public function __construct(UuidFactoryInterface $factory)
$this->factory = $factory;
}

/**
* @return string
*/
public function generateRequestId()
public function generateRequestId(): string
{
return $this->factory->uuid4()->toString();
}
Expand Down
5 changes: 1 addition & 4 deletions src/Generator/RamseyUuid4StaticGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

final class RamseyUuid4StaticGenerator implements GeneratorInterface
{
/**
* @return string
*/
public function generateRequestId()
public function generateRequestId(): string
{
return Uuid::uuid4()->toString();
}
Expand Down
14 changes: 2 additions & 12 deletions src/Generator/RamseyUuid5Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,17 @@
final class RamseyUuid5Generator implements GeneratorInterface
{
private $ns;

private $name;

private $factory;

/**
* @param UuidFactoryInterface $factory
* @param string $ns
* @param string $name
*/
public function __construct(UuidFactoryInterface $factory, $ns, $name)
public function __construct(UuidFactoryInterface $factory, string $ns, string $name)
{
$this->factory = $factory;
$this->ns = $ns;
$this->name = $name;
}

/**
* @return string
*/
public function generateRequestId()
public function generateRequestId(): string
{
return $this->factory->uuid5($this->ns, $this->name)->toString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/MonologProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(RequestIdProviderInterface $requestIdProvider)
$this->requestIdProvider = $requestIdProvider;
}

public function __invoke(array $record)
public function __invoke(array $record): array
{
try {
$requestId = $this->requestIdProvider->getRequestId();
Expand Down
2 changes: 1 addition & 1 deletion src/OverridePolicy/OverridePolicyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

interface OverridePolicyInterface
{
public function isAllowToOverride(ServerRequestInterface $request);
public function isAllowToOverride(ServerRequestInterface $request): bool;
}
8 changes: 2 additions & 6 deletions src/RequestDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ final class RequestDecorator
protected $requestIdProvider;
protected $headerName;

public function __construct(RequestIdProviderInterface $requestIdProvider, $headerName = RequestIdMiddleware::DEFAULT_RESPONSE_HEADER)
public function __construct(RequestIdProviderInterface $requestIdProvider, string $headerName = RequestIdMiddleware::DEFAULT_RESPONSE_HEADER)
{
$this->requestIdProvider = $requestIdProvider;
$this->headerName = $headerName;
}

/**
* Adds request id to request and return new instance
*
* @param RequestInterface $request
*
* @return RequestInterface
*/
public function decorate(RequestInterface $request)
public function decorate(RequestInterface $request): RequestInterface
{
return $request->withHeader($this->headerName, $this->requestIdProvider->getRequestId());
}
Expand Down
Loading

0 comments on commit f466aed

Please # to comment.