Skip to content

Commit

Permalink
exclude native classes
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Mar 20, 2022
1 parent 977defe commit 0bd15b7
Show file tree
Hide file tree
Showing 28 changed files with 64 additions and 90 deletions.
20 changes: 9 additions & 11 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,6 @@

// expected Qualified name
__DIR__ . '/tests/system/Autoloader/FileLocatorTest.php',

// SQLite3 as string
__DIR__ . '/app/Config/Database.php',
__DIR__ . '/system/Commands/Database/CreateDatabase.php',
__DIR__ . '/system/Database/SQLite3/Connection.php',
__DIR__ . '/tests/system/Database/ConfigTest.php',
__DIR__ . '/tests/system/Database/Live/DbUtilsTest.php',
__DIR__ . '/tests/system/Database/Live/ForgeTest.php',
__DIR__ . '/tests/system/Database/Live/GetTest.php',
__DIR__ . '/tests/system/Database/Live/SQLite/AlterTableTest.php',
__DIR__ . '/tests/system/Database/Migrations/MigrationRunnerTest.php',
],

// sometime too detail
Expand Down Expand Up @@ -164,4 +153,13 @@
$services->set(MakeInheritedMethodVisibilitySameAsParentRector::class);
$services->set(SimplifyEmptyArrayCheckRector::class);
$services->set(NormalizeNamespaceByPSR4ComposerAutoloadRector::class);
$services->set(StringClassNameToClassConstantRector::class)
->configure([
'Error',
'Exception',
'InvalidArgumentException',
'Closure',
'stdClass',
'SQLite3',
]);
};
2 changes: 1 addition & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ protected function startController()
$this->benchmark->start('controller_constructor');

