Skip to content

Commit

Permalink
Merge aa03986 into ff6a387
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed Jan 5, 2022
2 parents ff6a387 + aa03986 commit 7b61511
Show file tree
Hide file tree
Showing 101 changed files with 705 additions and 448 deletions.
13 changes: 12 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ includes:
- vendor/phpstan/phpstan-phpunit/rules.neon
parameters:
level: max

paths:
- src
- tests

excludePaths:
- tests\Resources\Template\*

ignoreErrors:
- '#Call to an undefined method Psr\\Http\\Message\\ServerRequestInterface::getBasePath\(\).#'

tmpDir: build/phpStan
checkMissingIterableValueType: false

checkMissingIterableValueType: false
# Pour les objets \ReflectionClass
checkGenericClassInNonGenericObjectType: false
11 changes: 10 additions & 1 deletion src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ final private function __construct(ServerRequestInterface $request)
public static function getInstance(?ServerRequestInterface $request = null): self
{
if (self::$instance === null) {
if (!$request instanceof ServerRequestInterface) {
throw new \InvalidArgumentException(
'The request must be an implementation of Psr\Http\Message\ServerRequestInterface.'
);
}

self::$instance = new static($request);
}

Expand Down Expand Up @@ -377,6 +383,9 @@ public function getDir(
bool $addEnv = true
): string {
$root = $this->getSetting('root', '');
if (!is_string($root)) {
throw new \InvalidArgumentException('The root parameter must be a string.');
}
$dir = $this->getSettingEnv($key, $default, $addEnv);

return Util::cleanDir("$root/$dir");
Expand Down Expand Up @@ -450,7 +459,7 @@ protected function loadRoutesAndServices(): void
*
* Les données doivent pouvoir être prise en charge par le Stream de la réponse.
*
* @param ResponseInterface|bool|float|int|object|ressource|string|null $response
* @param mixed $response
*
* @return ResponseInterface
*/
Expand Down
34 changes: 12 additions & 22 deletions src/Components/Form/FormGroupBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,33 +836,25 @@ protected function addEnd(FormGroupBuilder $form): void
*
* @see http://php.net/manual/fr/function.array-slice.php
*
* @param array $input Tableau associatif.
* @param int|string $offset
* @param int|string $length
* @param array $replacement
* @param bool $after Si le tableau de remplacement doit être intègré après.
* @param array $input Tableau associatif.
* @param string $key
* @param array $replacement
* @param bool $after Si le tableau de remplacement doit être intègré après.
*
* @return void
*/
private function arraySpliceAssoc(
array &$input,
$offset,
$length,
string $key,
array $replacement,
bool $after = false
bool $after
): void {
$keyIndices = array_flip(array_keys($input));

if (isset($input[ $offset ]) && is_string($offset)) {
$offset = $keyIndices[ $offset ];
}
if (isset($input[ $length ]) && is_string($length)) {
$length = $keyIndices[ $length ] - $offset;
}
/** @var int $offset */
$offset = array_flip(array_keys($input))[$key];

$input = array_slice($input, 0, $offset + ($after
? 1
: 0), true) + $replacement + array_slice($input, $offset + $length, null, true);
$input = array_slice($input, 0, $offset + ($after ? 1 : 0), true)
+ $replacement
+ array_slice($input, $offset, null, true);
}

/**
Expand All @@ -882,9 +874,7 @@ private function addItem(
if (isset($this->form[ $key ])) {
$subform = new FormGroupBuilder;
$callback($subform);
$this->arraySpliceAssoc($this->form, $key, ($after
? $key
: 0), $subform->getForm(), $after);
$this->arraySpliceAssoc($this->form, $key, $subform->getForm(), $after);

return true;
}
Expand Down
42 changes: 21 additions & 21 deletions src/Components/Http/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Message implements MessageInterface
/**
* Les entêtes.
*
* @var array
* @var string[][]
*/
protected $headers = [];

Expand All @@ -65,7 +65,7 @@ class Message implements MessageInterface
*
* @return string
*/
public function getProtocolVersion()
public function getProtocolVersion(): string
{
return $this->protocolVersion;
}
Expand All @@ -75,9 +75,9 @@ public function getProtocolVersion()
*
* @param string $version Version du protocole HTTP.
*
* @return $this
* @return static
*/
public function withProtocolVersion($version)
public function withProtocolVersion($version): MessageInterface
{
$clone = clone $this;
$clone->protocolVersion = $this->filterProtocolVersion($version);
Expand All @@ -88,9 +88,9 @@ public function withProtocolVersion($version)
/**
* Renvoie le tableau d'en-tête.
*
* @return array
* @return string[][]
*/
public function getHeaders()
public function getHeaders(): array
{
return $this->headers;
}
Expand All @@ -102,7 +102,7 @@ public function getHeaders()
*
* @return bool Renvoie true si l'en-tête est trouvé sinon faux.
*/
public function hasHeader($name)
public function hasHeader($name): bool
{
return isset($this->name[ strtolower($name) ]);
}
Expand All @@ -115,7 +115,7 @@ public function hasHeader($name)
* @return string[] Si l'en-tête est trouvé alors il est renvoyé
* toutes ses valeurs, sinon un tableau vide.
*/
public function getHeader($name)
public function getHeader($name): array
{
return $this->hasHeader($name)
? $this->headers[ $this->name[ strtolower($name) ] ]
Expand All @@ -130,7 +130,7 @@ public function getHeader($name)
* @return string Si l'en-tête est trouvé alors il est renvoyé
* toutes les valeurs de l'en-tête concaténés par une virgule, sinon une chaine vide.
*/
public function getHeaderLine($name)
public function getHeaderLine($name): string
{
return $this->hasHeader($name)
? implode(',', $this->getHeader($name))
Expand All @@ -143,9 +143,9 @@ public function getHeaderLine($name)
* @param string $name Nom du champ d'en-tête insensible à la casse.
* @param string|string[] $value Valeur(s) de l'en-tête.
*
* @return $this
* @return static
*/
public function withHeader($name, $value)
public function withHeader($name, $value): MessageInterface
{
$clone = clone $this;
$values = $clone->validateAndTrimHeader($name, $value);
Expand All @@ -161,9 +161,9 @@ public function withHeader($name, $value)
* @param string $name Nom du champ d'en-tête insensible à la casse.
* @param string|string[] $value Valeur(s) de l'en-tête.
*
* @return $this
* @return static
*/
public function withAddedHeader($name, $value)
public function withAddedHeader($name, $value): MessageInterface
{
$clone = clone $this;
$values = $this->validateAndTrimHeader($name, $value);
Expand All @@ -184,9 +184,9 @@ public function withAddedHeader($name, $value)
*
* @param string $name Nom de champ d'en-tête insensible à la casse à supprimer.
*
* @return $this
* @return static
*/
public function withoutHeader($name)
public function withoutHeader($name): MessageInterface
{
$clone = clone $this;
if ($clone->hasHeader($name)) {
Expand All @@ -201,7 +201,7 @@ public function withoutHeader($name)
*
* @return StreamInterface Renvoie le corps en tant que flux.
*/
public function getBody()
public function getBody(): StreamInterface
{
return $this->body;
}
Expand All @@ -211,9 +211,9 @@ public function getBody()
*
* @param StreamInterface $body Le corp.
*
* @return $this
* @return static
*/
public function withBody(StreamInterface $body)
public function withBody(StreamInterface $body): MessageInterface
{
$clone = clone $this;
$clone->body = $body;
Expand All @@ -224,7 +224,7 @@ public function withBody(StreamInterface $body)
/**
* Filtre la version du protocole.
*
* @param string $version
* @param mixed $version
*
* @throws \InvalidArgumentException Le protocole spécifié n'est pas valide.
*
Expand Down Expand Up @@ -274,8 +274,8 @@ protected function withHeaders(array $headers): void
*
* @see https://tools.ietf.org/html/rfc7230#section-3.2.4
*
* @param string $header
* @param array|string $values
* @param mixed $header
* @param mixed $values
*
* @throws \InvalidArgumentException;
*
Expand Down
16 changes: 8 additions & 8 deletions src/Components/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Request extends Message implements RequestInterface
/**
* L'URI de la requête.
*
* @var \Psr\Http\Message\UriInterface
* @var UriInterface
*/
protected $uri;

Expand Down Expand Up @@ -97,7 +97,7 @@ public function __construct(
*
* @return string Renvoie la méthode de requête.
*/
public function getMethod()
public function getMethod(): string
{
return $this->method;
}
Expand All @@ -109,7 +109,7 @@ public function getMethod()
*
* @return string Cible ce la requête.
*/
public function getRequestTarget()
public function getRequestTarget(): string
{
if ($this->requestTarget !== null) {
return $this->requestTarget;
Expand All @@ -134,7 +134,7 @@ public function getRequestTarget()
* @return UriInterface Renvoie une instance d'UriInterface
* représentant l'URI de la requête.
*/
public function getUri()
public function getUri(): UriInterface
{
return $this->uri;
}
Expand All @@ -147,7 +147,7 @@ public function getUri()
* @throws \InvalidArgumentException pour les méthodes HTTP invalides.
* @return static
*/
public function withMethod($method)
public function withMethod($method): RequestInterface
{
$clone = clone $this;
$clone->method = $this->filterMethod($method);
Expand All @@ -165,7 +165,7 @@ public function withMethod($method)
*
* @return static
*/
public function withRequestTarget($requestTarget)
public function withRequestTarget($requestTarget): RequestInterface
{
if (!is_string($requestTarget)) {
throw new \InvalidArgumentException('The target of the request must be a string.');
Expand All @@ -186,7 +186,7 @@ public function withRequestTarget($requestTarget)
*
* @return static
*/
public function withUri(UriInterface $uri, $preserveHost = false)
public function withUri(UriInterface $uri, $preserveHost = false): RequestInterface
{
$clone = clone $this;
$clone->uri = $uri;
Expand All @@ -204,7 +204,7 @@ public function withUri(UriInterface $uri, $preserveHost = false)
/**
* Filtre la méthde HTTP de la requête.
*
* @param string $method Méthode HTTP ('GET'|'POST'|...).
* @param mixed $method Méthode HTTP ('GET'|'POST'|...).
*
* @throws \InvalidArgumentException La méthode doit être une chaine de caractère.
* @throws \InvalidArgumentException La méthode n'est pas prise en charge par la requête.
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function getStatusCode(): int
*
* @return static
*/
public function withStatus($code, $reasonPhrase = '')
public function withStatus($code, $reasonPhrase = ''): ResponseInterface
{
$clone = clone $this;
$clone->code = $this->filtreCode($code);
Expand All @@ -202,7 +202,7 @@ public function getReasonPhrase(): string
/**
* Filtre le code d'état.
*
* @param int $code Code d'état.
* @param mixed $code Code d'état.
*
* @throws \InvalidArgumentException Le code de statut n'est pas valide.
*
Expand Down

0 comments on commit 7b61511

Please sign in to comment.