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
3 changes: 3 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ jobs:
- name: Run PHPStan
run: composer phpstan

- name: Run Rector
run: composer rector:check

- name: Run tests
run: composer test -- --fail-on-warning --fail-on-risky

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The format is based on Keep a Changelog.
- Refactored the Lang package to resolve adapter instances through `LangFactory` configuration and load file translations lazily on first use instead of preloading them during web boot (#533)
- **BREAKING:** Reshaped Lang configuration so `lang.default` now selects the adapter, locale fallback moved to `lang.default_locale`, and the unused `lang.enabled` toggle was removed (#533)
- **BREAKING:** Removed `Lang::isEnabled()` from the public Lang API because it no longer affected runtime behavior (#533)
- Applied the pending Rector refactors across `src/` (null-coalescing assignment for lazy initialization, explicit `instanceof` checks instead of truthiness checks on nullable objects, native return types on `env()`, `CurlAdapter::getId()` and `CurlAdapter::getResponseCookies()`) and added `composer rector:check` to the CI workflow after PHPStan (#587)

### Fixed
- The page not found response is JSON for every client that asks for JSON, not only when the `Accept` header is exactly `application/json`: clients such as axios (`application/json, text/plain, */*`), a `charset` parameter, `+json` types and AJAX requests used to get the HTML page. `page_not_found_response()` decides with `Request::expectsJson()` and takes an optional request (#581)
Expand Down
6 changes: 1 addition & 5 deletions src/App/Factories/AppFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ class AppFactory
public static function create(string $type, string $baseDir): App
{

if (!isset(self::$instances[$type])) {
self::$instances[$type] = self::createInstance($type, $baseDir);
}

return self::$instances[$type];
return self::$instances[$type] ??= self::createInstance($type, $baseDir);
}

public static function destroy(string $type): void
Expand Down
4 changes: 1 addition & 3 deletions src/Archive/Adapters/ZipAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ private function openArchive(): void
throw ArchiveException::missingArchiveName();
}

if ($this->archive === null) {
$this->archive = new ZipArchive();
}
$this->archive ??= new ZipArchive();

if ($this->archive->filename) {
$this->archive->close();
Expand Down
6 changes: 1 addition & 5 deletions src/Archive/Factories/ArchiveFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ public static function get(string $type = ArchiveType::PHAR): Archive
*/
public function resolve(string $type = ArchiveType::PHAR): Archive
{
if (!isset($this->instances[$type])) {
$this->instances[$type] = $this->createInstance($type);
}

return $this->instances[$type];
return $this->instances[$type] ??= $this->createInstance($type);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Asset/AssetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function register(array $assets): void
*/
public function registerAsset(Asset $asset): void
{
if ($asset->getName() && $this->get($asset->getName())) {
if ($asset->getName() && $this->get($asset->getName()) instanceof Asset) {
throw AssetException::nameInUse($asset->getName());
}

Expand Down
6 changes: 1 addition & 5 deletions src/Auth/Factories/AuthFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ public function resolve(?string $adapter = null): Auth

$adapterClass = $this->getAdapterClass($adapter);

if (!isset($this->instances[$adapter])) {
$this->instances[$adapter] = $this->createInstance($adapterClass, $adapter);
}

return $this->instances[$adapter];
return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Cache/Factories/CacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ public function resolve(?string $adapter = null): Cache

$adapterClass = $this->getAdapterClass($adapter);

if (!isset($this->instances[$adapter])) {
$this->instances[$adapter] = $this->createInstance($adapterClass, $adapter);
}

return $this->instances[$adapter];
return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Captcha/Factories/CaptchaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ public function resolve(?string $adapter = null): Captcha

$adapterClass = $this->getAdapterClass($adapter);

if (!isset($this->instances[$adapter])) {
$this->instances[$adapter] = $this->createInstance($adapterClass, $adapter);
}

return $this->instances[$adapter];
return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function importIfExists(Setup $setup): bool
*/
public function get(string $key, $default = null)
{
if ($this->configs && $this->configs->has($key)) {
if ($this->configs instanceof Data && $this->configs->has($key)) {
return $this->configs->get($key);
}

Expand All @@ -97,7 +97,7 @@ public function all(): ?Data
*/
public function has(string $key): bool
{
return $this->configs && !empty($this->configs->has($key));
return $this->configs instanceof Data && !empty($this->configs->has($key));
}

/**
Expand All @@ -117,7 +117,7 @@ public function set(string $key, $value): void
*/
public function delete(string $key): void
{
$this->configs && $this->configs->remove($key);
$this->configs instanceof Data && $this->configs->remove($key);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Database/Adapters/Sleekdb/SleekDbal.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,7 @@ protected function buildJoinPath(string $currentPath, string $table): string
*/
protected function getQueryBuilder(): QueryBuilder
{
if ($this->queryBuilder === null) {
$this->queryBuilder = $this->getOrmModel()->createQueryBuilder();
}
$this->queryBuilder ??= $this->getOrmModel()->createQueryBuilder();

return $this->queryBuilder;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Debugger/DebuggerStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ class DebuggerStore implements DebuggerStoreInterface
public function init(array $keys): void
{
foreach ($keys as $key) {
if (!isset(self::$store[$key])) {
self::$store[$key] = [];
}
self::$store[$key] ??= [];
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/Di/DiContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,7 @@ private function resolve(string $abstract, array $args = [], bool $singleton = t
$concrete = $this->registry->getConcrete($abstract);

if ($singleton) {
if (!isset($this->container[$abstract])) {
$this->container[$abstract] = $this->instantiate($concrete, $args);
}
$this->container[$abstract] ??= $this->instantiate($concrete, $args);
return $this->container[$abstract];
}

Expand Down
6 changes: 1 addition & 5 deletions src/Encryption/Factories/CryptorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ public static function get(string $type = CryptorType::SYMMETRIC): Cryptor
*/
public function resolve(string $type = CryptorType::SYMMETRIC): Cryptor
{
if (!isset($this->instances[$type])) {
$this->instances[$type] = $this->createInstance($type);
}

return $this->instances[$type];
return $this->instances[$type] ??= $this->createInstance($type);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Environment/Helpers/env.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function environment(): Environment
* @return mixed
* @throws EnvException|DiException|\ReflectionException
*/
function env(string $var, $default = null)
function env(string $var, $default = null): mixed
{
return environment()->getValue($var, $default);
}
8 changes: 4 additions & 4 deletions src/HttpClient/Adapters/CurlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ public function finalizeResponse($rawResponse): void
}

/**
* @return int|string
* @return int
*/
public function getId()
public function getId(): int
{
return $this->id;
}
Expand Down Expand Up @@ -291,9 +291,9 @@ public function getResponseHeaders(): iterable
}

/**
* @return mixed
* @return array<string, mixed>
*/
public function getResponseCookies()
public function getResponseCookies(): array
{
return $this->responseCookies;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lang/Adapters/FileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function get(string $key, array|string $params = null): string
$this->loadTranslations();
}

if ($this->translations && $this->translations->has($key)) {
if ($this->translations instanceof Data && $this->translations->has($key)) {
$message = $this->translations->get($key);
return $params ? _message($message, $params) : $message;
}
Expand Down
6 changes: 1 addition & 5 deletions src/Logger/Factories/LoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ public function resolve(?string $adapter = null): Logger

LoggerConfig::setAppLogLevel($logLevel);

if (!isset($this->instances[$adapter])) {
$this->instances[$adapter] = $this->createInstance($adapterClass, $adapter);
}

return $this->instances[$adapter];
return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Mailer/Factories/MailerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ public function resolve(?string $adapter = null): Mailer

$adapterClass = $this->getAdapterClass($adapter);

if (!isset($this->instances[$adapter])) {
$this->instances[$adapter] = $this->createInstance($adapterClass, $adapter);
}

return $this->instances[$adapter];
return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/RateLimit/Factories/RateLimiterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ public function resolve(?string $adapter = null): RateLimiter
$adapter ??= (string) config()->get('rate_limit.default', RateLimitType::FILE);
$adapterClass = $this->getAdapterClass($adapter);

if (!isset($this->instances[$adapter])) {
$this->instances[$adapter] = $this->createInstance($adapterClass, $adapter);
}

return $this->instances[$adapter];
return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Renderer/Factories/RendererFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ public function resolve(?string $adapter = null): Renderer

$adapterClass = $this->getAdapterClass($adapter);

if (!isset($this->instances[$adapter])) {
$this->instances[$adapter] = $this->createInstance($adapterClass, $adapter);
}

return $this->instances[$adapter];
return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Session/Factories/SessionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ public function resolve(?string $adapter = null): Session

$adapterClass = $this->getAdapterClass($adapter);

if (!isset($this->instances[$adapter])) {
$this->instances[$adapter] = $this->createInstance($adapterClass, $adapter);
}

return $this->instances[$adapter];
return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter);
}

/**
Expand Down
6 changes: 1 addition & 5 deletions src/Storage/Factories/FileSystemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ public function resolve(?string $adapter = null): FileSystem

$adapterClass = $this->getAdapterClass($adapter);

if (!isset($this->instances[$adapter])) {
$this->instances[$adapter] = $this->createInstance($adapterClass, $adapter);
}

return $this->instances[$adapter];
return $this->instances[$adapter] ??= $this->createInstance($adapterClass, $adapter);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ public function getErrors(): array
*/
protected function addError(string $field, string $rule, mixed $param = null): void
{
if (!isset($this->errors[$field])) {
$this->errors[$field] = [];
}
$this->errors[$field] ??= [];

$this->errors[$field][$rule] = $param;
}
Expand Down Expand Up @@ -249,9 +247,7 @@ protected function executeCustomRule(string $rule, mixed $value, ...$params): bo

private function setOrUpdateRule(string $field, string $ruleName, mixed $ruleParam): void
{
if (!isset($this->rules[$field])) {
$this->rules[$field] = [];
}
$this->rules[$field] ??= [];

$this->rules[$field][$ruleName] = $ruleParam;
}
Expand Down
Loading