Skip to content

Commit da9eace

Browse files
committed
Base Modules typos changes
1 parent 11e1434 commit da9eace

4 files changed

Lines changed: 61 additions & 44 deletions

File tree

system/CodeIgniter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
namespace CodeIgniter;
3939

40+
use Closure;
4041
use CodeIgniter\Filters\Exceptions\FilterException;
4142
use CodeIgniter\HTTP\DownloadResponse;
4243
use CodeIgniter\HTTP\RedirectResponse;
@@ -51,6 +52,7 @@
5152
use CodeIgniter\HTTP\CLIRequest;
5253
use CodeIgniter\Router\RouteCollectionInterface;
5354
use CodeIgniter\Exceptions\PageNotFoundException;
55+
use Exception;
5456

5557
/**
5658
* This class is the core of the framework, and will analyse the
@@ -545,7 +547,7 @@ public function displayCache($config)
545547
$cachedResponse = unserialize($cachedResponse);
546548
if (! is_array($cachedResponse) || ! isset($cachedResponse['output']) || ! isset($cachedResponse['headers']))
547549
{
548-
throw new \Exception('Error unserializing page cache');
550+
throw new Exception('Error unserializing page cache');
549551
}
550552

551553
$headers = $cachedResponse['headers'];
@@ -849,7 +851,7 @@ protected function display404errors(PageNotFoundException $e)
849851
// Is there a 404 Override available?
850852
if ($override = $this->router->get404Override())
851853
{
852-
if ($override instanceof \Closure)
854+
if ($override instanceof Closure)
853855
{
854856
echo $override($e->getMessage());
855857
}

system/Common.php

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,18 @@
3636
* @filesource
3737
*/
3838

39+
use CodeIgniter\Config\Config;
40+
use CodeIgniter\Files\Exceptions\FileNotFoundException;
3941
use CodeIgniter\HTTP\RedirectResponse;
4042
use CodeIgniter\HTTP\RequestInterface;
4143
use CodeIgniter\HTTP\ResponseInterface;
44+
use CodeIgniter\HTTP\URI;
45+
use Config\App;
46+
use Config\Database;
47+
use Config\Logger;
4248
use Config\Services;
49+
use Tests\Support\Log\TestLogger;
50+
use Zend\Escaper\Escaper;
4351

4452
/**
4553
* Common Functions
@@ -97,7 +105,7 @@ function cache(string $key = null)
97105
*/
98106
function config(string $name, bool $getShared = true)
99107
{
100-
return \CodeIgniter\Config\Config::get($name, $getShared);
108+
return Config::get($name, $getShared);
101109
}
102110
}
103111

@@ -126,7 +134,7 @@ function config(string $name, bool $getShared = true)
126134
*/
127135
function db_connect($db = null, bool $getShared = true)
128136
{
129-
return \Config\Database::connect($db, $getShared);
137+
return Database::connect($db, $getShared);
130138
}
131139
}
132140

