Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition to default php-cs-fixer config for codeigniter4 #539

Closed
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
19 changes: 9 additions & 10 deletions .config/.php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use CodeIgniter\CodingStandard\CodeIgniter4;
use Nexus\CsConfig\Factory;
use PhpCsFixer\Finder;

$finder = Finder::create()
Expand All @@ -12,22 +14,19 @@
'build',
'Views',
])
;
->append([
__FILE__,
__DIR__ . '/rector.php',
]);

$overrides = [
'yoda_style' => ['identical' => false],
// 'declare_strict_types' => true,
// 'void_return' => true,
];

$options = [
'finder' => $finder,
'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();
19 changes: 9 additions & 10 deletions .config/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Assets/Controllers/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 4 additions & 4 deletions src/Assets/Helpers/assets_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 3 additions & 7 deletions src/Auth/Actions/Email2FA.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,7 +49,6 @@ public function show(): string
$this->createIdentity($user);

return $this->render(config('Auth')->views['action_email_2fa'], ['user' => $user]);

}

/**
Expand Down Expand Up @@ -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) {
Expand All @@ -105,7 +104,6 @@ public function handle(IncomingRequest $request)
$email->clear();

return $this->render(config('Auth')->views['action_email_2fa_verify'], ['user' => $user]);

}

/**
Expand All @@ -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
Expand All @@ -149,8 +146,7 @@ private function getIdentity(User $user): ?UserIdentity

return $identityModel->getIdentityByType(
$user,
$this->type
$this->type,
);
}

}
4 changes: 2 additions & 2 deletions src/Auth/Actions/EmailActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ private function getIdentity(User $user): ?UserIdentity

return $identityModel->getIdentityByType(
$user,
$this->type
$this->type,
);
}
}
7 changes: 3 additions & 4 deletions src/Auth/Config/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<string>
* @phpstan-var list<string>
*/
public array $authenticationChain = [
Expand Down Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/Auth/Config/AuthGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Bonfire\Auth\Config;

use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Shield\Config\AuthGroups as ShieldAuthGroups;

class AuthGroups extends ShieldAuthGroups
Expand Down
1 change: 0 additions & 1 deletion src/Auth/Config/AuthToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

namespace Bonfire\Auth\Config;

use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Shield\Config\AuthToken as ShieldAuthToken;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/Controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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), '/ ');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bonfire.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/Commands/BreakingChangesNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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]));
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/Commands/Generators/CrudGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading
Loading