Skip to content

Commit

Permalink
[Rector] Clean up skip config and re-run Rector
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Mar 19, 2022
1 parent 6b8b0b5 commit 2888011
Show file tree
Hide file tree
Showing 69 changed files with 234 additions and 227 deletions.
3 changes: 2 additions & 1 deletion app/Config/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Config;

use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Session\Handlers\FileHandler;

class App extends BaseConfig
{
Expand Down Expand Up @@ -151,7 +152,7 @@ class App extends BaseConfig
*
* @var string
*/
public $sessionDriver = 'CodeIgniter\Session\Handlers\FileHandler';
public $sessionDriver = FileHandler::class;

/**
* --------------------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion app/Config/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Config;

use CodeIgniter\Database\Config;
use SQLite3;

/**
* Database Configuration
Expand Down Expand Up @@ -62,7 +63,7 @@ class Database extends Config
'username' => '',
'password' => '',
'database' => ':memory:',
'DBDriver' => 'SQLite3',
'DBDriver' => SQLite3::class,
'DBPrefix' => 'db_', // Needed to ensure we're working correctly with prefixes live. DO NOT REMOVE FOR CI DEVS
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
Expand Down
8 changes: 5 additions & 3 deletions app/Config/Format.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Format\FormatterInterface;
use CodeIgniter\Format\JSONFormatter;
use CodeIgniter\Format\XMLFormatter;

class Format extends BaseConfig
{
Expand Down Expand Up @@ -40,9 +42,9 @@ class Format extends BaseConfig
* @var array<string, string>
*/
public $formatters = [
'application/json' => 'CodeIgniter\Format\JSONFormatter',
'application/xml' => 'CodeIgniter\Format\XMLFormatter',
'text/xml' => 'CodeIgniter\Format\XMLFormatter',
'application/json' => JSONFormatter::class,
'application/xml' => XMLFormatter::class,
'text/xml' => XMLFormatter::class,
];

/**
Expand Down
3 changes: 2 additions & 1 deletion app/Config/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Config;

use CodeIgniter\Log\Handlers\FileHandler;
use CodeIgniter\Config\BaseConfig;

class Logger extends BaseConfig
Expand Down Expand Up @@ -83,7 +84,7 @@ class Logger extends BaseConfig
* File Handler
* --------------------------------------------------------------------
*/
'CodeIgniter\Log\Handlers\FileHandler' => [
FileHandler::class => [

// The log levels that this handler will handle.
'handles' => [
Expand Down
13 changes: 8 additions & 5 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@
RemoveUnusedPrivateMethodRector::class => [
// private method called via getPrivateMethodInvoker
__DIR__ . '/tests/system/Test/ReflectionHelperTest.php',
// Rector bug?
__DIR__ . '/system/CodeIgniter.php',
],

// call on purpose for nothing happen check
Expand All @@ -103,9 +101,14 @@
__DIR__ . '/system/Session/Handlers',
],

// may cause load view files directly when detecting class that
// make warning
StringClassNameToClassConstantRector::class,
// may cause load view files directly when detecting namespaced string
// due to internal PHPStan issue
StringClassNameToClassConstantRector::class => [
__DIR__ . '/app/Config/Pager.php',
__DIR__ . '/app/Config/Validation.php',
__DIR__ . '/tests/system/Validation/StrictRules/ValidationTest.php',
__DIR__ . '/tests/system/Validation/ValidationTest.php',
],

// sometime too detail
CountOnNullRector::class,
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/Handlers/PredisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,6 @@ public function getMetaData(string $key)
*/
public function isSupported(): bool
{
return class_exists('Predis\Client');
return class_exists(Client::class);
}
}
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')) {
if (is_object($this->controller) && (get_class($this->controller) === Closure::class)) {
$controller = $this->controller;

return $controller(...$this->router->params());
Expand Down
3 changes: 2 additions & 1 deletion system/Commands/Database/CreateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use CodeIgniter\Config\Factories;
use CodeIgniter\Database\SQLite3\Connection;
use Config\Database;
use SQLite3;
use Throwable;

/**
Expand Down Expand Up @@ -106,7 +107,7 @@ public function run(array $params)
$name = str_replace(['.db', '.sqlite'], '', $name) . ".{$ext}";
}

$config->{$group}['DBDriver'] = 'SQLite3';
$config->{$group}['DBDriver'] = SQLite3::class;
$config->{$group}['database'] = $name;

if ($name !== ':memory:') {
Expand Down
9 changes: 6 additions & 3 deletions system/Commands/Generators/ControllerGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
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 skeleton controller file.
Expand Down Expand Up @@ -99,7 +102,7 @@ protected function prepare(string $class): string
// Gets the appropriate parent class to extend.
if ($bare || $rest) {
if ($bare) {
$useStatement = 'CodeIgniter\Controller';
$useStatement = Controller::class;
$extends = 'Controller';
} elseif ($rest) {
$rest = is_string($rest) ? $rest : 'controller';
Expand All @@ -112,10 +115,10 @@ protected function prepare(string $class): string
}

if ($rest === 'controller') {
$useStatement = 'CodeIgniter\RESTful\ResourceController';
$useStatement = ResourceController::class;
$extends = 'ResourceController';
} elseif ($rest === 'presenter') {
$useStatement = 'CodeIgniter\RESTful\ResourcePresenter';
$useStatement = ResourcePresenter::class;
$extends = 'ResourcePresenter';
}
}
Expand Down
28 changes: 19 additions & 9 deletions system/Config/AutoloadConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@

namespace CodeIgniter\Config;

use Laminas\Escaper\Escaper;
use Psr\Log\AbstractLogger;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerTrait;
use Psr\Log\LogLevel;
use Psr\Log\NullLogger;

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

/**
Expand Down
4 changes: 2 additions & 2 deletions system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ protected static function discoverServices(string $name, array $arguments)
foreach ($files as $file) {
$classname = $locator->getClassname($file);

if (! in_array($classname, ['CodeIgniter\\Config\\Services'], true)) {
if (! in_array($classname, [\CodeIgniter\Config\Services::class], true)) {
static::$services[] = new $classname();
}
}
Expand Down Expand Up @@ -369,7 +369,7 @@ protected static function buildServicesCache(): void
foreach ($files as $file) {
$classname = $locator->getClassname($file);

if ($classname !== 'CodeIgniter\\Config\\Services') {
if ($classname !== \CodeIgniter\Config\Services::class) {
self::$serviceNames[] = $classname;
static::$services[] = new $classname();
}
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ abstract class BaseConnection implements ConnectionInterface
*
* @var string
*/
protected $queryClass = 'CodeIgniter\\Database\\Query';
protected $queryClass = Query::class;

/**
* Saves our connection settings.
Expand Down
2 changes: 1 addition & 1 deletion system/Database/BasePreparedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(BaseConnection $db)
*
* @return mixed
*/
public function prepare(string $sql, array $options = [], string $queryClass = 'CodeIgniter\\Database\\Query')
public function prepare(string $sql, array $options = [], string $queryClass = Query::class)
{
// We only supports positional placeholders (?)
// in order to work with the execute method below, so we
Expand Down
3 changes: 2 additions & 1 deletion system/Database/BaseResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CodeIgniter\Database;

use CodeIgniter\Entity\Entity;
use stdClass;

/**
* Class BaseResult
Expand Down Expand Up @@ -508,5 +509,5 @@ abstract protected function fetchAssoc();
*
* @return object
*/
abstract protected function fetchObject(string $className = 'stdClass');
abstract protected function fetchObject(string $className = stdClass::class);
}
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')
protected function fetchObject(string $className = stdClass::class)
{
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/OCI8/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected function fetchObject(string $className = stdClass::class)
{
$row = oci_fetch_object($this->resultID);

if ($className === 'stdClass' || ! $row) {
if ($className === stdClass::class || ! $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')
protected function fetchObject(string $className = stdClass::class)
{
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')
protected function fetchObject(string $className = stdClass::class)
{
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/SQLite3/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Connection extends BaseConnection
*
* @var string
*/
public $DBDriver = 'SQLite3';
public $DBDriver = SQLite3::class;

/**
* Identifier escape character
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')
protected function fetchObject(string $className = stdClass::class)
{
// No native support for fetching rows as objects
if (($row = $this->fetchAssoc()) === false) {
return false;
}

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

Expand Down
2 changes: 1 addition & 1 deletion system/Images/Handlers/ImageMagickHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct($config = null)

// We should never see this, so can't test it
// @codeCoverageIgnoreStart
if (! (extension_loaded('imagick') || class_exists('Imagick'))) {
if (! (extension_loaded('imagick') || class_exists(Imagick::class))) {
throw ImageException::forMissingExtension('IMAGICK');
}
// @codeCoverageIgnoreEnd
Expand Down
2 changes: 1 addition & 1 deletion system/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(string $locale)
{
$this->locale = $locale;

if (class_exists('MessageFormatter')) {
if (class_exists(MessageFormatter::class)) {
$this->intlSupport = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion system/Test/Fabricator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Faker\Generator;
use InvalidArgumentException;
use RuntimeException;
use stdClass;

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

use CodeIgniter\Database\BaseResult;
use stdClass;

class MockResult extends BaseResult
{
Expand Down Expand Up @@ -81,7 +82,7 @@ protected function fetchAssoc()
*
* @return object
*/
protected function fetchObject($className = 'stdClass')
protected function fetchObject($className = stdClass::class)
{
return new $className();
}
Expand Down
3 changes: 2 additions & 1 deletion system/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use CodeIgniter\Autoloader\FileLocator;
use CodeIgniter\Debug\Toolbar\Collectors\Views;
use CodeIgniter\Filters\DebugToolbar;
use CodeIgniter\View\Exceptions\ViewException;
use Config\Services;
use Config\Toolbar;
Expand Down Expand Up @@ -235,7 +236,7 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n
$this->logPerformance($this->renderVars['start'], microtime(true), $this->renderVars['view']);

if (($this->debug && (! isset($options['debug']) || $options['debug'] === true))
&& in_array('CodeIgniter\Filters\DebugToolbar', service('filters')->getFiltersClass()['after'], true)
&& in_array(DebugToolbar::class, service('filters')->getFiltersClass()['after'], true)
) {
$toolbarCollectors = config(Toolbar::class)->collectors;

Expand Down
Loading

0 comments on commit 2888011

Please sign in to comment.