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

use static:: instead of self:: for protected and public properties #1465

Merged
merged 2 commits into from
Nov 12, 2018
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
8 changes: 4 additions & 4 deletions application/Config/Mimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,12 @@ public static function guessTypeFromExtension(string $extension)
{
$extension = trim(strtolower($extension), '. ');

if (! array_key_exists($extension, self::$mimes))
if (! array_key_exists($extension, static::$mimes))
{
return null;
}

return is_array(self::$mimes[$extension]) ? self::$mimes[$extension][0] : self::$mimes[$extension];
return is_array(static::$mimes[$extension]) ? static::$mimes[$extension][0] : static::$mimes[$extension];
}

//--------------------------------------------------------------------
Expand All @@ -509,12 +509,12 @@ public static function guessExtensionFromType(string $type, ?string $proposed_ex

$proposed_extension = trim(strtolower($proposed_extension));

if (! is_null($proposed_extension) && array_key_exists($proposed_extension, self::$mimes) && in_array($type, is_string(self::$mimes[$proposed_extension]) ? [self::$mimes[$proposed_extension]] : self::$mimes[$proposed_extension]))
if (! is_null($proposed_extension) && array_key_exists($proposed_extension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposed_extension]) ? [static::$mimes[$proposed_extension]] : static::$mimes[$proposed_extension]))
{
return $proposed_extension;
}

foreach (self::$mimes as $ext => $types)
foreach (static::$mimes as $ext => $types)
{
if (is_string($types) && $types === $type)
{
Expand Down
6 changes: 3 additions & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ public function displayCache($config)
*/
public static function cache(int $time)
{
self::$cacheTTL = $time;
static::$cacheTTL = $time;
}

//--------------------------------------------------------------------
Expand All @@ -599,7 +599,7 @@ public function cachePage(Cache $config)
}

return cache()->save(
$this->generateCacheName($config), serialize(['headers' => $headers, 'output' => $this->output]), self::$cacheTTL
$this->generateCacheName($config), serialize(['headers' => $headers, 'output' => $this->output]), static::$cacheTTL
);
}

Expand Down Expand Up @@ -931,7 +931,7 @@ protected function gatherOutput($cacheConfig = null, $returned = null)

// Cache it without the performance metrics replaced
// so that we can have live speed updates along the way.
if (self::$cacheTTL > 0)
if (static::$cacheTTL > 0)
{
$this->cachePage($cacheConfig);
}
Expand Down
26 changes: 13 additions & 13 deletions system/Database/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public static function connect($group = null, bool $getShared = true)
throw new \InvalidArgumentException($group . ' is not a valid database connection group.');
}

if ($getShared && isset(self::$instances[$group]))
if ($getShared && isset(static::$instances[$group]))
{
return self::$instances[$group];
return static::$instances[$group];
}

self::ensureFactory();
Expand All @@ -104,9 +104,9 @@ public static function connect($group = null, bool $getShared = true)
$config = $config->$group;
}

$connection = self::$factory->load($config, $group);
$connection = static::$factory->load($config, $group);

self::$instances[$group] = & $connection;
static::$instances[$group] = & $connection;

return $connection;
}
Expand All @@ -120,7 +120,7 @@ public static function connect($group = null, bool $getShared = true)
*/
public static function getConnections()
{
return self::$instances;
return static::$instances;
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -149,16 +149,16 @@ public static function forge(string $group = null)
throw new \InvalidArgumentException($group . ' is not a valid database connection group.');
}

if (! isset(self::$instances[$group]))
if (! isset(static::$instances[$group]))
{
$db = self::connect($group);
}
else
{
$db = self::$instances[$group];
$db = static::$instances[$group];
}

return self::$factory->loadForge($db);
return static::$factory->loadForge($db);
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -186,16 +186,16 @@ public static function utils(string $group = null)
throw new \InvalidArgumentException($group . ' is not a valid database connection group.');
}

if (! isset(self::$instances[$group]))
if (! isset(static::$instances[$group]))
{
$db = self::connect($group);
}
else
{
$db = self::$instances[$group];
$db = static::$instances[$group];
}

return self::$factory->loadUtils($db);
return static::$factory->loadUtils($db);
}

//--------------------------------------------------------------------
Expand All @@ -221,12 +221,12 @@ public static function seeder(string $group = null)
*/
protected static function ensureFactory()
{
if (self::$factory instanceof \CodeIgniter\Database\Database)
if (static::$factory instanceof \CodeIgniter\Database\Database)
{
return;
}

self::$factory = new \CodeIgniter\Database\Database();
static::$factory = new \CodeIgniter\Database\Database();
}

//--------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions system/Debug/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ protected static function format(string $data, string $format = 'html')

$files = [];

$current = self::$request->getGet('debugbar_time');
$current = static::$request->getGet('debugbar_time');
$app = config(App::class);

