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
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ parameters:
- APP_NAMESPACE
- CI_DEBUG
- ENVIRONMENT
- CodeIgniter\CodeIgniter::CI_VERSION
10 changes: 10 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector;
use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\DeadCode\Rector\StmtsAwareInterface\RemoveJustPropertyFetchForAssignRector;
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
Expand Down Expand Up @@ -108,6 +110,14 @@
RemoveJustPropertyFetchForAssignRector::class => [
__DIR__ . '/src/Models/UserModel.php',
],

// Ignore tests that use CodeIgniter::CI_VERSION
UnwrapFutureCompatibleIfPhpVersionRector::class => [
__DIR__ . '/tests/Commands/UserModelGeneratorTest.php',
],
RemoveUnusedPrivatePropertyRector::class => [
__DIR__ . '/tests/Commands/UserModelGeneratorTest.php',
],
]);
// auto import fully qualified class names
$rectorConfig->importNames();
Expand Down
9 changes: 6 additions & 3 deletions src/Commands/Generators/UserModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class UserModelGenerator extends BaseCommand
/**
* Actually execute the command.
*/
public function run(array $params): void
public function run(array $params): int
{
$this->component = 'Model';
$this->directory = 'Models';
Expand All @@ -68,12 +68,15 @@ public function run(array $params): void
if (! $this->verifyChosenModelClassName($class, $params)) {
CLI::error('Cannot use `ShieldUserModel` as class name as this conflicts with the parent class.', 'light_gray', 'red');

return; // @TODO when CI4 is at v4.3+, change this to `return 1;` to signify failing exit
return 1;
}

$params[0] = $class;

$this->execute($params);
// @TODO execute() is deprecated in CI v4.3.0.
$this->execute($params); // @phpstan-ignore-line suppress deprecated error.

return 0;
}

/**
Expand Down
21 changes: 17 additions & 4 deletions tests/Commands/UserModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tests\Commands;

use CodeIgniter\CodeIgniter;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Filters\CITestStreamFilter;

Expand All @@ -18,10 +19,16 @@ protected function setUp(): void
{
parent::setUp();

CITestStreamFilter::$buffer = '';
if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) {
CITestStreamFilter::registration();
CITestStreamFilter::addOutputFilter();
CITestStreamFilter::addErrorFilter();
} else {
CITestStreamFilter::$buffer = '';

$this->streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter');
$this->streamFilter = stream_filter_append(STDERR, 'CITestStreamFilter');
$this->streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter');
$this->streamFilter = stream_filter_append(STDERR, 'CITestStreamFilter');
}

if (is_file(HOMEPATH . 'src/Models/UserModel.php')) {
copy(HOMEPATH . 'src/Models/UserModel.php', HOMEPATH . 'src/Models/UserModel.php.bak');
Expand All @@ -34,7 +41,13 @@ protected function tearDown(): void
{
parent::tearDown();

stream_filter_remove($this->streamFilter);
if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) {
CITestStreamFilter::removeOutputFilter();
CITestStreamFilter::removeErrorFilter();
} else {
stream_filter_remove($this->streamFilter);
}

$this->deleteTestFiles();

if (is_file(HOMEPATH . 'src/Models/UserModel.php.bak')) {
Expand Down