diff --git a/.config/.php-cs-fixer.dist.php b/.config/.php-cs-fixer.dist.php index 84c13f43..e5171a1e 100644 --- a/.config/.php-cs-fixer.dist.php +++ b/.config/.php-cs-fixer.dist.php @@ -1,5 +1,7 @@ append([ + __FILE__, + __DIR__ . '/rector.php', + ]); $overrides = [ - 'yoda_style' => ['identical' => false], + // 'declare_strict_types' => true, + // 'void_return' => true, ]; $options = [ @@ -23,11 +29,4 @@ 'cacheFile' => '../build/.php-cs-fixer.cache', ]; -return (new PhpCsFixer\Config()) - ->setRules([ - '@PSR12' => true, - 'array_syntax' => ['syntax' => 'short'], - ]) - ->setCacheFile(__DIR__.'/../build/.php-cs-fixer.cache') - ->setFinder($finder) -; +return Factory::create(new CodeIgniter4(), $overrides, $options)->forProjects(); diff --git a/.config/rector.php b/.config/rector.php index b752a285..1267e558 100644 --- a/.config/rector.php +++ b/.config/rector.php @@ -17,10 +17,10 @@ use Rector\CodeQuality\Rector\Foreach_\ForeachToInArrayRector; use Rector\CodeQuality\Rector\Foreach_\SimplifyForeachToCoalescingRector; use Rector\CodeQuality\Rector\FuncCall\ArrayMergeOfNonArraysToSimpleArrayRector; -//use Rector\CodeQuality\Rector\FuncCall\BoolvalToTypeCastRector; +// use Rector\CodeQuality\Rector\FuncCall\BoolvalToTypeCastRector; use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector; use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector; -//use Rector\CodeQuality\Rector\FuncCall\FloatvalToTypeCastRector; +// use Rector\CodeQuality\Rector\FuncCall\FloatvalToTypeCastRector; use Rector\CodeQuality\Rector\FuncCall\InlineIsAInstanceOfRector; use Rector\CodeQuality\Rector\FuncCall\IntvalToTypeCastRector; use Rector\CodeQuality\Rector\FuncCall\SetTypeToCastRector; @@ -91,7 +91,6 @@ use Rector\Renaming\Rector\ClassMethod\RenameAnnotationRector; use Rector\Renaming\Rector\ConstFetch\RenameConstantRector; use Rector\Set\ValueObject\LevelSetList; -use Rector\Set\ValueObject\SetList; use Rector\ValueObject\PhpVersion; /** @@ -151,8 +150,8 @@ $rectorConfig->rule(ArrayKeyExistsTernaryThenValueToCoalescingRector::class); $rectorConfig->rule(ArrayMergeOfNonArraysToSimpleArrayRector::class); $rectorConfig->rule(BooleanNotIdenticalToNotIdenticalRector::class); - //$rectorConfig->rule(BoolvalToTypeCastRector::class); - //$rectorConfig->rule(CallableThisArrayToAnonymousFunctionRector::class); + // $rectorConfig->rule(BoolvalToTypeCastRector::class); + // $rectorConfig->rule(CallableThisArrayToAnonymousFunctionRector::class); $rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class); $rectorConfig->rule(CleanupUnneededNullsafeOperatorRector::class); $rectorConfig->rule(CombineIfRector::class); @@ -163,13 +162,13 @@ $rectorConfig->rule(CompleteMissingIfElseBracketRector::class); $rectorConfig->rule(ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class); $rectorConfig->rule(ConvertStaticPrivateConstantToSelfRector::class); - //$rectorConfig->rule(FloatvalToTypeCastRector::class); + // $rectorConfig->rule(FloatvalToTypeCastRector::class); $rectorConfig->rule(ForRepeatedCountToOwnVariableRector::class); $rectorConfig->rule(ForeachToInArrayRector::class); - //$rectorConfig->rule(GetClassToInstanceOfRector::class); + // $rectorConfig->rule(GetClassToInstanceOfRector::class); $rectorConfig->rule(InlineIfToExplicitIfRector::class); $rectorConfig->rule(InlineIsAInstanceOfRector::class); - //$rectorConfig->rule(IntvalToTypeCastRector::class); + // $rectorConfig->rule(IntvalToTypeCastRector::class); $rectorConfig->rule(JoinStringConcatRector::class); $rectorConfig->rule(NewStaticToNewSelfRector::class); $rectorConfig->rule(NumberCompareToMaxFuncCallRector::class); @@ -194,7 +193,7 @@ $rectorConfig->rule(SingleInArrayToCompareRector::class); $rectorConfig->rule(SingularSwitchToIfRector::class); $rectorConfig->rule(StrlenZeroToIdenticalEmptyStringRector::class); - //$rectorConfig->rule(StrvalToTypeCastRector::class); + // $rectorConfig->rule(StrvalToTypeCastRector::class); $rectorConfig->rule(SwitchNegatedTernaryRector::class); $rectorConfig->rule(SwitchTrueToIfRector::class); $rectorConfig->rule(TernaryEmptyArrayArrayDimFetchToCoalesceRector::class); @@ -222,7 +221,7 @@ $rectorConfig->rule(StaticClosureRector::class); $rectorConfig->rule(SymplifyQuoteEscapeRector::class); $rectorConfig->rule(TernaryConditionVariableAssignmentRector::class); - //$rectorConfig->rule(UseIncrementAssignRector::class); + // $rectorConfig->rule(UseIncrementAssignRector::class); $rectorConfig->rule(VersionCompareFuncCallToConstantRector::class); $rectorConfig->rule(WrapEncapsedVariableInCurlyBracesRector::class); // Removing diff --git a/src/Assets/Controllers/AssetController.php b/src/Assets/Controllers/AssetController.php index 0ec5ab1c..fc45033b 100644 --- a/src/Assets/Controllers/AssetController.php +++ b/src/Assets/Controllers/AssetController.php @@ -61,9 +61,9 @@ public function serve(...$segments) } else { $filename = $origFilename; } - $baseAssetFolders = config('Assets')->folders; // get list of folders with assets + $baseAssetFolders = config('Assets')->folders; // get list of folders with assets $targetBaseAssetFolder = array_shift($segments); // from segments choose the first one as main folder - $folder = $baseAssetFolders[$targetBaseAssetFolder] ?? ROOTPATH . '/somer^3andomWhatever'; // point to folder in the website or a non-existent folder within root path + $folder = $baseAssetFolders[$targetBaseAssetFolder] ?? ROOTPATH . '/somer^3andomWhatever'; // point to folder in the website or a non-existent folder within root path $path = $folder . '/' . implode('/', $segments) . '/' . $filename; if (! is_file($path) || empty($folder)) { diff --git a/src/Assets/Helpers/assets_helper.php b/src/Assets/Helpers/assets_helper.php index 7ae3a9f2..eafb7a59 100644 --- a/src/Assets/Helpers/assets_helper.php +++ b/src/Assets/Helpers/assets_helper.php @@ -8,7 +8,7 @@ * For the full copyright and license information, please view * the LICENSE file that was distributed with this source code. */ -if (!defined('asset_link')) { +if (! defined('asset_link')) { /** * Generates the URL to serve an asset to the client * @@ -56,7 +56,7 @@ function asset_link(string $location, string $type, mixed $attributes = null): s } } -if (!defined('asset')) { +if (! defined('asset')) { function asset(string $location, string $type): string { $config = config('Assets'); @@ -93,12 +93,12 @@ function asset(string $location, string $type): string array_shift($tempSegments); $path = rtrim($config->folders[current($segments)], ' /') . '/' . implode( '/', - $tempSegments + $tempSegments, ) . '/' . $filename; $filetime = filemtime($path); - if (!$filetime) { + if (! $filetime) { throw new RuntimeException('Unable to get modification time of asset file: ' . $filename); } $fingerprint = $separator . $filetime; diff --git a/src/Auth/Actions/Email2FA.php b/src/Auth/Actions/Email2FA.php index b63b0c19..ad00b46d 100644 --- a/src/Auth/Actions/Email2FA.php +++ b/src/Auth/Actions/Email2FA.php @@ -8,8 +8,8 @@ use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\I18n\Time; -use CodeIgniter\Shield\Authentication\Authenticators\Session; use CodeIgniter\Shield\Authentication\Actions\Email2FA as ShieldEmail2FA; +use CodeIgniter\Shield\Authentication\Authenticators\Session; use CodeIgniter\Shield\Entities\User; use CodeIgniter\Shield\Entities\UserIdentity; use CodeIgniter\Shield\Exceptions\RuntimeException; @@ -49,7 +49,6 @@ public function show(): string $this->createIdentity($user); return $this->render(config('Auth')->views['action_email_2fa'], ['user' => $user]); - } /** @@ -94,7 +93,7 @@ public function handle(IncomingRequest $request) $email->setMessage($this->view( setting('Auth.views')['action_email_2fa_email'], ['code' => $identity->secret, 'ipAddress' => $ipAddress, 'userAgent' => $userAgent, 'date' => $date], - ['debug' => false] + ['debug' => false], )); if ($email->send(false) === false) { @@ -105,7 +104,6 @@ public function handle(IncomingRequest $request) $email->clear(); return $this->render(config('Auth')->views['action_email_2fa_verify'], ['user' => $user]); - } /** @@ -132,7 +130,6 @@ public function verify(IncomingRequest $request) session()->setFlashdata('error', lang('Auth.invalid2FAToken')); return $this->render(config('Auth')->views['action_email_2fa_verify']); - } // Get our login redirect url @@ -149,8 +146,7 @@ private function getIdentity(User $user): ?UserIdentity return $identityModel->getIdentityByType( $user, - $this->type + $this->type, ); } - } diff --git a/src/Auth/Actions/EmailActivator.php b/src/Auth/Actions/EmailActivator.php index 11b6e427..58d969f6 100644 --- a/src/Auth/Actions/EmailActivator.php +++ b/src/Auth/Actions/EmailActivator.php @@ -53,7 +53,7 @@ public function show(): string $userEmail = $user->email; if ($userEmail === null) { throw new LogicException( - 'Email Activation needs user email address. user_id: ' . $user->id + 'Email Activation needs user email address. user_id: ' . $user->id, ); } @@ -141,7 +141,7 @@ private function getIdentity(User $user): ?UserIdentity return $identityModel->getIdentityByType( $user, - $this->type + $this->type, ); } } diff --git a/src/Auth/Config/Auth.php b/src/Auth/Config/Auth.php index 92bfcacb..a30621c8 100644 --- a/src/Auth/Config/Auth.php +++ b/src/Auth/Config/Auth.php @@ -2,7 +2,7 @@ namespace Bonfire\Auth\Config; -use CodeIgniter\Config\BaseConfig; +use Bonfire\Users\Models\UserModel; use CodeIgniter\Shield\Authentication\Actions\ActionInterface; use CodeIgniter\Shield\Authentication\AuthenticatorInterface; use CodeIgniter\Shield\Authentication\Authenticators\AccessTokens; @@ -14,7 +14,6 @@ use CodeIgniter\Shield\Authentication\Passwords\NothingPersonalValidator; use CodeIgniter\Shield\Authentication\Passwords\PwnedValidator; use CodeIgniter\Shield\Authentication\Passwords\ValidatorInterface; -use Bonfire\Users\Models\UserModel; use CodeIgniter\Shield\Config\Auth as ShieldAuth; class Auth extends ShieldAuth @@ -130,7 +129,7 @@ class Auth extends ShieldAuth * when using the 'chain' filter. Each Authenticator listed will be checked. * If no match is found, then the next in the chain will be checked. * - * @var string[] + * @var list * @phpstan-var list */ public array $authenticationChain = [ @@ -506,7 +505,7 @@ protected function getUrl(string $url): string $final_url = ''; switch (true) { - case strpos($url, 'http://') === 0 || strpos($url, 'https://') === 0: // URL begins with 'http' or 'https'. E.g. http://example.com + case str_starts_with($url, 'http://') || str_starts_with($url, 'https://') : // URL begins with 'http' or 'https'. E.g. http://example.com $final_url = $url; break; diff --git a/src/Auth/Config/AuthGroups.php b/src/Auth/Config/AuthGroups.php index b2f304b0..5518e233 100644 --- a/src/Auth/Config/AuthGroups.php +++ b/src/Auth/Config/AuthGroups.php @@ -2,7 +2,6 @@ namespace Bonfire\Auth\Config; -use CodeIgniter\Config\BaseConfig; use CodeIgniter\Shield\Config\AuthGroups as ShieldAuthGroups; class AuthGroups extends ShieldAuthGroups diff --git a/src/Auth/Config/AuthToken.php b/src/Auth/Config/AuthToken.php index 55e0834b..2dc4aa25 100644 --- a/src/Auth/Config/AuthToken.php +++ b/src/Auth/Config/AuthToken.php @@ -13,7 +13,6 @@ namespace Bonfire\Auth\Config; -use CodeIgniter\Config\BaseConfig; use CodeIgniter\Shield\Config\AuthToken as ShieldAuthToken; /** diff --git a/src/Auth/Controllers/RegisterController.php b/src/Auth/Controllers/RegisterController.php index b6f93f01..8e25bee1 100644 --- a/src/Auth/Controllers/RegisterController.php +++ b/src/Auth/Controllers/RegisterController.php @@ -36,7 +36,7 @@ protected function getRedirectURL(): string { $url = setting('Auth.redirects')['register']; - return strpos($url, 'http') === 0 + return str_starts_with($url, 'http') ? $url : rtrim(site_url($url), '/ '); } diff --git a/src/Bonfire.php b/src/Bonfire.php index f4acfd4e..457d9f3e 100644 --- a/src/Bonfire.php +++ b/src/Bonfire.php @@ -72,7 +72,7 @@ private function saveInAdmin() $path = parse_url($url, PHP_URL_PATH); - $this->inAdmin = strpos($path, ADMIN_AREA) !== false; + $this->inAdmin = str_contains($path, ADMIN_AREA); } /** diff --git a/src/Commands/BreakingChangesNotification.php b/src/Commands/BreakingChangesNotification.php index 3f24513d..eb6afd78 100644 --- a/src/Commands/BreakingChangesNotification.php +++ b/src/Commands/BreakingChangesNotification.php @@ -22,13 +22,13 @@ public function run(array $params) // Read the changelog file $breakingChangeDate = $this->getLatestBreakingChangeDate($changelogFile); - if ($breakingChangeDate && (!$lastUpdateDate || $lastUpdateDate < $breakingChangeDate)) { + if ($breakingChangeDate && (! $lastUpdateDate || $lastUpdateDate < $breakingChangeDate)) { CLI::write( '======= WARNING: =======' . PHP_EOL . 'Breaking changes since the previous update of your Bonfire install detected. ' . PHP_EOL . 'You may need to update your app manually. ' . PHP_EOL . 'Please read the docs/intro/changelog.md file for more information.', - 'yellow' + 'yellow', ); CLI::write('Latest breaking change date: ' . $breakingChangeDate, 'yellow'); @@ -47,22 +47,24 @@ private function getLastUpdateDate(string $filePath): ?string // Create the file if it does not exist file_put_contents($filePath, ''); + return null; } private function getLatestBreakingChangeDate(string $filePath): ?string { - if (!file_exists($filePath)) { + if (! file_exists($filePath)) { return null; } - $file = fopen($filePath, 'r'); + $file = fopen($filePath, 'rb'); if ($file) { while (($line = fgets($file)) !== false) { - if (strpos($line, '(breaking change)') !== false) { + if (str_contains($line, '(breaking change)')) { preg_match('/## (\d{1,2} \w+ \d{4})/', $line, $matches); if (isset($matches[1])) { fclose($file); + return date('Y-m-d', strtotime($matches[1])); } } diff --git a/src/Commands/Generators/CrudGenerator.php b/src/Commands/Generators/CrudGenerator.php index d081b79a..110782f2 100644 --- a/src/Commands/Generators/CrudGenerator.php +++ b/src/Commands/Generators/CrudGenerator.php @@ -3,11 +3,8 @@ namespace Bonfire\Commands\Generators; use CodeIgniter\CLI\BaseCommand; -use CodeIgniter\CLI\CLI; use CodeIgniter\CLI\GeneratorTrait; use CodeIgniter\Controller; -use CodeIgniter\RESTful\ResourceController; -use CodeIgniter\RESTful\ResourcePresenter; /** * Generates a controller and view files for a CRUD. diff --git a/src/Commands/Install.php b/src/Commands/Install.php index 9815187b..b3bac3c6 100644 --- a/src/Commands/Install.php +++ b/src/Commands/Install.php @@ -15,6 +15,7 @@ use Bonfire\Auth\Config\Auth; use Bonfire\Auth\Config\AuthGroups; use Bonfire\Auth\Config\AuthToken; +use Bonfire\Commands\Install\Publisher; use Bonfire\Config\Bonfire; use Bonfire\Config\Site; use Bonfire\Config\Themes; @@ -22,12 +23,11 @@ use Bonfire\Dashboard\Config\Dashboard; use Bonfire\Recycler\Config\Recycler; use Bonfire\Users\Config\Users; -use CodeIgniter\Encryption\Encryption; -use Bonfire\Commands\Install\Publisher; use Bonfire\Users\Models\UserModel; use Bonfire\Users\User; use CodeIgniter\CLI\BaseCommand; use CodeIgniter\CLI\CLI; +use CodeIgniter\Encryption\Encryption; use Config\Autoload as AutoloadConfig; use ReflectionException; @@ -93,6 +93,7 @@ class Install extends BaseCommand /** * Actually execute a command. + * * @throws ReflectionException */ public function run(array $params) @@ -164,7 +165,7 @@ private function setAppUrl() CLI::newLine(); $url = CLI::prompt('What URL are you running Bonfire under locally?'); - if (strpos($url, 'http://') === false && strpos($url, 'https://') === false) { + if (! str_contains($url, 'http://') && ! str_contains($url, 'https://')) { $url = 'http://' . $url; } @@ -173,9 +174,9 @@ private function setAppUrl() private function setDatabase() { - $host = ''; - $user = ''; - $pass = ''; + $host = ''; + $user = ''; + $pass = ''; $driver = CLI::prompt('Database driver:', ['MySQLi', 'Postgre', 'SQLite3', 'SQLSRV']); $name = CLI::prompt('Database name:', 'bonfire'); if ($driver !== 'SQLite3') { @@ -375,7 +376,6 @@ private function setSecurityCSRF(): void $this->replace($file, $replaces); } - /** * Replace for setupHelper() * @@ -402,7 +402,6 @@ private function replace(string $file, array $replaces): void } error(" Error updating {$cleanPath}."); - } /** @@ -412,37 +411,39 @@ private function updateComposerJson() { $composerJsonPath = ROOTPATH . 'composer.json'; - if (!file_exists($composerJsonPath)) { - CLI::write("composer.json not found.", 'red'); + if (! file_exists($composerJsonPath)) { + CLI::write('composer.json not found.', 'red'); + return; } $composerJson = json_decode(file_get_contents($composerJsonPath), true); if (json_last_error() !== JSON_ERROR_NONE) { - CLI::write("Error decoding composer.json: " . json_last_error_msg(), 'red'); + CLI::write('Error decoding composer.json: ' . json_last_error_msg(), 'red'); + return; } // Ensure the scripts section exists - if (!isset($composerJson['scripts'])) { + if (! isset($composerJson['scripts'])) { $composerJson['scripts'] = []; } // Ensure the post-update-cmd section exists - if (!isset($composerJson['scripts']['post-update-cmd'])) { + if (! isset($composerJson['scripts']['post-update-cmd'])) { $composerJson['scripts']['post-update-cmd'] = []; } // Add the Bonfire update script if it's not already present - $bonfireUpdateScript = "php spark notify:breaking-changes"; - if (!in_array($bonfireUpdateScript, $composerJson['scripts']['post-update-cmd'])) { + $bonfireUpdateScript = 'php spark notify:breaking-changes'; + if (! in_array($bonfireUpdateScript, $composerJson['scripts']['post-update-cmd'], true)) { $composerJson['scripts']['post-update-cmd'][] = $bonfireUpdateScript; } // Save the updated composer.json file_put_contents($composerJsonPath, json_encode($composerJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); - CLI::write("composer.json updated successfully.", 'green'); + CLI::write('composer.json updated successfully.', 'green'); } } diff --git a/src/Commands/Install/Publisher.php b/src/Commands/Install/Publisher.php index ef5f3066..023aa822 100644 --- a/src/Commands/Install/Publisher.php +++ b/src/Commands/Install/Publisher.php @@ -63,9 +63,9 @@ public function publishClass(string $className): void $content = file_get_contents($file); $replace = [ - $namespace => 'Config', - 'BaseConfig' => 'Bonfire' . $rawClassName, - 'use CodeIgniter\Config\BaseConfig;' => "use {$className} as Bonfire{$rawClassName};", + $namespace => 'Config', + 'BaseConfig' => 'Bonfire' . $rawClassName, + 'use CodeIgniter\Config\BaseConfig;' => "use {$className} as Bonfire{$rawClassName};", "class {$rawClassName} extends Shield{$rawClassName}" => "class {$rawClassName} extends Bonfire{$rawClassName}", ]; diff --git a/src/Config/Registrar.php b/src/Config/Registrar.php index c88ad3e1..441edc93 100644 --- a/src/Config/Registrar.php +++ b/src/Config/Registrar.php @@ -7,7 +7,6 @@ use Bonfire\Core\Filters\OnlineCheck; use Bonfire\Users\Validation\UserRules; use Bonfire\View\Decorator; -use CodeIgniter\Autoloader\Autoloader; use CodeIgniter\Shield\Authentication\Passwords\ValidationRules as PasswordRules; use CodeIgniter\Shield\Filters\ChainAuth; use CodeIgniter\Shield\Filters\SessionAuth; @@ -96,6 +95,4 @@ public static function View() ], ]; } - - } diff --git a/src/Config/Services.php b/src/Config/Services.php index 70a3610d..5373546b 100644 --- a/src/Config/Services.php +++ b/src/Config/Services.php @@ -41,7 +41,7 @@ public static function bonfire(bool $getShared = true) /** * Returns the system menu manager * - * @return \Bonfire\Menus\Manager + * @return MenuManager */ public static function menus(bool $getShared = true) { @@ -56,7 +56,7 @@ public static function menus(bool $getShared = true) * Returns the Resource Tab manager that integrates * extra tabs into resources like Users, User Groups, etc. * - * @return ResourceTabs|mixed + * @return mixed|ResourceTabs */ public static function resourceTabs(bool $getShared = true) { diff --git a/src/Consent/Controllers/ConsentSettingsController.php b/src/Consent/Controllers/ConsentSettingsController.php index 56bdae76..bf660d92 100644 --- a/src/Consent/Controllers/ConsentSettingsController.php +++ b/src/Consent/Controllers/ConsentSettingsController.php @@ -46,7 +46,7 @@ public function save() 'requireConsent' => 'permit_empty', 'consentLength' => 'required_with[requireConsent]|string', 'policyUrl' => 'required_with[requireConsent]|string', - 'policyTitle' => 'required_with[requireConsent]|string', + 'policyTitle' => 'required_with[requireConsent]|string', 'consentMessage' => 'required_with[requireConsent]|string', 'consents.*.name' => 'required_with[requireConsent]|string', 'consents.*.desc' => 'required_with[requireConsent]|string', diff --git a/src/Consent/Filters/ConsentFilter.php b/src/Consent/Filters/ConsentFilter.php index 53d3da32..92a9db17 100644 --- a/src/Consent/Filters/ConsentFilter.php +++ b/src/Consent/Filters/ConsentFilter.php @@ -68,11 +68,11 @@ public function after(RequestInterface $request, ResponseInterface $response, $a ]); // Replace {policy_url} with the actual link. $link = setting('Consent.policyUrl'); - $link = strpos('http', (string) $link) === 0 + $link = str_starts_with('http', (string) $link) ? $link : site_url($link); $policyTitle = setting('Consent.policyTitle'); - $html = str_ireplace('{policy_url}', "{$policyTitle}", $html); + $html = str_ireplace('{policy_url}', "{$policyTitle}", $html); $cssFile = setting('Consent.consentFormStyles'); $jsFile = setting('Consent.consentFormScripts'); diff --git a/src/Consent/Language/en/Consent.php b/src/Consent/Language/en/Consent.php index caad9cfc..15f52844 100644 --- a/src/Consent/Language/en/Consent.php +++ b/src/Consent/Language/en/Consent.php @@ -10,5 +10,5 @@ */ return [ - 'consentModTitle' => 'Consent', + 'consentModTitle' => 'Consent', ]; diff --git a/src/Consent/Language/it/Consent.php b/src/Consent/Language/it/Consent.php index 0f024af3..a6d0366c 100644 --- a/src/Consent/Language/it/Consent.php +++ b/src/Consent/Language/it/Consent.php @@ -10,5 +10,5 @@ */ return [ - 'consentModTitle' => 'Consenso', + 'consentModTitle' => 'Consenso', ]; diff --git a/src/Consent/Language/lt/Consent.php b/src/Consent/Language/lt/Consent.php index c8ab7f1d..032a2886 100644 --- a/src/Consent/Language/lt/Consent.php +++ b/src/Consent/Language/lt/Consent.php @@ -10,5 +10,5 @@ */ return [ - 'consentModTitle' => 'Sutikimas (BDAR)', + 'consentModTitle' => 'Sutikimas (BDAR)', ]; diff --git a/src/Core/Traits/SearchInMeta.php b/src/Core/Traits/SearchInMeta.php index e8d2ac9e..acc9dd4f 100644 --- a/src/Core/Traits/SearchInMeta.php +++ b/src/Core/Traits/SearchInMeta.php @@ -19,30 +19,34 @@ trait SearchInMeta * @param string $className The resource entity class namespaced name that the * data is associated with in meta_info table. * @param string $tableName The name of the table to join meta_info to. + * * @return $this */ public function joinMetaInfo($className, $tableName) { $this->join('meta_info m', $tableName . '.id = m.resource_id AND m.class = "' . $className . '"', 'left'); + return $this; } /** * Custom method to do a like query on meta_info table during search. * - * @param string $field The key to search for. - * @param mixed $match The value to search for. - * @param string $side The side to add the wildcard ('both', 'left', 'right', or 'none'). - * @param bool|null $escape Whether to escape the value. - * @param bool $insensitiveSearch Whether to perform a case-insensitive search. + * @param string $field The key to search for. + * @param mixed $match The value to search for. + * @param string $side The side to add the wildcard ('both', 'left', 'right', or 'none'). + * @param bool|null $escape Whether to escape the value. + * @param bool $insensitiveSearch Whether to perform a case-insensitive search. + * * @return $this */ public function orLikeInMetaInfo($field, $match, $side = 'both', $escape = null, $insensitiveSearch = false) { $this->orGroupStart() - ->where('m.key', $field) - ->like('m.value', $match, $side, $escape, $insensitiveSearch) - ->groupEnd(); + ->where('m.key', $field) + ->like('m.value', $match, $side, $escape, $insensitiveSearch) + ->groupEnd(); + return $this; } } diff --git a/src/Email/Language/en/Email.php b/src/Email/Language/en/Email.php index c0050faa..bb5fb2fc 100644 --- a/src/Email/Language/en/Email.php +++ b/src/Email/Language/en/Email.php @@ -10,5 +10,5 @@ */ return [ - 'emailModTitle' => 'Email', + 'emailModTitle' => 'Email', ]; diff --git a/src/Email/Language/it/Email.php b/src/Email/Language/it/Email.php index c0050faa..bb5fb2fc 100644 --- a/src/Email/Language/it/Email.php +++ b/src/Email/Language/it/Email.php @@ -10,5 +10,5 @@ */ return [ - 'emailModTitle' => 'Email', + 'emailModTitle' => 'Email', ]; diff --git a/src/Email/Language/lt/Email.php b/src/Email/Language/lt/Email.php index dcb75b74..15ca0ccb 100644 --- a/src/Email/Language/lt/Email.php +++ b/src/Email/Language/lt/Email.php @@ -10,5 +10,5 @@ */ return [ - 'emailModTitle' => 'El. laiškai', + 'emailModTitle' => 'El. laiškai', ]; diff --git a/src/Groups/Language/en/Groups.php b/src/Groups/Language/en/Groups.php index d8ae6add..29f3c5bc 100644 --- a/src/Groups/Language/en/Groups.php +++ b/src/Groups/Language/en/Groups.php @@ -10,5 +10,5 @@ */ return [ - 'groupsModTitle' => 'User Groups', + 'groupsModTitle' => 'User Groups', ]; diff --git a/src/Groups/Language/it/Groups.php b/src/Groups/Language/it/Groups.php index 80871f49..1a4493fc 100644 --- a/src/Groups/Language/it/Groups.php +++ b/src/Groups/Language/it/Groups.php @@ -10,5 +10,5 @@ */ return [ - 'groupsModTitle' => 'Ruoli', + 'groupsModTitle' => 'Ruoli', ]; diff --git a/src/Groups/Language/lt/Groups.php b/src/Groups/Language/lt/Groups.php index 2181bda3..b826f9c3 100644 --- a/src/Groups/Language/lt/Groups.php +++ b/src/Groups/Language/lt/Groups.php @@ -10,5 +10,5 @@ */ return [ - 'groupsModTitle' => 'Vartotojų grupės', + 'groupsModTitle' => 'Vartotojų grupės', ]; diff --git a/src/Menus/HasMenuIcons.php b/src/Menus/HasMenuIcons.php index e0a4381d..0df36b35 100644 --- a/src/Menus/HasMenuIcons.php +++ b/src/Menus/HasMenuIcons.php @@ -112,7 +112,7 @@ protected function buildImageIconTag(string $class): string { $class = empty($class) ? '' : "class=\"{$class}\" "; - $iconUrl = strpos($this->iconUrl, '://') !== false + $iconUrl = str_contains($this->iconUrl, '://') ? $this->iconUrl : '/' . ltrim($this->iconUrl, '/ '); diff --git a/src/Menus/Manager.php b/src/Menus/Manager.php index dc7d3a7e..17a1fc4d 100644 --- a/src/Menus/Manager.php +++ b/src/Menus/Manager.php @@ -22,7 +22,7 @@ * * The main class used to work with menus in the system. * - * @method self createMenu(string $name) + * @method self createMenu(string $name) * @method Menu menu(string $name) */ class Manager @@ -30,7 +30,7 @@ class Manager /** * A collection of menus currently known about. * - * @var array array of `\Bonfire\Menus\Menu` + * @var list array of `\Bonfire\Menus\Menu` */ private array $_menus = []; @@ -50,8 +50,6 @@ public function createMenu(string $name): self * Returns the specified menu instance * * @param string $name Menu's name - * - * @return Menu */ public function menu(string $name): Menu { diff --git a/src/Menus/Menu.php b/src/Menus/Menu.php index df69159c..d3f09022 100644 --- a/src/Menus/Menu.php +++ b/src/Menus/Menu.php @@ -28,14 +28,14 @@ class Menu * Holds all Menu items or Menu collections that appear at * top level in this menu. * - * @var array<(MenuCollection | MenuItem)> + * @var list<(MenuCollection | MenuItem)> */ protected array $items = []; /** * Returns all Menu items or Menu collections in the menu. * - * @return array<(MenuCollection | MenuItem)> + * @return list<(MenuCollection | MenuItem)> */ public function items(): array { @@ -61,8 +61,6 @@ public function addItem(MenuItem $item): self * * @param string $name name or slug of the new Menu Collection * @param string $title Title of the new Menu Collection - * - * @return MenuCollection */ public function createCollection(string $name, string $title): MenuCollection { @@ -80,8 +78,6 @@ public function createCollection(string $name, string $title): MenuCollection * * @param string $name name of Menu Collection * @param array $items Array of Menu Item - * - * @return MenuCollection */ public function collect(string $name, array $items): MenuCollection { @@ -125,7 +121,7 @@ public function collection(string $name) /** * Returns an array of all collections stored, if any. * - * @return array + * @return list */ public function collections(): array { diff --git a/src/Menus/MenuCollection.php b/src/Menus/MenuCollection.php index c4f616c5..e5938962 100644 --- a/src/Menus/MenuCollection.php +++ b/src/Menus/MenuCollection.php @@ -32,7 +32,7 @@ class MenuCollection extends MenuItem /** * Holds all Menu items of a collection * - * @var array + * @var list */ protected array $items = []; @@ -101,7 +101,7 @@ public function addItem(MenuItem $item): self /** * Add multiple Menu items at once. * - * @param array $items list of MenuItem Instance + * @param list $items list of MenuItem Instance */ public function addItems(array $items): self { @@ -118,6 +118,7 @@ public function addItems(array $items): self public function removeItem(string $title): void { $counter = count($this->items); + for ($i = 0; $i < $counter; $i++) { if ($this->items[$i]->title() === $title) { unset($this->items[$i]); @@ -140,7 +141,7 @@ public function removeAllItems(): self * Returns all items in the Collection, sorted by weight, * where larger weights make them fall to the bottom. * - * @return array + * @return list */ public function items(): array { @@ -175,7 +176,7 @@ static function ($a, $b) { } return $a->weight <=> $b->weight; - } + }, ); } diff --git a/src/Menus/MenuItem.php b/src/Menus/MenuItem.php index 478b44ab..563dd203 100644 --- a/src/Menus/MenuItem.php +++ b/src/Menus/MenuItem.php @@ -110,7 +110,7 @@ public function setTitle(string $title): self */ public function setUrl(string $url): self { - $this->url = strpos($url, '://') !== false ? $url : '/' . ltrim($url, '/ '); + $this->url = str_contains($url, '://') ? $url : '/' . ltrim($url, '/ '); return $this; } diff --git a/src/Recycler/Controllers/RecycleController.php b/src/Recycler/Controllers/RecycleController.php index e40582b0..66c78d6d 100644 --- a/src/Recycler/Controllers/RecycleController.php +++ b/src/Recycler/Controllers/RecycleController.php @@ -54,9 +54,7 @@ public function viewResource() ->paginate(setting('Site.perPage')); // localize resources if possible - $resources = array_map(function ($resource) { - return $this->localizeResource($resource); - }, $resources); + $resources = array_map(fn ($resource) => $this->localizeResource($resource), $resources); return $this->render($this->viewPrefix . 'listResource', [ 'resources' => $resources, @@ -140,17 +138,16 @@ public function purge(string $resourceType, int $resourceId) */ public function localizeResource(array $resource): array { - - //dd($resource); + // dd($resource); foreach ($resource['columns'] as $colKey => $colName) { - $key = $resource['label'] . '.recycler.columns.' . $colName; - $value = lang($key); - $resource['localizedColumns'][$colKey] = $key == $value ? $resource['columns'][$colKey] : $value; + $key = $resource['label'] . '.recycler.columns.' . $colName; + $value = lang($key); + $resource['localizedColumns'][$colKey] = $key === $value ? $resource['columns'][$colKey] : $value; } - $key = $resource['label'] . '.recycler.label'; - $value = lang($key); - $resource['label'] = $key == $value ? $resource['label'] : $value; + $key = $resource['label'] . '.recycler.label'; + $value = lang($key); + $resource['label'] = $key === $value ? $resource['label'] : $value; return $resource; } diff --git a/src/Recycler/Language/lt/Recycler.php b/src/Recycler/Language/lt/Recycler.php index b1e2b37b..d7f250ea 100644 --- a/src/Recycler/Language/lt/Recycler.php +++ b/src/Recycler/Language/lt/Recycler.php @@ -10,7 +10,7 @@ 'restoreMsgContent' => 'Atkurti šį įrašą?', 'purgeMsgTitle' => 'Ištrinti amžiams', 'purgeMsgContent' => 'Ištrinti įrašą visam laikui?', - 'resultLabel' => '{0, plural, + 'resultLabel' => '{0, plural, =0 {# įrašų} =1 {# įrašas} one {# įrašas} diff --git a/src/Resources/ResourceTab.php b/src/Resources/ResourceTab.php index dab03a7d..ae105672 100644 --- a/src/Resources/ResourceTab.php +++ b/src/Resources/ResourceTab.php @@ -71,7 +71,7 @@ public function getUrl(): string $url = $this->url; - if (strpos($this->url, '(id)') !== false) { + if (str_contains($this->url, '(id)')) { $url = $this->fillPlaceholder($url); } diff --git a/src/Settings/Controllers/GeneralSettingsController.php b/src/Settings/Controllers/GeneralSettingsController.php index b7df82d5..7a71d9a2 100644 --- a/src/Settings/Controllers/GeneralSettingsController.php +++ b/src/Settings/Controllers/GeneralSettingsController.php @@ -11,8 +11,8 @@ namespace Bonfire\Settings\Controllers; -use CodeIgniter\HTTP\RedirectResponse; use Bonfire\Core\AdminController; +use CodeIgniter\HTTP\RedirectResponse; use DateTimeZone; /** @@ -41,7 +41,7 @@ public function general() $timezoneAreas = []; foreach (timezone_identifiers_list() as $timezone) { - if (strpos($timezone, '/') === false) { + if (! str_contains($timezone, '/')) { $timezoneAreas[] = $timezone; continue; @@ -54,7 +54,7 @@ public function general() } $currentTZ = setting('App.appTimezone'); - $currentTZArea = strpos($currentTZ, '/') === false + $currentTZArea = ! str_contains($currentTZ, '/') ? $currentTZ : substr($currentTZ, 0, strpos($currentTZ, '/')); diff --git a/src/Tools/Controllers/LogsController.php b/src/Tools/Controllers/LogsController.php index d10c2710..67ab902b 100644 --- a/src/Tools/Controllers/LogsController.php +++ b/src/Tools/Controllers/LogsController.php @@ -44,9 +44,7 @@ public function index() // Define the regular expression pattern for log files $logPattern = '/^log-\d{4}-\d{2}-\d{2}\.log$/'; // Filter the array removing index.html and other files that do not match - $logs = array_filter($logs, function ($filename) use ($logPattern) { - return preg_match($logPattern, $filename); - }); + $logs = array_filter($logs, static fn ($filename) => preg_match($logPattern, $filename)); $result = $this->logsHandler->paginateLogs($logs, $this->logsLimit); @@ -54,12 +52,13 @@ public function index() for ($i = 0; $i < count($result['logs']); $i++) { if ($result['logs'][$i] === 'index.html') { unset($result['logs'][$i]); + continue; } - $logFilePath = $this->logsPath . $result['logs'][$i]; + $logFilePath = $this->logsPath . $result['logs'][$i]; $result['logs'][$i] = [ 'filename' => $result['logs'][$i], - 'content' => $this->logsHandler->countLogLevels($logFilePath), + 'content' => $this->logsHandler->countLogLevels($logFilePath), ]; } @@ -114,7 +113,7 @@ public function delete() if (empty($delete) && empty($deleteAll)) { return redirect()->to(ADMIN_AREA . '/tools/logs')->with( 'error', - lang('Bonfire.resourcesNotFound', ['logs']) + lang('Bonfire.resourcesNotFound', ['logs']), ); } diff --git a/src/Tools/Language/lt/Tools.php b/src/Tools/Language/lt/Tools.php index 4acb2cd1..e8ccdf2f 100644 --- a/src/Tools/Language/lt/Tools.php +++ b/src/Tools/Language/lt/Tools.php @@ -10,22 +10,22 @@ */ return [ - 'systemInfoModTitle' => 'Sistemos info', - 'logsModTitle' => 'Žurnalai', - 'log' => 'Žurnalas', - 'empty' => 'Žurnalų failų nėra.', - 'level' => 'Lygmuo', - 'date' => 'Data', - 'time' => 'Laikas', - 'file' => 'Failo pavadinimas', - 'content' => 'Turinys', - 'deleteFile' => 'Trinti žurnalo failą', - 'deleteSelected' => 'Trinti pažymėtus', - 'deleteAll' => 'Trinti visus žurnalų failus', - 'deleteConfirm' => 'Ar tikrai norite ištrinti šį failą?', - 'deleteSelectedConfirm' => 'Ar tikrai norite ištrinti visus pažymėtus failus?', - 'deleteAllConfirm' => 'Ar tikrai norite ištrinti visus žurnalų failus?', - 'deleteSuccess' => 'Failas(-ai) sėkmingai ištrintas(-i).', - 'deleteAllSuccess' => 'Visi failai buvo sėkmingai ištrinti.', - 'deleteError' => 'Nepavyksta ištrinti.', + 'systemInfoModTitle' => 'Sistemos info', + 'logsModTitle' => 'Žurnalai', + 'log' => 'Žurnalas', + 'empty' => 'Žurnalų failų nėra.', + 'level' => 'Lygmuo', + 'date' => 'Data', + 'time' => 'Laikas', + 'file' => 'Failo pavadinimas', + 'content' => 'Turinys', + 'deleteFile' => 'Trinti žurnalo failą', + 'deleteSelected' => 'Trinti pažymėtus', + 'deleteAll' => 'Trinti visus žurnalų failus', + 'deleteConfirm' => 'Ar tikrai norite ištrinti šį failą?', + 'deleteSelectedConfirm' => 'Ar tikrai norite ištrinti visus pažymėtus failus?', + 'deleteAllConfirm' => 'Ar tikrai norite ištrinti visus žurnalų failus?', + 'deleteSuccess' => 'Failas(-ai) sėkmingai ištrintas(-i).', + 'deleteAllSuccess' => 'Visi failai buvo sėkmingai ištrinti.', + 'deleteError' => 'Nepavyksta ištrinti.', ]; diff --git a/src/Tools/Libraries/Logs.php b/src/Tools/Libraries/Logs.php index 1fb3d5f4..17859603 100644 --- a/src/Tools/Libraries/Logs.php +++ b/src/Tools/Libraries/Logs.php @@ -11,6 +11,8 @@ namespace Bonfire\Tools\Libraries; +use DateTime; + /** * Provides view cells for Users */ @@ -111,7 +113,7 @@ public function countLogLevels($filePath): string $fileContent = file_get_contents($filePath); if ($fileContent === false) { - throw new Exception("Unable to read the file: $filePath"); + throw new Exception("Unable to read the file: {$filePath}"); } // Count occurrences of each level @@ -120,24 +122,21 @@ public function countLogLevels($filePath): string } // Remove entries with value 0 - $counts = array_filter($counts, function ($value) { - return $value > 0; - }); + $counts = array_filter($counts, static fn ($value) => $value > 0); $counts = array_reverse($counts); - // Transform the array into a string with color codes $result = []; + foreach ($counts as $level => $count) { - $class = self::$levelClasses[$level]; + $class = self::$levelClasses[$level]; $result[] = '' . $level . ': ' . $count; } return strtolower(implode(', ', $result)); } - /** * returns an array of the file contents * each element in the array is a line @@ -181,15 +180,18 @@ public function paginateLogs(array $logs, int $limit) /** * Retrieves the adjacent log files (previous and next) relative to the given log file. * - * @param string $currentFile The current log file name. - * @param array $logFiles An array of all log file names. + * @param string $currentFile The current log file name. + * @param array $logFiles An array of all log file names. + * @param mixed $currentLogFileBasename + * @param mixed $logsPath + * * @return array An associative array with 'previous' and 'next' keys containing the respective log file names, or null if not available. */ public function getAdjacentLogFiles($currentLogFileBasename, $logsPath): array { // Extract the date from the current log file name preg_match('/log-(\d{4}-\d{2}-\d{2})/', $currentLogFileBasename, $matches); - $currentDate = new \DateTime($matches[1]); + $currentDate = new DateTime($matches[1]); // Retrieve the list of log files in the directory $logFiles = glob($logsPath . '/log-*.log'); @@ -216,14 +218,14 @@ public function getAdjacentLogFiles($currentLogFileBasename, $logsPath): array return [ 'prev' => [ - 'link' => $previousLogFileBasename, + 'link' => $previousLogFileBasename, 'label' => substr($previousLogFileBasename ?? '', 4, 10), ], - 'curr' => [ + 'curr' => [ 'label' => substr($currentLogFileBasename, 4, 10), ], 'next' => [ - 'link' => $nextLogFileBasename, + 'link' => $nextLogFileBasename, 'label' => substr($nextLogFileBasename ?? '', 4, 10), ], ]; diff --git a/src/Users/Config/Users.php b/src/Users/Config/Users.php index 484c8cc7..cce98d65 100644 --- a/src/Users/Config/Users.php +++ b/src/Users/Config/Users.php @@ -55,7 +55,6 @@ class Users extends BaseConfig * -------------------------------------------------------------------------- * relative to FCPATH and base_url */ - public $avatarDirectory = 'uploads/avatars'; /** @@ -70,7 +69,8 @@ class Users extends BaseConfig * toolbar avatar size) */ public $avatarResize = false; - public $avatarSize = 140; + + public $avatarSize = 140; public $avatarResizeFloor = 32; /** @@ -141,7 +141,6 @@ class Users extends BaseConfig * ], * ], */ - public $metaFields = [ 'Example Fields' => [ 'blog' => ['label' => 'Blog', 'type' => 'text', 'validation' => 'permit_empty|valid_url_strict'], @@ -149,13 +148,12 @@ class Users extends BaseConfig ]; /** - * -------------------------------------------------------------------------- - * Search in additional fields - * -------------------------------------------------------------------------- - * To enable search in additional user fields, add the field names to this array. - * - */ + * -------------------------------------------------------------------------- + * Search in additional fields + * -------------------------------------------------------------------------- + * To enable search in additional user fields, add the field names to this array. + */ public $includeMetaFieldsInSearech = [ - 'blog', + 'blog', ]; } diff --git a/src/Users/Controllers/UserController.php b/src/Users/Controllers/UserController.php index 2fd9c38a..38f7ec12 100644 --- a/src/Users/Controllers/UserController.php +++ b/src/Users/Controllers/UserController.php @@ -11,11 +11,11 @@ namespace Bonfire\Users\Controllers; -use CodeIgniter\HTTP\RedirectResponse; use Bonfire\Core\AdminController; use Bonfire\Users\Models\UserFilter; use Bonfire\Users\Models\UserModel; use Bonfire\Users\User; +use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\Shield\Models\LoginModel; use CodeIgniter\Shield\Models\UserIdentityModel; use ReflectionException; diff --git a/src/Users/Database/Seeds/Seed100Users.php b/src/Users/Database/Seeds/Seed100Users.php index 81bb9c23..2f274042 100644 --- a/src/Users/Database/Seeds/Seed100Users.php +++ b/src/Users/Database/Seeds/Seed100Users.php @@ -9,26 +9,26 @@ class Seed100Users extends Seeder { public function run() { - $faker = Factory::create(); + $faker = Factory::create(); $groups = ['user', 'beta', 'developer']; for ($i = 0; $i < 100; $i++) { $timestamp = $faker->dateTimeBetween('-1 year', 'now')->format('Y-m-d H:i:s'); $firstName = $faker->firstName; - $lastName = $faker->lastName; - $username = substr($this->toAscii($firstName), 0, 5) . substr($this->toAscii($lastName), 0, 5); - $active = $faker->boolean; - $email = strtolower($this->toAscii($firstName) . '.' . $this->toAscii($lastName) . '@example.com'); - $secret2 = $faker->sha256; + $lastName = $faker->lastName; + $username = substr($this->toAscii($firstName), 0, 5) . substr($this->toAscii($lastName), 0, 5); + $active = $faker->boolean; + $email = strtolower($this->toAscii($firstName) . '.' . $this->toAscii($lastName) . '@example.com'); + $secret2 = $faker->sha256; // Insert into users table $this->db->table('users')->insert([ - 'first_name' => $firstName, - 'last_name' => $lastName, - 'username' => $username, - 'active' => $active, - 'created_at' => $timestamp, - 'updated_at' => $timestamp, + 'first_name' => $firstName, + 'last_name' => $lastName, + 'username' => $username, + 'active' => $active, + 'created_at' => $timestamp, + 'updated_at' => $timestamp, 'last_active' => $timestamp, ]); @@ -38,15 +38,15 @@ public function run() // Insert into auth_identities table $this->db->table('auth_identities')->insert([ 'user_id' => $userId, - 'type' => 'email_password', - 'secret' => $email, + 'type' => 'email_password', + 'secret' => $email, 'secret2' => $secret2, ]); // Insert into auth_groups_users table $this->db->table('auth_groups_users')->insert([ - 'user_id' => $userId, - 'group' => $faker->randomElement($groups), + 'user_id' => $userId, + 'group' => $faker->randomElement($groups), 'created_at' => $timestamp, ]); } diff --git a/src/Users/Language/lt/Users.php b/src/Users/Language/lt/Users.php index 99f24c5e..fef8c7c1 100644 --- a/src/Users/Language/lt/Users.php +++ b/src/Users/Language/lt/Users.php @@ -1,15 +1,15 @@ 'Vartotojai', - 'editUser' => 'Keisti vartotoją', - 'newUser' => 'Naujas vartotojas', - 'users' => 'Vartotojai', - 'user' => 'Vartotojas', - 'userGenitive' => 'vartotojo', - 'userAccusative' => 'vartotoją', + 'usersModTitle' => 'Vartotojai', + 'editUser' => 'Keisti vartotoją', + 'newUser' => 'Naujas vartotojas', + 'users' => 'Vartotojai', + 'user' => 'Vartotojas', + 'userGenitive' => 'vartotojo', + 'userAccusative' => 'vartotoją', 'usersAccusative' => 'vartotojus', - 'permissions' => 'Leidimai', + 'permissions' => 'Leidimai', // avatar 'deleteImageConfirm' => 'Ar tikrai norite pašalinti paveikslėlį? Jo atkurti nebus galima', 'deleteImage' => 'Ištrinti įkeltą paveikslėlį', diff --git a/src/Users/Libraries/UserCells.php b/src/Users/Libraries/UserCells.php index 53ececc9..452466e5 100644 --- a/src/Users/Libraries/UserCells.php +++ b/src/Users/Libraries/UserCells.php @@ -16,8 +16,7 @@ */ class UserCells { - protected $viewPrefix = 'Bonfire\Users\Views\\'; - + protected $viewPrefix = 'Bonfire\Users\Views\\'; protected string $configClass = 'Users'; /** diff --git a/src/Users/Models/UserModel.php b/src/Users/Models/UserModel.php index 532dec2e..0a935113 100644 --- a/src/Users/Models/UserModel.php +++ b/src/Users/Models/UserModel.php @@ -18,9 +18,8 @@ class UserModel extends ShieldUsers 'username', 'status', 'status_message', 'active', 'last_active', 'deleted_at', 'avatar', 'first_name', 'last_name', ]; - protected $allowCallbacks = true; - protected $beforeDelete = ['deleteAvatar']; + protected $beforeDelete = ['deleteAvatar']; /** * Performs additional setup when finding objects @@ -59,13 +58,13 @@ public function fake(Generator &$faker): User public function deleteAvatar(array $data): array { // if it is a soft delete, return at once - if (!$data['purge']) { + if (! $data['purge']) { return $data; } $user = $this->withDeleted()->find($data['id'][0]); // Retrieve the entity - if (!$user) { + if (! $user) { return $data; } @@ -74,7 +73,7 @@ public function deleteAvatar(array $data): array $avatarDir = FCPATH . (setting('Users.avatarDirectory') ?? 'uploads/avatars'); if ( - !empty($userAvatar) + ! empty($userAvatar) && file_exists($avatarDir . '/' . $userAvatar) ) { @unlink($avatarDir . '/' . $userAvatar); diff --git a/src/Users/SearchProvider.php b/src/Users/SearchProvider.php index e81a756f..d2426416 100644 --- a/src/Users/SearchProvider.php +++ b/src/Users/SearchProvider.php @@ -11,13 +11,14 @@ namespace Bonfire\Users; +use Bonfire\Core\Traits\SearchInMeta; use Bonfire\Search\Interfaces\SearchProviderInterface; use Bonfire\Users\Models\UserModel; -use Bonfire\Core\Traits\SearchInMeta; class SearchProvider extends UserModel implements SearchProviderInterface { use SearchInMeta; + /** * Performs a primary search for just this resource. */ @@ -31,7 +32,7 @@ public function search(string $term, int $limit = 10, ?array $post = null): arra $searchInMeta = setting('Users.includeMetaFieldsInSearech'); - if (!empty($searchInMeta)) { + if (! empty($searchInMeta)) { // TODO: find a better way to access both of these variables - // Entity to which the data is assigned and table name to join meta_info with $query->joinMetaInfo('Bonfire\Users\User', 'users'); @@ -42,7 +43,7 @@ public function search(string $term, int $limit = 10, ?array $post = null): arra ->orLike('username', $term, 'right', true, true) ->orLike('secret', $term, 'both', true, true); - if (!empty($searchInMeta)) { + if (! empty($searchInMeta)) { foreach ($searchInMeta as $metaField) { $query->orLikeInMetaInfo($metaField, $term, 'both', true, true); } diff --git a/src/Users/User.php b/src/Users/User.php index f9225b41..f38f40c0 100644 --- a/src/Users/User.php +++ b/src/Users/User.php @@ -63,10 +63,11 @@ public function avatarLink(?int $size = null): string // Default from Gravatar if (isset($this->id) && empty($this->avatar) && setting('Users.useGravatar')) { $hash = md5(strtolower(trim($this->email))); + return "https://www.gravatar.com/avatar/{$hash}?" . http_build_query([ 's' => ($size ?? 60), 'd' => setting( - 'Users.gravatarDefault' + 'Users.gravatarDefault', ), ]); } diff --git a/src/View/Component.php b/src/View/Component.php index 8b597e7e..669ed9ee 100644 --- a/src/View/Component.php +++ b/src/View/Component.php @@ -78,6 +78,7 @@ protected function renderView(string $view, array $data): string extract($data); ob_start(); eval('?>' . file_get_contents($view)); + return ob_get_clean() ?: ''; })($view, $data); } diff --git a/src/View/ComponentRenderer.php b/src/View/ComponentRenderer.php index 2453e4ed..844b6622 100644 --- a/src/View/ComponentRenderer.php +++ b/src/View/ComponentRenderer.php @@ -12,6 +12,7 @@ namespace Bonfire\View; use RuntimeException; +use Throwable; class ComponentRenderer { @@ -120,19 +121,19 @@ private function renderPairedTags(string $output): string do { try { $output = preg_replace_callback($pattern, function ($match) { - $view = $this->locateView($match['name']); - $attributes = $this->parseAttributes($match['attributes']); + $view = $this->locateView($match['name']); + $attributes = $this->parseAttributes($match['attributes']); $attributes['slot'] = $match['slot']; - $component = $this->factory($match['name'], $view); + $component = $this->factory($match['name'], $view); return $component instanceof Component ? $component->withView($view)->withData($attributes)->render() : $this->renderView($view, $attributes); }, $output, -1, $replaceCount); - } catch (\Throwable $e) { + } catch (Throwable $e) { break; } - } while (!empty($replaceCount)); + } while (! empty($replaceCount)); return $output ?? preg_last_error(); } @@ -181,6 +182,7 @@ private function renderView(string $view, array $data): string extract($data); ob_start(); eval('?>' . file_get_contents($view)); + return ob_get_clean() ?: ''; })($view, $data); } diff --git a/src/Widgets/Controllers/WidgetsSettingsController.php b/src/Widgets/Controllers/WidgetsSettingsController.php index 8f5f5663..19993b50 100644 --- a/src/Widgets/Controllers/WidgetsSettingsController.php +++ b/src/Widgets/Controllers/WidgetsSettingsController.php @@ -11,8 +11,8 @@ namespace Bonfire\Widgets\Controllers; -use CodeIgniter\HTTP\RedirectResponse; use Bonfire\Core\AdminController; +use CodeIgniter\HTTP\RedirectResponse; class WidgetsSettingsController extends AdminController { diff --git a/src/Widgets/Language/en/Widgets.php b/src/Widgets/Language/en/Widgets.php index e90549f6..8d5c76ed 100644 --- a/src/Widgets/Language/en/Widgets.php +++ b/src/Widgets/Language/en/Widgets.php @@ -10,6 +10,6 @@ */ return [ - 'widgetsModTitle' => 'Widgets', - 'viewDetail' => 'View Detail', + 'widgetsModTitle' => 'Widgets', + 'viewDetail' => 'View Detail', ]; diff --git a/src/Widgets/Language/it/Widgets.php b/src/Widgets/Language/it/Widgets.php index 84c9be40..127ed2b2 100644 --- a/src/Widgets/Language/it/Widgets.php +++ b/src/Widgets/Language/it/Widgets.php @@ -10,6 +10,6 @@ */ return [ - 'widgetsModTitle' => 'Widgets', - 'viewDetail' => 'Visualizza dettaglio', + 'widgetsModTitle' => 'Widgets', + 'viewDetail' => 'Visualizza dettaglio', ]; diff --git a/src/Widgets/Language/lt/Widgets.php b/src/Widgets/Language/lt/Widgets.php index 2f216d90..7e195905 100644 --- a/src/Widgets/Language/lt/Widgets.php +++ b/src/Widgets/Language/lt/Widgets.php @@ -10,6 +10,6 @@ */ return [ - 'widgetsModTitle' => 'Skydelio elementai', - 'viewDetail' => 'Rodyti detaliau', + 'widgetsModTitle' => 'Skydelio elementai', + 'viewDetail' => 'Rodyti detaliau', ]; diff --git a/src/Widgets/Types/Charts/ChartDataset.php b/src/Widgets/Types/Charts/ChartDataset.php index f8e545a0..3573aa91 100644 --- a/src/Widgets/Types/Charts/ChartDataset.php +++ b/src/Widgets/Types/Charts/ChartDataset.php @@ -69,7 +69,7 @@ public function data(): array } /** - * @return array|string[] + * @return array|list */ public function backgroundColor(): array { @@ -77,7 +77,7 @@ public function backgroundColor(): array } /** - * @return array|string[] + * @return array|list */ public function borderColor(): array { diff --git a/src/Widgets/Types/Charts/ChartsCollection.php b/src/Widgets/Types/Charts/ChartsCollection.php index 0cbe13f9..6021f4fb 100644 --- a/src/Widgets/Types/Charts/ChartsCollection.php +++ b/src/Widgets/Types/Charts/ChartsCollection.php @@ -67,6 +67,7 @@ public function addItems(array $items): ChartsCollection public function removeItem(string $title) { $counter = count($this->items); + for ($i = 0; $i < $counter; $i++) { if ($this->items[$i]->title() === $title) { unset($this->items[$i]); diff --git a/src/Widgets/Types/Charts/ChartsItem.php b/src/Widgets/Types/Charts/ChartsItem.php index 578c5cfd..bc9a644d 100644 --- a/src/Widgets/Types/Charts/ChartsItem.php +++ b/src/Widgets/Types/Charts/ChartsItem.php @@ -26,7 +26,7 @@ class ChartsItem implements Item protected $weight; /** - * @var array|string[] + * @var array|list */ protected array $bgColor = [ 'rgba(255, 99, 132, 0.2)', @@ -39,7 +39,7 @@ class ChartsItem implements Item ]; /** - * @var array|string[] + * @var array|list */ protected array $borderColor = [ 'rgb(255, 99, 132)', @@ -56,7 +56,7 @@ class ChartsItem implements Item protected int $overOffset = 20; /** - * @var array|string[] + * @var array|list */ protected array $supportedTypes = [ 'line', diff --git a/src/Widgets/Types/Stats/StatsCollection.php b/src/Widgets/Types/Stats/StatsCollection.php index b133c567..b01cfd60 100644 --- a/src/Widgets/Types/Stats/StatsCollection.php +++ b/src/Widgets/Types/Stats/StatsCollection.php @@ -76,6 +76,7 @@ public function addItems(array $items): StatsCollection public function removeItem(string $title) { $counter = count($this->items); + for ($i = 0; $i < $counter; $i++) { if ($this->items[$i]->title() === $title) { unset($this->items[$i]); diff --git a/src/Widgets/Types/Stats/StatsItem.php b/src/Widgets/Types/Stats/StatsItem.php index c1c5f21d..ef3ebf66 100644 --- a/src/Widgets/Types/Stats/StatsItem.php +++ b/src/Widgets/Types/Stats/StatsItem.php @@ -107,7 +107,7 @@ public function setFaIcon(?string $faIcon): StatsItem public function setUrl(string $url = '#'): StatsItem { - $this->url = strpos($url, '://') !== false + $this->url = str_contains($url, '://') ? $url : '/' . ltrim($url, '/ '); diff --git a/tests/Consent/ConsentHelperTest.php b/tests/Consent/ConsentHelperTest.php index fc604c83..2f6dd4e2 100644 --- a/tests/Consent/ConsentHelperTest.php +++ b/tests/Consent/ConsentHelperTest.php @@ -6,10 +6,9 @@ use Tests\Support\TestCase; /** - * @backupGlobals disabled - * * @internal */ +#[\PHPUnit\Framework\Attributes\BackupGlobals(false)] final class ConsentHelperTest extends TestCase { protected function setUp(): void diff --git a/tests/Recycler/RecyclerTest.php b/tests/Recycler/RecyclerTest.php index 06de3b1f..6dfc35a7 100644 --- a/tests/Recycler/RecyclerTest.php +++ b/tests/Recycler/RecyclerTest.php @@ -57,7 +57,6 @@ public function testRestore() $result = $this->actingAs($this->admin) ->get(route_to('recycler-restore', 'users', $user1->id)); - $this->seeInDatabase('users', [ 'id' => $user1->id, 'deleted_at' => null, diff --git a/tests/View/MetadataTest.php b/tests/View/MetadataTest.php index 4d6e3c7e..fa58521b 100644 --- a/tests/View/MetadataTest.php +++ b/tests/View/MetadataTest.php @@ -11,7 +11,7 @@ final class MetadataTest extends TestCase { /** - * @var \Bonfire\View\Metadata + * @var Metadata */ protected $meta; @@ -32,7 +32,7 @@ public function testCanRenderMetaTags() $this->assertSame( '' . "\n" . '' . "\n", - $this->meta->render('meta') + $this->meta->render('meta'), ); } diff --git a/tests/_support/TestCase.php b/tests/_support/TestCase.php index 92659dbe..fdd72819 100644 --- a/tests/_support/TestCase.php +++ b/tests/_support/TestCase.php @@ -28,7 +28,7 @@ abstract class TestCase extends CIUnitTestCase * When migrations are ran, will ensure * all migrations in all modules will run. */ - protected $namespace = null; + protected $namespace; /** * @var Factory