for ($i = 0; $i < $total; $i++)
Expand Down Expand Up @@ -418,7 +418,7 @@ protected function roundTo($number, $increments = 5)
*/
public static function eventHandler()
{
self::$request = Services::request();
static::$request = Services::request();

if (ENVIRONMENT === 'testing')
{
Expand All @@ -427,7 +427,7 @@ public static function eventHandler()

// If the request contains '?debugbar then we're
// simply returning the loading script
if (self::$request->getGet('debugbar') !== null)
if (static::$request->getGet('debugbar') !== null)
{
// Let the browser know that we are sending javascript
header('Content-Type: application/javascript');
Expand All @@ -442,19 +442,19 @@ public static function eventHandler()

// Otherwise, if it includes ?debugbar_time, then
// we should return the entire debugbar.
if (self::$request->getGet('debugbar_time'))
if (static::$request->getGet('debugbar_time'))
{
helper('security');

// Negotiate the content-type to format the output
$format = self::$request->negotiate('media', [
$format = static::$request->negotiate('media', [
'text/html',
'application/json',
'application/xml',
]);
$format = explode('/', $format)[1];

$file = sanitize_filename('debugbar_' . self::$request->getGet('debugbar_time'));
$file = sanitize_filename('debugbar_' . static::$request->getGet('debugbar_time'));
$filename = WRITEPATH . 'debugbar/' . $file;

// Show the toolbar
Expand Down
6 changes: 3 additions & 3 deletions system/Email/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public function __construct($config = null)
{
$this->initialize($config);

isset(self::$func_overload) || self::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'));
isset(static::$func_overload) || static::$func_overload = (extension_loaded('mbstring') && ini_get('mbstring.func_overload'));

log_message('info', 'Email Class Initialized');
}
Expand Down Expand Up @@ -2515,7 +2515,7 @@ public function __destruct()
*/
protected static function strlen($str)
{
return (self::$func_overload) ? mb_strlen($str, '8bit') : strlen($str);
return (static::$func_overload) ? mb_strlen($str, '8bit') : strlen($str);
}

//--------------------------------------------------------------------
Expand All @@ -2531,7 +2531,7 @@ protected static function strlen($str)
*/
protected static function substr($str, $start, $length = null)
{
if (self::$func_overload)
if (static::$func_overload)
{
return mb_substr($str, $start, $length, '8bit');
}
Expand Down
42 changes: 21 additions & 21 deletions system/Events/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,19 @@ public static function initialize()
*/
public static function on($event_name, callable $callback, $priority = EVENT_PRIORITY_NORMAL)
{
if (! isset(self::$listeners[$event_name]))
if (! isset(static::$listeners[$event_name]))
{
self::$listeners[$event_name] = [
true, // If there's only 1 item, it's sorted.
[$priority],
[$callback],
];
static::$listeners[$event_name] = [
true, // If there's only 1 item, it's sorted.
[$priority],
[$callback],
];
}
else
{
self::$listeners[$event_name][0] = false; // Not sorted
self::$listeners[$event_name][1][] = $priority;
self::$listeners[$event_name][2][] = $callback;
static::$listeners[$event_name][0] = false; // Not sorted
static::$listeners[$event_name][1][] = $priority;
static::$listeners[$event_name][2][] = $callback;
}
}

Expand All @@ -172,7 +172,7 @@ public static function on($event_name, callable $callback, $priority = EVENT_PRI
public static function trigger($eventName, ...$arguments): bool
{
// Read in our Config/events file so that we have them all!
if (! self::$initialized)
if (! static::$initialized)
{
self::initialize();
}
Expand Down Expand Up @@ -220,22 +220,22 @@ public static function trigger($eventName, ...$arguments): bool
*/
public static function listeners($event_name): array
{
if (! isset(self::$listeners[$event_name]))
if (! isset(static::$listeners[$event_name]))
{
return [];
}

// The list is not sorted
if (! self::$listeners[$event_name][0])
if (! static::$listeners[$event_name][0])
{
// Sort it!
array_multisort(self::$listeners[$event_name][1], SORT_NUMERIC, self::$listeners[$event_name][2]);
array_multisort(static::$listeners[$event_name][1], SORT_NUMERIC, static::$listeners[$event_name][2]);

// Mark it as sorted already!
self::$listeners[$event_name][0] = true;
static::$listeners[$event_name][0] = true;
}

return self::$listeners[$event_name][2];
return static::$listeners[$event_name][2];
}

//--------------------------------------------------------------------
Expand All @@ -253,17 +253,17 @@ public static function listeners($event_name): array
*/
public static function removeListener($event_name, callable $listener): bool
{
if (! isset(self::$listeners[$event_name]))
if (! isset(static::$listeners[$event_name]))
{
return false;
}

foreach (self::$listeners[$event_name][2] as $index => $check)
foreach (static::$listeners[$event_name][2] as $index => $check)
{
if ($check === $listener)
{
unset(self::$listeners[$event_name][1][$index]);
unset(self::$listeners[$event_name][2][$index]);
unset(static::$listeners[$event_name][1][$index]);
unset(static::$listeners[$event_name][2][$index]);

return true;
}
Expand All @@ -286,11 +286,11 @@ public static function removeAllListeners($event_name = null)
{
if (! is_null($event_name))
{
unset(self::$listeners[$event_name]);
unset(static::$listeners[$event_name]);
}
else
{
self::$listeners = [];
static::$listeners = [];
}
}

Expand Down
4 changes: 2 additions & 2 deletions system/Test/Filters/CITestStreamFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function filter($in, $out, &$consumed, $closing)
{
while ($bucket = stream_bucket_make_writeable($in))
{
self::$buffer .= $bucket->data;
$consumed += $bucket->datalen;
static::$buffer .= $bucket->data;
$consumed += $bucket->datalen;
}
return PSFS_PASS_ON;
}
Expand Down