@@ -182,6 +190,7 @@ function view(string $name, array $data = [], array $options = []): string
182190
* @param string|null $cacheName
183191
*
184192
* @return string
193+
* @throws \ReflectionException
185194
*/
186195
function view_cell(string $library, $params = null, int $ttl = 0, string $cacheName = null): string
187196
{
@@ -281,7 +290,7 @@ function esc($data, string $context = 'html', string $encoding = null)
281290

282291
if (! in_array($context, ['html', 'js', 'css', 'url', 'attr']))
283292
{
284-
throw new \InvalidArgumentException('Invalid escape context provided.');
293+
throw new InvalidArgumentException('Invalid escape context provided.');
285294
}
286295

287296
if ($context === 'attr')
@@ -296,12 +305,12 @@ function esc($data, string $context = 'html', string $encoding = null)
296305
static $escaper;
297306
if (! $escaper)
298307
{
299-
$escaper = new \Zend\Escaper\Escaper($encoding);
308+
$escaper = new Escaper($encoding);
300309
}
301310

302311
if ($encoding && $escaper->getEncoding() !== $encoding)
303312
{
304-
$escaper = new \Zend\Escaper\Escaper($encoding);
313+
$escaper = new Escaper($encoding);
305314
}
306315

307316
$data = $escaper->$method($data);
@@ -471,7 +480,7 @@ function log_message(string $level, string $message, array $context = [])
471480
// for asserting that logs were called in the test code.
472481
if (ENVIRONMENT === 'testing')
473482
{
474-
$logger = new \Tests\Support\Log\TestLogger(new \Config\Logger());
483+
$logger = new TestLogger(new Logger());
475484

476485
return $logger->log($level, $message, $context);
477486
}
@@ -534,27 +543,27 @@ function route_to(string $method, ...$params)
534543
* between ascii characters, like Java\0script.
535544
*
536545
* @param string $str
537-
* @param boolean $url_encoded
546+
* @param boolean $urlEncoded
538547
*
539548
* @return string
540549
*/
541-
function remove_invisible_characters(string $str, bool $url_encoded = true): string
550+
function remove_invisible_characters(string $str, bool $urlEncoded = true): string
542551
{
543-
$non_displayables = [];
552+
$nonDisplayables = [];
544553

545554
// every control character except newline (dec 10),
546555
// carriage return (dec 13) and horizontal tab (dec 09)
547-
if ($url_encoded)
556+
if ($urlEncoded)
548557
{
549-
$non_displayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
550-
$non_displayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
558+
$nonDisplayables[] = '/%0[0-8bcef]/'; // url encoded 00-08, 11, 12, 14, 15
559+
$nonDisplayables[] = '/%1[0-9a-f]/'; // url encoded 16-31
551560
}
552561

553-
$non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
562+
$nonDisplayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
554563

555564
do
556565
{
557-
$str = preg_replace($non_displayables, '', $str, -1, $count);
566+
$str = preg_replace($nonDisplayables, '', $str, -1, $count);
558567
}
559568
while ($count);
560569

@@ -611,7 +620,7 @@ function helper($filenames)
611620

612621
if (empty($path))
613622
{
614-
throw \CodeIgniter\Files\Exceptions\FileNotFoundException::forFileNotFound($filename);
623+
throw FileNotFoundException::forFileNotFound($filename);
615624
}
616625

617626
$includes[] = $path;
@@ -687,7 +696,7 @@ function helper($filenames)
687696
*/
688697
function app_timezone(): string
689698
{
690-
$config = config(\Config\App::class);
699+
$config = config(App::class);
691700

692701
return $config->appTimezone;
693702
}
@@ -706,7 +715,7 @@ function app_timezone(): string
706715
*/
707716
function csrf_token(): string
708717
{
709-
$config = config(\Config\App::class);
718+
$config = config(App::class);
710719

711720
return $config->CSRFTokenName;
712721
}
@@ -797,7 +806,7 @@ function force_https(int $duration = 31536000, RequestInterface $request = null,
797806
$uri = $request->uri;
798807
$uri->setScheme('https');
799808

800-
$uri = \CodeIgniter\HTTP\URI::createURIString(
809+
$uri = URI::createURIString(
801810
$uri->getScheme(), $uri->getAuthority(true), $uri->getPath(), // Absolute URIs should use a "/" for an empty path
802811
$uri->getQuery(), $uri->getFragment()
803812
);
@@ -936,12 +945,13 @@ function stringify_attributes($attributes, bool $js = false): string
936945
* the file, based on the read-only attribute. is_writable() is also unreliable
937946
* on Unix servers if safe_mode is on.
938947
*
939-
* @link https://bugs.php.net/bug.php?id=54709
948+
* @link https://bugs.php.net/bug.php?id=54709
940949
*
941950
* @param string $file
942951
*
943952
* @return boolean
944953
*
954+
* @throws \Exception
945955
* @codeCoverageIgnore Not practical to test, as travis runs on linux
946956
*/
947957
function is_really_writable(string $file): bool
@@ -996,7 +1006,7 @@ function is_really_writable(string $file): bool
9961006
*/
9971007
function slash_item(string $item): ?string
9981008
{
999-
$config = config(\Config\App::class);
1009+
$config = config(App::class);
10001010
$configItem = $config->{$item};
10011011

10021012
if (! isset($configItem) || empty(trim($configItem)))

system/ComposerScripts.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
namespace CodeIgniter;
4040

41+
use ReflectionClass;
42+
4143
/**
4244
* ComposerScripts
4345
*
@@ -76,7 +78,7 @@ public static function postUpdate()
7678
*
7779
* @return boolean
7880
*/
79-
protected static function moveFile(string $source, string $destination)
81+
protected static function moveFile(string $source, string $destination): bool
8082
{
8183
$source = realpath($source);
8284

@@ -105,7 +107,7 @@ protected static function moveFile(string $source, string $destination)
105107
*/
106108
protected static function getClassFilePath(string $class)
107109
{
108-
$reflector = new \ReflectionClass($class);
110+
$reflector = new ReflectionClass($class);
109111

110112
return $reflector->getFileName();
111113
}

system/Model.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
namespace CodeIgniter;
4040

41+
use Closure;
4142
use CodeIgniter\Exceptions\ModelException;
4243
use Config\Database;
4344
use CodeIgniter\I18n\Time;
@@ -47,6 +48,9 @@
4748
use CodeIgniter\Database\ConnectionInterface;
4849
use CodeIgniter\Validation\ValidationInterface;
4950
use CodeIgniter\Database\Exceptions\DataException;
51+
use ReflectionClass;
52+
use ReflectionProperty;
53+
use stdClass;
5054

5155
/**
5256
* Class Model
@@ -354,11 +358,10 @@ public function find($id = null)
354358
/**
355359
* Fetches the column of database from $this->table
356360
*
357-
* @param string $column_name Column name
361+
* @param string $columnName
358362
*
359363
* @return array|null The resulting row of data, or null if no data found.
360364
*
361-
* @throws \CodeIgniter\Database\Exceptions\DataException
362365
*/
363366
public function findColumn(string $columnName)
364367
{
@@ -536,8 +539,8 @@ public static function classToArray($data, $primaryKey = null, string $dateForma
536539
}
537540
else
538541
{
539-
$mirror = new \ReflectionClass($data);
540-
$props = $mirror->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED);
542+
$mirror = new ReflectionClass($data);
543+
$props = $mirror->getProperties(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED);
541544

542545
$properties = [];
543546

@@ -619,10 +622,15 @@ public function insert($data = null, bool $returnID = true)
619622
$this->tempData = [];
620623
}
621624

625+
if (empty($data))
626+
{
627+
throw DataException::forEmptyDataset('insert');
628+
}
629+
622630
// If $data is using a custom class with public or protected
623631
// properties representing the table elements, we need to grab
624632
// them as an array.
625-
if (is_object($data) && ! $data instanceof \stdClass)
633+
if (is_object($data) && ! $data instanceof stdClass)
626634
{
627635
$data = static::classToArray($data, $this->primaryKey, $this->dateFormat, false);
628636
}
@@ -668,11 +676,6 @@ public function insert($data = null, bool $returnID = true)
668676

669677
$data = $this->trigger('beforeInsert', ['data' => $data]);
670678

671-
if (empty($data))
672-
{
673-
throw DataException::forEmptyDataset('insert');
674-
}
675-
676679
// Must use the set() method to ensure objects get converted to arrays
677680
$result = $this->builder()
678681
->set($data['data'], '', $escape)
@@ -749,10 +752,15 @@ public function update($id = null, $data = null): bool
749752
$this->tempData = [];
750753
}
751754

755+
if (empty($data))
756+
{
757+
throw DataException::forEmptyDataset('update');
758+
}
759+
752760
// If $data is using a custom class with public or protected
753761
// properties representing the table elements, we need to grab
754762
// them as an array.
755-
if (is_object($data) && ! $data instanceof \stdClass)
763+
if (is_object($data) && ! $data instanceof stdClass)
756764
{
757765
$data = static::classToArray($data, $this->primaryKey, $this->dateFormat);
758766
}
@@ -790,11 +798,6 @@ public function update($id = null, $data = null): bool
790798

791799
$data = $this->trigger('beforeUpdate', ['id' => $id, 'data' => $data]);
792800

793-
if (empty($data))
794-
{
795-
throw DataException::forEmptyDataset('update');
796-
}
797-
798801
$builder = $this->builder();
799802

800803
if ($id)
@@ -956,9 +959,9 @@ public function onlyDeleted()
956959
* @param null $data
957960
* @param boolean $returnSQL
958961
*
959-
* @return boolean TRUE on success, FALSE on failure
962+
* @return mixed
960963
*/
961-
public function replace($data = null, bool $returnSQL = false): bool
964+
public function replace($data = null, bool $returnSQL = false)
962965
{
963966
// Validate data before saving.
964967
if (! empty($data) && $this->skipValidation === false)
@@ -1019,7 +1022,7 @@ public function asObject(string $class = 'object')
10191022
*
10201023
* @throws \CodeIgniter\Database\Exceptions\DataException
10211024
*/
1022-
public function chunk(int $size, \Closure $userFunc)
1025+
public function chunk(int $size, Closure $userFunc)
10231026
{
10241027
$total = $this->builder()
10251028
->countAllResults(false);
@@ -1317,7 +1320,7 @@ public function setValidationMessage(string $field, array $fieldMessages)
13171320
* Validate the data against the validation rules (or the validation group)
13181321
* specified in the class property, $validationRules.
13191322
*
1320-
* @param array $data
1323+
* @param array|object $data
13211324
*
13221325
* @return boolean
13231326
*/

0 commit comments

Comments
 (0)