// Is it routed to a Closure?
if (is_object($this->controller) && (get_class($this->controller) === Closure::class)) {
if (is_object($this->controller) && (get_class($this->controller) === 'Closure')) {
$controller = $this->controller;

return $controller(...$this->router->params());
Expand Down
19 changes: 9 additions & 10 deletions system/Config/AutoloadConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Laminas\Escaper\Escaper;
use Psr\Log\AbstractLogger;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -103,15 +102,15 @@ class AutoloadConfig
* @var array<string, string>
*/
protected $coreClassmap = [
AbstractLogger::class => SYSTEMPATH . 'ThirdParty/PSR/Log/AbstractLogger.php',
InvalidArgumentException::class => SYSTEMPATH . 'ThirdParty/PSR/Log/InvalidArgumentException.php',
LoggerAwareInterface::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareInterface.php',
LoggerAwareTrait::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareTrait.php',
LoggerInterface::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerInterface.php',
LoggerTrait::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerTrait.php',
LogLevel::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LogLevel.php',
NullLogger::class => SYSTEMPATH . 'ThirdParty/PSR/Log/NullLogger.php',
Escaper::class => SYSTEMPATH . 'ThirdParty/Escaper/Escaper.php',
AbstractLogger::class => SYSTEMPATH . 'ThirdParty/PSR/Log/AbstractLogger.php',
'InvalidArgumentException' => SYSTEMPATH . 'ThirdParty/PSR/Log/InvalidArgumentException.php',
LoggerAwareInterface::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareInterface.php',
LoggerAwareTrait::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerAwareTrait.php',
LoggerInterface::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerInterface.php',
LoggerTrait::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LoggerTrait.php',
LogLevel::class => SYSTEMPATH . 'ThirdParty/PSR/Log/LogLevel.php',
NullLogger::class => SYSTEMPATH . 'ThirdParty/PSR/Log/NullLogger.php',
Escaper::class => SYSTEMPATH . 'ThirdParty/Escaper/Escaper.php',
];

/**
Expand Down
3 changes: 1 addition & 2 deletions system/Database/BaseResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace CodeIgniter\Database;

use CodeIgniter\Entity\Entity;
use stdClass;

/**
* Class BaseResult
Expand Down Expand Up @@ -509,5 +508,5 @@ abstract protected function fetchAssoc();
*
* @return object
*/
abstract protected function fetchObject(string $className = stdClass::class);
abstract protected function fetchObject(string $className = 'stdClass');
}
2 changes: 1 addition & 1 deletion system/Database/MySQLi/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function fetchAssoc()
*
* @return bool|Entity|object
*/
protected function fetchObject(string $className = stdClass::class)
protected function fetchObject(string $className = 'stdClass')
{
if (is_subclass_of($className, Entity::class)) {
return empty($data = $this->fetchAssoc()) ? false : (new $className())->setAttributes($data);
Expand Down
5 changes: 2 additions & 3 deletions system/Database/OCI8/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use CodeIgniter\Database\BaseResult;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Entity;
use stdClass;

/**
* Result for OCI8
Expand Down Expand Up @@ -94,11 +93,11 @@ protected function fetchAssoc()
*
* @return bool|Entity|object
*/
protected function fetchObject(string $className = stdClass::class)
protected function fetchObject(string $className = 'stdClass')
{
$row = oci_fetch_object($this->resultID);

if ($className === stdClass::class || ! $row) {
if ($className === 'stdClass' || ! $row) {
return $row;
}
if (is_subclass_of($className, Entity::class)) {
Expand Down
2 changes: 1 addition & 1 deletion system/Database/Postgre/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function fetchAssoc()
*
* @return bool|Entity|object
*/
protected function fetchObject(string $className = stdClass::class)
protected function fetchObject(string $className = 'stdClass')
{
if (is_subclass_of($className, Entity::class)) {
return empty($data = $this->fetchAssoc()) ? false : (new $className())->setAttributes($data);
Expand Down
2 changes: 1 addition & 1 deletion system/Database/SQLSRV/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected function fetchAssoc()
*
* @return bool|Entity|object
*/
protected function fetchObject(string $className = stdClass::class)
protected function fetchObject(string $className = 'stdClass')
{
if (is_subclass_of($className, Entity::class)) {
return empty($data = $this->fetchAssoc()) ? false : (new $className())->setAttributes($data);
Expand Down
4 changes: 2 additions & 2 deletions system/Database/SQLite3/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ protected function fetchAssoc()
*
* @return bool|object
*/
protected function fetchObject(string $className = stdClass::class)
protected function fetchObject(string $className = 'stdClass')
{
// No native support for fetching rows as objects
if (($row = $this->fetchAssoc()) === false) {
return false;
}

if ($className === stdClass::class) {
if ($className === 'stdClass') {
return (object) $row;
}

Expand Down
3 changes: 1 addition & 2 deletions system/Test/Fabricator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Faker\Generator;
use InvalidArgumentException;
use RuntimeException;
use stdClass;

/**
* Fabricator
Expand Down Expand Up @@ -410,7 +409,7 @@ public function makeObject(?string $className = null): object
{
if ($className === null) {
if ($this->model->returnType === 'object' || $this->model->returnType === 'array') {
$className = stdClass::class;
$className = 'stdClass';
} else {
$className = $this->model->returnType;
}
Expand Down
3 changes: 1 addition & 2 deletions system/Test/Mock/MockResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace CodeIgniter\Test\Mock;

use CodeIgniter\Database\BaseResult;
use stdClass;

class MockResult extends BaseResult
{
Expand Down Expand Up @@ -82,7 +81,7 @@ protected function fetchAssoc()
*
* @return object
*/
protected function fetchObject($className = stdClass::class)
protected function fetchObject($className = 'stdClass')
{
return new $className();
}
Expand Down
3 changes: 1 addition & 2 deletions tests/system/Autoloader/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Config\Autoload;
use Config\Modules;
use Config\Services;
use InvalidArgumentException;
use UnnamespacedClass;

/**
Expand Down Expand Up @@ -55,7 +54,7 @@ public function testLoadStoredClass()

public function testInitializeWithInvalidArguments()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("Config array must contain either the 'psr4' key or the 'classmap' key.");

$config = new Autoload();
Expand Down
5 changes: 2 additions & 3 deletions tests/system/Cache/Handlers/BaseHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace CodeIgniter\Cache\Handlers;

use CodeIgniter\Test\CIUnitTestCase;
use InvalidArgumentException;
use stdClass;
use Tests\Support\Cache\RestrictiveHandler;

Expand All @@ -28,7 +27,7 @@ final class BaseHandlerTest extends CIUnitTestCase
*/
public function testValidateKeyInvalidType($input)
{
$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Cache key must be a string');

BaseHandler::validateKey($input);
Expand All @@ -49,7 +48,7 @@ public function testValidateKeyUsesConfig()
{
config('Cache')->reservedCharacters = 'b';

$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Cache key contains reserved characters b');

BaseHandler::validateKey('banana');
Expand Down
3 changes: 1 addition & 2 deletions tests/system/CommonFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
use Config\App;
use Config\Logger;
use Config\Modules;
use InvalidArgumentException;
use Kint;
use stdClass;
use Tests\Support\Models\JobModel;
Expand Down Expand Up @@ -167,7 +166,7 @@ public function testEscapeWithDifferentEncodings()

public function testEscapeBadContext()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');
esc(['width' => '800', 'height' => '600'], 'bogus');
}

Expand Down
5 changes: 2 additions & 3 deletions tests/system/Config/DotEnvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace CodeIgniter\Config;

use CodeIgniter\Test\CIUnitTestCase;
use InvalidArgumentException;
use org\bovigo\vfs\vfsStream;

/**
Expand Down Expand Up @@ -116,7 +115,7 @@ public function testLoadsUnreadableFile()
$file = 'unreadable.env';
$path = rtrim($this->fixturesFolder, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $file;
chmod($path, 0000);
$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("The .env file is not readable: {$path}");
$dotenv = new DotEnv($this->fixturesFolder, $file);
$dotenv->load();
Expand All @@ -136,7 +135,7 @@ public function testQuotedDotenvLoadsEnvironmentVars()

public function testSpacedValuesWithoutQuotesThrowsException()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('.env values containing spaces must be surrounded by quotes.');

$dotenv = new DotEnv($this->fixturesFolder, 'spaced-wrong.env');
Expand Down
8 changes: 4 additions & 4 deletions tests/system/Config/FactoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public function testInjection()

$result = Factories::widgets('Banana');

$this->assertInstanceOf(stdClass::class, $result);
$this->assertInstanceOf('stdClass', $result);
}

public function testRespectsComponentAlias()
Expand All @@ -210,7 +210,7 @@ public function testRespectsPath()

public function testRespectsInstanceOf()
{
Factories::setOptions('widgets', ['instanceOf' => stdClass::class]);
Factories::setOptions('widgets', ['instanceOf' => 'stdClass']);

$result = Factories::widgets('SomeWidget');
$this->assertInstanceOf(SomeWidget::class, $result);
Expand All @@ -223,13 +223,13 @@ public function testSharedRespectsInstanceOf()
{
Factories::injectMock('widgets', 'SomeWidget', new OtherWidget());

$result = Factories::widgets('SomeWidget', ['instanceOf' => stdClass::class]);
$result = Factories::widgets('SomeWidget', ['instanceOf' => 'stdClass']);
$this->assertInstanceOf(SomeWidget::class, $result);
}

public function testPrioritizesParameterOptions()
{
Factories::setOptions('widgets', ['instanceOf' => stdClass::class]);
Factories::setOptions('widgets', ['instanceOf' => 'stdClass']);

$result = Factories::widgets('OtherWidget', ['instanceOf' => null]);
$this->assertInstanceOf(OtherWidget::class, $result);
Expand Down
3 changes: 1 addition & 2 deletions tests/system/Cookie/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Config\Cookie as CookieConfig;
use DateTimeImmutable;
use DateTimeZone;
use InvalidArgumentException;
use LogicException;

/**
Expand Down Expand Up @@ -274,7 +273,7 @@ public function testArrayAccessOfCookie(): void
$this->assertArrayHasKey('path', $cookie);
$this->assertSame($cookie['path'], $cookie->getPath());

$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');
$cookie['expiry'];
}

Expand Down
5 changes: 2 additions & 3 deletions tests/system/Database/Builder/WhereTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use CodeIgniter\Database\BaseBuilder;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Mock\MockConnection;
use InvalidArgumentException;
use stdClass;

/**
Expand Down Expand Up @@ -267,7 +266,7 @@ public function provideInvalidKeys()
*/
public function testWhereInvalidKeyThrowInvalidArgumentException($key)
{
$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');
$builder = $this->db->table('jobs');

$builder->whereIn($key, ['Politician', 'Accountant']);
Expand All @@ -289,7 +288,7 @@ public function provideInvalidValues()
*/
public function testWhereInEmptyValuesThrowInvalidArgumentException($values)
{
$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');
$builder = $this->db->table('jobs');

$builder->whereIn('name', $values);
Expand Down
7 changes: 3 additions & 4 deletions tests/system/Database/DatabaseSeederTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use CodeIgniter\Test\CIUnitTestCase;
use Config\Database;
use Faker\Generator;
use InvalidArgumentException;

/**
* @internal
Expand All @@ -23,7 +22,7 @@ final class DatabaseSeederTest extends CIUnitTestCase
{
public function testInstantiateNoSeedPath()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');

$config = new Database();
$config->filesPath = '';
Expand All @@ -32,7 +31,7 @@ public function testInstantiateNoSeedPath()

public function testInstantiateNotDirSeedPath()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');

$config = new Database();
$config->filesPath = APPPATH . 'Foo';
Expand All @@ -49,7 +48,7 @@ public function testFakerGet()

public function testCallOnEmptySeeder()
{
$this->expectException(InvalidArgumentException::class);
$this->expectException('InvalidArgumentException');

$seeder = new Seeder(new Database());
$seeder->call('');
Expand Down
Loading

0 comments on commit 0bd15b7

Please sign in to comment.