Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[master] type all class properties and function parameters
  • Loading branch information
annadamm-check24 committed Mar 4, 2024
commit 60e35f07c664c7b65bdf5863dbcc9e1d64d0ed12
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Breaking Changes

- PHP 8.1 is now required
- All class properties and function parameters are now typed

### Fixed

Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,24 @@
"rector/rector": "^1.0",
"roave/security-advisories": "dev-latest",
"phpunit/phpunit": "^11.0",
"squizlabs/php_codesniffer": "^3.9"
"squizlabs/php_codesniffer": "^3.9",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-deprecation-rules": "^1.1"
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"archive": {
"exclude": ["data", "tests", "rector.config.php"]
},
"scripts": {
"check" : [
"@cs-check",
"@test"
],
"cs-check" : "phpcs --parallel=50",
"cs-fix" : "phpcbf",
"phpstan": "phpstan analyse",
"rector": [
"rector --config=rector.config.php",
"@cs-fix"
Expand Down
102 changes: 101 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parameters:
ignoreErrors:
-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Client/ClientBuilder.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Server/ServerBuilder.php
16 changes: 16 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-deprecation-rules/rules.neon

parameters:
tmpDir: data/phpstan
cache:
nodesByStringCountMax: 0
level: 5
fileExtensions:
- php
paths:
- src
- tests
6 changes: 6 additions & 0 deletions rector.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationRector;
use Rector\TypeDeclaration\Rector\Property\AddPropertyTypeDeclarationRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths(
Expand All @@ -23,6 +26,9 @@
LevelSetList::UP_TO_PHP_81,
DowngradeLevelSetList::DOWN_TO_PHP_81,
SetList::CODE_QUALITY,
SetList::TYPE_DECLARATION,
]
);

$rectorConfig->importNames();
};
13 changes: 7 additions & 6 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Dflydev\Hawk\Client;

use InvalidArgumentException;
use Dflydev\Hawk\Credentials\CredentialsInterface;
use Dflydev\Hawk\Crypto\Artifacts;
use Dflydev\Hawk\Crypto\Crypto;
Expand All @@ -25,7 +26,7 @@ public function __construct(
) {
}

public function createRequest(CredentialsInterface $credentials, $uri, $method, array $options = [])
public function createRequest(CredentialsInterface $credentials, $uri, $method, array $options = []): Request
{
$timestamp = $options['timestamp'] ?? $this->timeProvider->createTimestamp();
if ($this->localtimeOffset) {
Expand All @@ -50,7 +51,7 @@ public function createRequest(CredentialsInterface $credentials, $uri, $method,
$contentType = $options['content_type'];
$hash = $this->crypto->calculatePayloadHash($payload, $credentials->algorithm(), $contentType);
} else {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
"If one of 'payload' and 'content_type' are specified, both must be specified."
);
}
Expand Down Expand Up @@ -107,12 +108,12 @@ public function authenticate(
Request $request,
$headerObjectOrString,
array $options = []
) {
): bool {
$header = HeaderFactory::createFromHeaderObjectOrString(
'Server-Authorization',
$headerObjectOrString,
function (): never {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
'Header must either be a string or an instance of "Dflydev\Hawk\Header\Header"'
);
}
Expand All @@ -123,7 +124,7 @@ function (): never {
$payload = $options['payload'];
$contentType = $options['content_type'];
} else {
throw new \InvalidArgumentException(
throw new InvalidArgumentException(
'If one of "payload" and "content_type" are specified, both must be specified.'
);
}
Expand Down Expand Up @@ -168,7 +169,7 @@ function (): never {
return $artifacts->hash() === $hash;
}

public function createBewit(CredentialsInterface $credentials, $uri, $ttlSec, array $options = [])
public function createBewit(CredentialsInterface $credentials, $uri, $ttlSec, array $options = []): string
{
$timestamp = $options['timestamp'] ?? $this->timeProvider->createTimestamp();
if ($this->localtimeOffset) {
Expand Down
20 changes: 10 additions & 10 deletions src/Client/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,40 @@

class ClientBuilder
{
private $crypto;
private $timeProvider;
private $nonceProvider;
private $localtimeOffset = 0;
private ?Crypto $crypto = null;
private ?TimeProviderInterface $timeProvider = null;
private ?NonceProviderInterface $nonceProvider = null;
private int $localtimeOffset = 0;

public function setCrypto(Crypto $crypto)
public function setCrypto(Crypto $crypto): static
{
$this->crypto = $crypto;

return $this;
}

public function setTimeProvider(TimeProviderInterface $timeProvider)
public function setTimeProvider(TimeProviderInterface $timeProvider): static
{
$this->timeProvider = $timeProvider;

return $this;
}

public function setNonceProvider(NonceProviderInterface $nonceProvider)
public function setNonceProvider(NonceProviderInterface $nonceProvider): static
{
$this->nonceProvider = $nonceProvider;

return $this;
}

public function setLocaltimeOffset($localtimeOffset = null)
public function setLocaltimeOffset(int $localtimeOffset = null): static
{
$this->localtimeOffset = $localtimeOffset;

return $this;
}

public function build()
public function build(): Client
{
$crypto = $this->crypto ?: new Crypto();
$timeProvider = $this->timeProvider ?: DefaultTimeProviderFactory::create();
Expand All @@ -57,7 +57,7 @@ public function build()
);
}

public static function create()
public static function create(): static
{
return new static();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Client/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

interface ClientInterface
{
public function createRequest(CredentialsInterface $credentials, $uri, $method, array $options = []);
public function createRequest(CredentialsInterface $credentials, string $uri, string $method, array $options = []);
public function authenticate(
CredentialsInterface $credentials,
Request $request,
Expand Down
4 changes: 2 additions & 2 deletions src/Client/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ public function __construct(private readonly Header $header, private readonly Ar
{
}

public function header()
public function header(): Header
{
return $this->header;
}

public function artifacts()
public function artifacts(): Artifacts
{
return $this->artifacts;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Credentials/CallbackCredentialsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public function __construct(private $callback)
{
}

public function loadCredentialsById($id)
public function loadCredentialsById(string $id): CredentialsInterface
{
return call_user_func($this->callback, $id);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Credentials/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

class Credentials implements CredentialsInterface
{
public function __construct(private $key, private $algorithm = 'sha256', private $id = null)
public function __construct(private string $key, private string $algorithm = 'sha256', private ?string $id = null)
{
}

public function id()
public function id(): ?string
{
return $this->id;
}

public function key()
public function key(): string
{
return $this->key;
}

public function algorithm()
public function algorithm(): string
{
return $this->algorithm;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Credentials/CredentialsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

interface CredentialsInterface
{
public function key();
public function algorithm();
public function id();
public function key(): string;
public function algorithm(): string;
public function id(): ?string;
}
2 changes: 1 addition & 1 deletion src/Credentials/CredentialsProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

interface CredentialsProviderInterface
{
public function loadCredentialsById($id);
public function loadCredentialsById(string $id): CredentialsInterface;
}
Loading