Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
366 changes: 0 additions & 366 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/Altair/Cache/SimpleCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public function setMultiple(iterable $values, null|int|DateInterval $ttl = null)
$items = $this->pool->getItems($keys);
} else {
foreach ($values as $key => $value) {
$key = \is_int($key) ? (string) $key : $key;
$items[$key] = $this->pool->getItem($key)->set($value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Altair/Cache/Storage/FilesystemCacheItemStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private function setCacheDirectory(Filesystem $filesystem, ?string $directory):
}

$path .= '/';
if ('\\' === '/' && \strlen($path) > 234) { // windows allows max of 258
if (DIRECTORY_SEPARATOR === '\\' && \strlen($path) > 234) { // windows allows max of 258
throw new InvalidArgumentException(\sprintf('Cache directory path is too long "%s"', $path));
}

Expand Down
12 changes: 4 additions & 8 deletions src/Altair/Cache/Storage/PredisCacheItemStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use Override;
use Predis\Client;
use Predis\Collection\Iterator\Keyspace;
use Predis\Connection\Aggregate\PredisCluster;
use Predis\Connection\Aggregate\RedisCluster;
use Predis\Connection\Cluster\PredisCluster;
use Predis\Connection\Cluster\RedisCluster;

class PredisCacheItemStorage implements CacheItemStorageInterface
{
Expand Down Expand Up @@ -163,14 +163,10 @@ public function save(array $values, int $lifespan)
}

$this->client->pipeline(
/** @param Client $pipe */
static function ($pipe) use ($serialized, $lifespan): void {
/** @var Client $pipe */
foreach ($serialized as $id => $value) {
if (0 >= $lifespan) {
$pipe->set($id, $value);
} else {
$pipe->setex($id, $lifespan, $value);
}
$pipe->setex($id, $lifespan, $value);
}
}
);
Expand Down
7 changes: 1 addition & 6 deletions src/Altair/Cache/Storage/RedisCacheItemStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,7 @@ public function save(array $values, int $lifespan)
$this->client->multi(Redis::PIPELINE);
$ids = [];
foreach ($serialized as $id => $value) {
if (0 >= $lifespan) {
$this->client->set($id, $value);
} else {
$this->client->setex($id, $lifespan, $value);
}

$this->client->setex($id, $lifespan, $value);
$ids[] = $id;
}

Expand Down
8 changes: 2 additions & 6 deletions src/Altair/Common/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static function merge(array $a, array $b): array
* $value = Arr::getValue($versions, ['1.0', 'date']);
* ```
*
* @param array|object $array array or object to extract value from
* @param mixed $array array or object to extract the value from; any other type yields the default
* @param string|Closure|array<array-key, string|Closure> $key key name of the array element, an array of keys or property name of the object,
* or an anonymous function returning the value. The anonymous function signature should be:
* `function($array, $defaultValue)`.
Expand All @@ -94,7 +94,7 @@ public static function merge(array $a, array $b): array
*
* @return mixed the value of the element if found, default value otherwise
*/
public static function getValue(array $array, $key, mixed $default = null)
public static function getValue(mixed $array, $key, mixed $default = null)
{
if ($key instanceof Closure) {
return $key($array, $default);
Expand Down Expand Up @@ -636,10 +636,6 @@ public static function isAssociative(array $array, bool $allStrings = true): boo
*/
public static function isIndexed(array $array, bool $consecutive = false): bool
{
if (!\is_array($array)) {
return false;
}

if ($array === []) {
return true;
}
Expand Down
7 changes: 4 additions & 3 deletions src/Altair/Container/Collection/AliasesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ class AliasesCollection extends Map
*/
public function define(string $original, string $alias, SharesCollection $sharesCollection): self
{
if (($original === '' || $original === '0' || !\is_string($original)) || ($alias === '' || $alias === '0' || !\is_string($alias))) {
if ($original === '' || $original === '0' || $alias === '' || $alias === '0') {
throw new InvalidArgumentException('"$original" and/or "$alias" cannot be empty.');
}

/** @var AliasesCollection|string $original */
$original = $this->normalizeName($original);

if (isset($sharesCollection[$original])) {
Expand All @@ -56,7 +55,9 @@ public function define(string $original, string $alias, SharesCollection $shares
$sharesCollection->put($alias, null)->remove($original);
}

return $this->put($original, $alias);
$this->put($original, $alias);

return $this;
}

/**
Expand Down
8 changes: 6 additions & 2 deletions src/Altair/Container/Collection/SharesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ public function shareClass(string $name, AliasesCollection $aliasesCollection):
{
[, $normalizedName] = $aliasesCollection->resolve($name);

return $this->put($normalizedName, $this[$normalizedName] ?? null);
$this->put($normalizedName, $this[$normalizedName] ?? null);

return $this;
}

/**
Expand All @@ -49,6 +51,8 @@ public function shareInstance(object $instance, AliasesCollection $aliasesCollec
);
}

return $this->put($normalizedName, $instance);
$this->put($normalizedName, $instance);

return $this;
}
}
10 changes: 4 additions & 6 deletions src/Altair/Container/Executable.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@

class Executable
{
/**
* @var ReflectionFunctionAbstract|ReflectionFunction
*/
protected $callableReflection;
protected ReflectionFunction|ReflectionMethod $callableReflection;

/**
* @var mixed|null The object to invoke the method on if $reflectionFunction is a ReflectionMethod. In
Expand All @@ -41,8 +38,10 @@ public function __construct(ReflectionFunctionAbstract $reflectionFunction, $obj
{
if ($reflectionFunction instanceof ReflectionMethod) {
$this->setMethodCallable($reflectionFunction, $object);
} else {
} elseif ($reflectionFunction instanceof ReflectionFunction) {
$this->callableReflection = $reflectionFunction;
} else {
throw new InvalidArgumentException(\sprintf('Unsupported reflection type "%s".', $reflectionFunction::class));
}
}

Expand Down Expand Up @@ -87,7 +86,6 @@ protected function setMethodCallable(ReflectionMethod $reflection, mixed $object
}

/**
* @param ReflectionFunction|ReflectionFunctionAbstract $reflection
* @param array<int, mixed> $args
*/
protected function invokeClosure(ReflectionFunction $reflection, array $args): mixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@

interface CommandMiddlewareInterface
{
public function handle(CommandMessageInterface $message, callable $next);
public function handle(CommandMessageInterface $message, callable $next): void;
}
7 changes: 2 additions & 5 deletions src/Altair/Courier/Middleware/CommandLockerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
class CommandLockerMiddleware implements CommandMiddlewareInterface
{
/**
* @var array
* @var array<int, CommandMessageInterface>
*/
protected $queue = [];

/**
* @var bool
*/
protected $running = false;
protected bool $running = false;

/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@
*/
class CommandRunnerMiddlewareStrategy implements CommandRunnerStrategyInterface
{
/**
* @var array<int, CommandMiddlewareInterface|class-string<CommandMiddlewareInterface>>
*/
protected array $middlewares;

/**
* CommandRunnerMiddlewareStrategy constructor.
*
* @param array<int, CommandMiddlewareInterface|class-string<CommandMiddlewareInterface>>|null $middlewares
*/
public function __construct(?array $middlewares = null, protected ?MiddlewareResolverInterface $resolver = null)
{
Expand All @@ -37,6 +42,7 @@ public function __construct(?array $middlewares = null, protected ?MiddlewareRes
/**
* Returns a new instance with
*
* @param array<int, CommandMiddlewareInterface|class-string<CommandMiddlewareInterface>> $middlewares
*
* @throws InvalidCommandMiddlewareException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Altair/Doctor/Configuration/DoctorConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private function readRequirements(string $projectRoot): array

sort($extensions, SORT_STRING);

return [$floor, array_values($extensions)];
return [$floor, $extensions];
}

private function normalizeVersion(string $constraint, string $fallback): string
Expand Down
2 changes: 1 addition & 1 deletion src/Altair/Events/Cli/CheckpointCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __invoke(
$head = $event;
}

$eventId = $head?->id ?? '';
$eventId = $head->id ?? '';

$this->storage->create($name, $eventId);

Expand Down
2 changes: 0 additions & 2 deletions src/Altair/Happen/Contracts/EventDispatcherInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ public function hasListeners(string $event): bool;
* The first parameter should be the event name. All event listeners will
* be removed.
*
*
* @return EventDispatcherInterface;
*/
public function removeAllListeners(string $event): EventDispatcherInterface;

Expand Down
4 changes: 0 additions & 4 deletions src/Altair/Http/Base/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Altair\Http\Collection\InputCollection;
use Altair\Http\Collection\SettingsCollection;
use Altair\Http\Contracts\PayloadInterface;
use Altair\Structure\Map;
use Override;

class Payload implements PayloadInterface
Expand All @@ -36,9 +35,6 @@ class Payload implements PayloadInterface
*/
protected $messages = [];

/**
* @var Map|null
*/
protected SettingsCollection $settingsCollection;

/**
Expand Down
17 changes: 6 additions & 11 deletions src/Altair/Http/Collection/HttpStatusCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use IteratorAggregate;
use Override;
use ReflectionClass;
use Traversable;

/**
* @implements IteratorAggregate<int, string>
Expand All @@ -36,9 +35,9 @@ class HttpStatusCollection implements Countable, IteratorAggregate

/**
* @inheritDoc
* @param array<int, string>|Traversable<int, string> $values
* @param iterable<int, string> $values
*/
public function __construct($values = [])
public function __construct(iterable $values = [])
{
$this->values = $this->buildCommonValues();

Expand Down Expand Up @@ -107,7 +106,7 @@ public function getReasonPhrase(int $code): string
* @throws InvalidArgumentException If the requested $statusCode is not valid
*
*/
public function getResponseClass(int $code): string
public function getResponseClass(int $code): int
{
$responseClass = [
1 => HttpStatusCodeInterface::RESPONSE_CLASS_INFORMATIONAL,
Expand All @@ -117,7 +116,7 @@ public function getResponseClass(int $code): string
5 => HttpStatusCodeInterface::RESPONSE_CLASS_SERVER_ERROR,
];
$code = $this->filterCode($code);
return $responseClass[(int) substr($code, 0, 1)];
return $responseClass[intdiv($code, 100)];
}

/**
Expand Down Expand Up @@ -172,14 +171,10 @@ public function merge(int $code, string $reason): void
/**
* Merges an array of status codes and its reason phrase into the default values.
*
* @param array<int, string>|Traversable<int, string> $values
* @param iterable<int, string> $values
*/
public function mergeAll($values): void
public function mergeAll(iterable $values): void
{
if (!\is_array($values) || !$values instanceof Traversable) {
throw new InvalidArgumentException("Values must be a Traversable object or an array");
}

foreach ($values as $code => $reason) {
$this->merge($code, $reason);
}
Expand Down
6 changes: 2 additions & 4 deletions src/Altair/Http/Formatter/PhpViewFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Altair\Http\Contracts\PayloadInterface;
use Altair\Http\Exception\InvalidArgumentException;
use Altair\Http\Exception\RuntimeException;
use Exception;
use Override;
use Throwable;

Expand Down Expand Up @@ -94,7 +93,6 @@ protected function renderLayout(PayloadInterface $payload, $content): string
*
* @param array<string, mixed> $params
*
* @throws Exception
* @throws Throwable
*/
protected function renderPhpFile(string $file, array $params = []): string
Expand All @@ -108,14 +106,14 @@ protected function renderPhpFile(string $file, array $params = []): string
require($file);

return ob_get_clean();
} catch (Exception|Throwable $e) {
} catch (Throwable $throwable) {
while (ob_get_level() > $level) {
if (!@ob_end_clean()) {
ob_clean();
}
}

throw $e;
throw $throwable;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Altair/Http/Middleware/SessionHeadersMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
{
$prevName = session_name();
$prevCookie = $this->cookieManager->getFromRequest($request, $prevName);
$prevId = $prevCookie?->getValue();
$prevId = $prevCookie->getValue();
if ($prevId !== null) {
session_id($prevId);
}
Expand All @@ -57,9 +57,9 @@ private function createNewSessionCookie(string $sessionId): SetCookie
$params = session_get_cookie_params();

return (new SetCookie((string) session_name(), $sessionId))
->withDomain($params['domain'] ?? null)
->withPath($params['path'] ?? null)
->withExpires($params['lifetime'] ?? null)
->withDomain($params['domain'])
->withPath($params['path'])
->withExpires($params['lifetime'])
->withSecure(!empty($params['secure']))
->withHttpOnly(!empty($params['httponly']));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Altair/Http/Middleware/SpamBlockerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(
}

$entries = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$this->list = $entries === false ? [] : array_values($entries);
$this->list = $entries === false ? [] : $entries;
}

#[Override]
Expand Down
2 changes: 1 addition & 1 deletion src/Altair/Http/Responder/CompoundResponder.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __invoke(
PayloadInterface $payload
): ResponseInterface {
foreach ($this->responders as $responder) {
/** @var callable $responder */
/** @var ResponderInterface $responder */
$responder = $this->resolve($responder);
$response = $responder($request, $response, $payload);
}
Expand Down
Loading
Loading