Skip to content

Commit

Permalink
Improving code quality (#10)
Browse files Browse the repository at this point in the history
- Added full PHP 8 support
- Removed support for pre PHP 7.4
- Improved the code style and added SCA
  - Added type hints
- Copyright updated
  • Loading branch information
devtronic authored Mar 22, 2022
1 parent 903786e commit d104634
Show file tree
Hide file tree
Showing 63 changed files with 871 additions and 1,188 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ jobs:

- name: Run SCA
run: composer run-script phpstan

- name: Run CS
run: composer run-script fix-cs:dry-run
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
vendor/
composer.lock
client.php
/.phpunit.result.cache
/.idea/
/.php_cs.cache
.phpunit.result.cache
.idea/
.php_cs.cache
.php-cs-fixer.cache
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## v3.0.0 (22. Mar 2022)

Changes:
- Added full PHP 8 support
- Removed support for pre PHP 7.4
- Improved the code style and added SCA
- Added type hints
- Copyright updated

## v2.1.1 (21. Mar 2022)

Bug Fixes:
Expand Down
22 changes: 18 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
"description": "Implementation of the Billbee custom shop API in PHP",
"type": "library",
"require": {
"php": "5.6.* || ^7.0 || ^8.0",
"php": "^7.4 || ^8.0",
"psr/http-message": "^1.0",
"jms/serializer": "^1.14.0 || ^3.14.0",
"ralouphie/getallheaders": "~3.0",
"mintware-de/streams": "^1.0",
"mintware-de/streams": "^2.0.0",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^5.7 || ^7.0 || ^8.0 || ^9.0",
"friendsofphp/php-cs-fixer": "^2.15"
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
"friendsofphp/php-cs-fixer": "^v3.8.0",
"phpstan/phpstan": "^1.4"
},
"suggest": {
"ext-xdebug": "*"
},
"license": "MIT",
"authors": [
Expand All @@ -32,6 +36,16 @@
"fix-cs": [
"./vendor/bin/php-cs-fixer fix ./src/ --using-cache=no --rules=@PSR2",
"./vendor/bin/php-cs-fixer fix ./tests/ --using-cache=no --rules=@PSR2"
],
"fix-cs:dry-run": [
"./vendor/bin/php-cs-fixer fix ./src/ --using-cache=no --rules=@PSR2 --dry-run",
"./vendor/bin/php-cs-fixer fix ./tests/ --using-cache=no --rules=@PSR2 --dry-run"
],
"phpstan": [
"./vendor/bin/phpstan"
],
"test": [
"./vendor/bin/phpunit"
]
},
"archive": {
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: max
paths:
- src
- tests
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--
~ This file is part of the Billbee Custom Shop API package.
~
~ Copyright 2019 by Billbee GmbH
~ Copyright 2019-2022 by Billbee GmbH
~
~ For the full copyright and license information, please read the LICENSE
~ file that was distributed with this source code.
Expand All @@ -17,7 +17,7 @@
</coverage>
<testsuites>
<testsuite name="UnitTests">
<directory suffix="Test.php">./tests/</directory>
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
5 changes: 3 additions & 2 deletions src/Exception/NotImplementedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Billbee Custom Shop API package.
*
* Copyright 2019 by Billbee GmbH
* Copyright 2019-2022 by Billbee GmbH
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
Expand All @@ -13,10 +13,11 @@
namespace Billbee\CustomShopApi\Exception;

use Exception;
use Throwable;

class NotImplementedException extends Exception
{
public function __construct($code = 0, $previous = null)
public function __construct(int $code = 0, Throwable $previous = null)
{
parent::__construct("Diese Aktion ist nicht implementiert", $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/OrderNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Billbee Custom Shop API package.
*
* Copyright 2019 by Billbee GmbH
* Copyright 2019-2022 by Billbee GmbH
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ProductNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Billbee Custom Shop API package.
*
* Copyright 2019 by Billbee GmbH
* Copyright 2019-2022 by Billbee GmbH
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
Expand Down
58 changes: 42 additions & 16 deletions src/Http/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Billbee Custom Shop API package.
*
* Copyright 2019 by Billbee GmbH
* Copyright 2019-2022 by Billbee GmbH
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
Expand All @@ -12,36 +12,48 @@

namespace Billbee\CustomShopApi\Http;

use MintWare\Streams\MemoryStream;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\StreamInterface;

abstract class Message
/**
* @template T
*/
abstract class Message implements MessageInterface
{
protected $protocolVersion = "1.1";
protected string $protocolVersion = "1.1";

/** @var string[][] */
protected $headers = [];
/** @var array<array<string>> */
protected array $headers = [];

/** @var StreamInterface */
protected $body;
protected StreamInterface $body;

public function __construct()
{
$this->body = new MemoryStream(null);
}

/** @inheritDoc */
public function getProtocolVersion()
public function getProtocolVersion(): string
{
return $this->protocolVersion;
}

/** @inheritDoc */
/**
* @inheritDoc
* @phpstan-return T
*/
public function withProtocolVersion($version)
{
/** @var T $request */
$request = clone $this;
$request->protocolVersion = $version;

return $request;
}

/** @inheritDoc */
public function getHeaders()
public function getHeaders(): array
{
return $this->headers;
}
Expand Down Expand Up @@ -72,25 +84,36 @@ public function getHeaderLine($name)
return $line;
}

/** @inheritDoc */
/**
* @inheritDoc
* @phpstan-return T
*/
public function withHeader($name, $value)
{
/** @var T $request */
$request = clone $this;

$request->headers[$name] = is_array($value) ? $value : [$value];

return $request;
}

/** @inheritDoc */
/**
* @inheritDoc
* @phpstan-return T
*/
public function withAddedHeader($name, $value)
{
return $this->withHeader($name, $value);
}

/** @inheritDoc */
/**
* @inheritDoc
* @phpstan-return T
*/
public function withoutHeader($name)
{
/** @var T $request */
$request = clone $this;

if ($request->hasHeader($name)) {
Expand All @@ -100,15 +123,18 @@ public function withoutHeader($name)
return $request;
}

/** @inheritDoc */
public function getBody()
public function getBody(): ?StreamInterface
{
return $this->body;
}

/** @inheritDoc */
/**
* @inheritDoc
* @phpstan-return T
*/
public function withBody(StreamInterface $body)
{
/** @var T $request */
$request = clone $this;

$request->body = $body;
Expand Down
28 changes: 15 additions & 13 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Billbee Custom Shop API package.
*
* Copyright 2019 by Billbee GmbH
* Copyright 2019-2022 by Billbee GmbH
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
Expand All @@ -17,19 +17,18 @@
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;

/** @inheritDoc */
/**
* @extends Message<Request>
*/
class Request extends Message implements RequestInterface
{
/** @var string */
private $requestTarget;
private string $requestTarget = '';

/** @var string */
private $method;
private string $method = 'GET';

/** @var UriInterface */
private $uri;
private UriInterface $uri;

public static function createFromGlobals()
public static function createFromGlobals(): Request
{
$request = new Request();

Expand Down Expand Up @@ -62,12 +61,15 @@ public static function createFromGlobals()
}

/** @inheritDoc */
public function getRequestTarget()
public function getRequestTarget(): string
{
return $this->requestTarget;
}

/** @inheritDoc */
/**
* @inheritDoc
* @param string $requestTarget
*/
public function withRequestTarget($requestTarget)
{
$request = clone $this;
Expand All @@ -78,7 +80,7 @@ public function withRequestTarget($requestTarget)
}

/** @inheritDoc */
public function getMethod()
public function getMethod(): string
{
return $this->method;
}
Expand All @@ -94,7 +96,7 @@ public function withMethod($method)
}

/** @inheritDoc */
public function getUri()
public function getUri(): UriInterface
{
return $this->uri;
}
Expand Down
12 changes: 9 additions & 3 deletions src/Http/RequestHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This file is part of the Billbee Custom Shop API package.
*
* Copyright 2019 by Billbee GmbH
* Copyright 2019-2022 by Billbee GmbH
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code.
Expand All @@ -16,7 +16,13 @@

interface RequestHandlerInterface
{
public function handle(RequestInterface $request, $queryArgs = []);
/**
* @param array<string, string> $queryArgs
*/
public function handle(RequestInterface $request, array $queryArgs = []): Response;

public function canHandle(RequestInterface $request, $queryArgs = []);
/**
* @param array<string, string> $queryArgs
*/
public function canHandle(RequestInterface $request, array $queryArgs = []): bool;
}
Loading

0 comments on commit d104634

Please sign in to comment.