Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jenssegers committed May 12, 2018
1 parent 9954a8c commit a61a82c
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 117 deletions.
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@
"relay/relay": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0|^5.0",
"satooshi/php-coveralls": "^0.6",
"mockery/mockery": "^0.9"
"phpunit/phpunit": "^6.0|^7.0",
"satooshi/php-coveralls": "^2.0",
"mockery/mockery": "^1.1"
},
"autoload": {
"psr-4": {
"Proxy\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Proxy\\": "tests"
}
}
}
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
Expand Down
9 changes: 5 additions & 4 deletions src/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php namespace Proxy\Adapter;
<?php

namespace Proxy\Adapter;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

interface AdapterInterface {

interface AdapterInterface
{
/**
* Send the request and return the response.
*
* @param RequestInterface $request
* @return ResponseInterface
*/
public function send(RequestInterface $request);

}
14 changes: 6 additions & 8 deletions src/Adapter/Dummy/DummyAdapter.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?php namespace Proxy\Adapter\Dummy;
<?php

namespace Proxy\Adapter\Dummy;

use Proxy\Adapter\AdapterInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Response;

class DummyAdapter implements AdapterInterface {

class DummyAdapter implements AdapterInterface
{
/**
* Send the request and return the response.
*
* @param RequestInterface $request
* @return ResponseInterface
* @inheritdoc
*/
public function send(RequestInterface $request)
{
Expand Down
14 changes: 6 additions & 8 deletions src/Adapter/Guzzle/GuzzleAdapter.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php namespace Proxy\Adapter\Guzzle;
<?php

namespace Proxy\Adapter\Guzzle;

use GuzzleHttp\Client;
use Proxy\Adapter\AdapterInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class GuzzleAdapter implements AdapterInterface {

class GuzzleAdapter implements AdapterInterface
{
/**
* The Guzzle client instance.
*
Expand All @@ -25,10 +26,7 @@ public function __construct(Client $client = null)
}

/**
* Send the request and return the response.
*
* @param RequestInterface $request
* @return ResponseInterface
* @inheritdoc
*/
public function send(RequestInterface $request)
{
Expand Down
8 changes: 6 additions & 2 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<?php namespace Proxy\Exception;
<?php

class InvalidArgumentException extends \InvalidArgumentException {}
namespace Proxy\Exception;

class InvalidArgumentException extends \InvalidArgumentException
{
}
8 changes: 6 additions & 2 deletions src/Exception/UnexpectedValueException.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<?php namespace Proxy\Exception;
<?php

class UnexpectedValueException extends \UnexpectedValueException {}
namespace Proxy\Exception;

class UnexpectedValueException extends \UnexpectedValueException
{
}
25 changes: 6 additions & 19 deletions src/Factory.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php namespace Proxy;
<?php

namespace Proxy;

use Proxy\Adapter\AdapterInterface;
use Proxy\Exception\InvalidArgumentException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class Factory {

class Factory
{
/**
* The default adapter name.
*
Expand All @@ -29,17 +29,6 @@ public static function create($adapter = null)
return new Proxy($instance);
}

/**
* Forward a request using the default adapter.
*
* @param RequestInterface $request
* @return ResponseInterface
*/
public static function forward(RequestInterface $request)
{
return static::create()->forward($request);
}

/**
* Get the default adapter name.
*
Expand Down Expand Up @@ -71,12 +60,10 @@ protected static function createAdapter($adapter)
{
$class = '\\Proxy\\Adapter\\' . ucfirst($adapter) . '\\' . ucfirst($adapter) . 'Adapter';

if (class_exists($class))
{
if (class_exists($class)) {
return new $class;
}

throw new InvalidArgumentException("Adapter [$adapter] not found.");
}

}
14 changes: 8 additions & 6 deletions src/Filter/FilterInterface.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php namespace Proxy\Filter;
<?php

namespace Proxy\Filter;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

interface FilterInterface {

interface FilterInterface
{
/**
* Apply filter to request and/or response.
*
* @param RequestInterface $response
* @param ResponseInterface $response
* @param RequestInterface $request
* @param ResponseInterface $response
* @param callable $next
* @return ResponseInterface
*/
public function __invoke(RequestInterface $request, ResponseInterface $response, callable $next);

}
10 changes: 5 additions & 5 deletions src/Filter/RemoveEncodingFilter.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php namespace Proxy\Filter;
<?php

namespace Proxy\Filter;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class RemoveEncodingFilter implements FilterInterface {

class RemoveEncodingFilter implements FilterInterface
{
const TRANSFER_ENCODING = 'transfer-encoding';

const CONTENT_ENCODING = 'content-encoding';

/**
Expand All @@ -20,5 +21,4 @@ public function __invoke(RequestInterface $request, ResponseInterface $response,
->withoutHeader(self::TRANSFER_ENCODING)
->withoutHeader(self::CONTENT_ENCODING);
}

}
12 changes: 6 additions & 6 deletions src/Filter/RemoveLocationFilter.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php namespace Proxy\Filter;
<?php

namespace Proxy\Filter;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class RemoveLocationFilter implements FilterInterface {

class RemoveLocationFilter implements FilterInterface
{
const LOCATION = 'location';

/**
Expand All @@ -14,14 +16,12 @@ public function __invoke(RequestInterface $request, ResponseInterface $response,
{
$response = $next($request, $response);

if ($response->hasHeader(self::LOCATION))
{
if ($response->hasHeader(self::LOCATION)) {
$response = $response
->withHeader('X-Proxy-Location', $response->getHeader(self::LOCATION))
->withoutHeader(self::LOCATION);
}

return $response;
}

}
19 changes: 12 additions & 7 deletions src/Filter/RewriteLocationFilter.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php namespace Proxy\Filter;
<?php

namespace Proxy\Filter;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class RewriteLocationFilter implements FilterInterface {

class RewriteLocationFilter implements FilterInterface
{
const LOCATION = 'location';

/**
Expand All @@ -14,15 +16,18 @@ public function __invoke(RequestInterface $request, ResponseInterface $response,
{
$response = $next($request, $response);

if ($response->hasHeader(self::LOCATION))
{
if ($response->hasHeader(self::LOCATION)) {
$original = parse_url($response->getHeader(self::LOCATION));

$target = rtrim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']), '/');

if (isset($original['path'])) $target .= $original['path'];
if (isset($original['path'])) {
$target .= $original['path'];
}

if (isset($original['query'])) $target .= '?' . $original['query'];
if (isset($original['query'])) {
$target .= '?' . $original['query'];
}

$response = $response
->withHeader('X-Proxy-Location', $response->getHeader(self::LOCATION))
Expand Down
17 changes: 8 additions & 9 deletions src/Proxy.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Proxy;
<?php

namespace Proxy;

use Proxy\Adapter\AdapterInterface;
use Proxy\Exception\UnexpectedValueException;
Expand All @@ -8,8 +10,8 @@
use Zend\Diactoros\Response;
use Zend\Diactoros\Uri;

class Proxy {

class Proxy
{
/**
* The Request instance.
*
Expand Down Expand Up @@ -59,12 +61,11 @@ public function forward(RequestInterface $request)
*
* @param string $target
* @throws UnexpectedValueException
* @return Response
* @return ResponseInterface
*/
public function to($target)
{
if (is_null($this->request))
{
if ($this->request === null) {
throw new UnexpectedValueException('Missing request instance.');
}

Expand All @@ -89,8 +90,7 @@ public function to($target)

$stack = $this->filters;

$stack[] = function (RequestInterface $request, ResponseInterface $response, callable $next)
{
$stack[] = function (RequestInterface $request, ResponseInterface $response, callable $next) {
$response = $this->adapter->send($request);

return $next($request, $response);
Expand Down Expand Up @@ -123,5 +123,4 @@ public function getRequest()
{
return $this->request;
}

}
10 changes: 7 additions & 3 deletions tests/Proxy/Adapter/Dummy/DummyAdapterTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php namespace Proxy\Adapter\Dummy;
<?php

namespace Proxy\Adapter\Dummy;

use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\TestCase;

class DummyAdapterTest extends \PHPUnit_Framework_TestCase
class DummyAdapterTest extends TestCase
{
/**
* @var DummyAdapter
Expand All @@ -21,6 +25,6 @@ public function adapter_returns_psr_response()
{
$response = $this->adapter->send(ServerRequestFactory::fromGlobals(), '/');

$this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response);
$this->assertInstanceOf(ResponseInterface::class, $response);
}
}
Loading

0 comments on commit a61a82c

Please sign in to comment.