Skip to content

Import global classes but fully qualify functions and constants #4899

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion app/Config/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Database extends Config
*
* @var string
*/
public $filesPath = APPPATH . 'Database' . DIRECTORY_SEPARATOR;
public $filesPath = APPPATH . 'Database' . \DIRECTORY_SEPARATOR;

/**
* Lets you choose which connection group to
Expand Down
8 changes: 4 additions & 4 deletions app/Config/Mimes.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,11 @@ public static function guessTypeFromExtension(string $extension)
{
$extension = trim(strtolower($extension), '. ');

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

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

/**
Expand All @@ -512,7 +512,7 @@ public static function guessExtensionFromType(string $type, ?string $proposedExt
$proposedExtension = trim(strtolower($proposedExtension));

if ($proposedExtension !== '') {
if (array_key_exists($proposedExtension, static::$mimes) && in_array($type, is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension], true)) {
if (\array_key_exists($proposedExtension, static::$mimes) && \in_array($type, \is_string(static::$mimes[$proposedExtension]) ? [static::$mimes[$proposedExtension]] : static::$mimes[$proposedExtension], true)) {
// The detected mime type matches with the proposed extension.
return $proposedExtension;
}
Expand All @@ -524,7 +524,7 @@ public static function guessExtensionFromType(string $type, ?string $proposedExt
// Reverse check the mime type list if no extension was proposed.
// This search is order sensitive!
foreach (static::$mimes as $ext => $types) {
if ((is_string($types) && $types === $type) || (is_array($types) && in_array($type, $types, true))) {
if ((\is_string($types) && $types === $type) || (\is_array($types) && \in_array($type, $types, true))) {
return $ext;
}
}
Expand Down
6 changes: 3 additions & 3 deletions system/API/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function respond($data = null, ?int $status = null, string $message = '')
*/
public function fail($messages, int $status = 400, ?string $code = null, string $customMessage = '')
{
if (! is_array($messages)) {
if (! \is_array($messages)) {
$messages = ['error' => $messages];
}

Expand Down Expand Up @@ -305,7 +305,7 @@ public function failServerError(string $description = 'Internal Server Error', ?
protected function format($data = null)
{
// If the data is a string, there's not much we can do to it...
if (is_string($data)) {
if (\is_string($data)) {
// The content type should be text/... and not application/...
$contentType = $this->response->getHeaderLine('Content-Type');
$contentType = str_replace('application/json', 'text/html', $contentType);
Expand All @@ -320,7 +320,7 @@ protected function format($data = null)
$mime = "application/{$this->format}";

// Determine correct response type through content negotiation if not explicitly declared
if (empty($this->format) || ! in_array($this->format, ['json', 'xml'], true)) {
if (empty($this->format) || ! \in_array($this->format, ['json', 'xml'], true)) {
$mime = $this->request->negotiate('media', $format->getConfig()->supportedResponseFormats, false);
}

Expand Down
16 changes: 8 additions & 8 deletions system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function register()

// Load our non-class files
foreach ($this->files as $file) {
if (is_string($file)) {
if (\is_string($file)) {
$this->includeFile($file);
}
}
Expand All @@ -136,22 +136,22 @@ public function register()
*/
public function addNamespace($namespace, ?string $path = null)
{
if (is_array($namespace)) {
if (\is_array($namespace)) {
foreach ($namespace as $prefix => $namespacedPath) {
$prefix = trim($prefix, '\\');

if (is_array($namespacedPath)) {
if (\is_array($namespacedPath)) {
foreach ($namespacedPath as $dir) {
$this->prefixes[$prefix][] = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR;
$this->prefixes[$prefix][] = rtrim($dir, '\\/') . \DIRECTORY_SEPARATOR;
}

continue;
}

$this->prefixes[$prefix][] = rtrim($namespacedPath, '\\/') . DIRECTORY_SEPARATOR;
$this->prefixes[$prefix][] = rtrim($namespacedPath, '\\/') . \DIRECTORY_SEPARATOR;
}
} else {
$this->prefixes[trim($namespace, '\\')][] = rtrim($path, '\\/') . DIRECTORY_SEPARATOR;
$this->prefixes[trim($namespace, '\\')][] = rtrim($path, '\\/') . \DIRECTORY_SEPARATOR;
}

return $this;
Expand Down Expand Up @@ -196,7 +196,7 @@ public function loadClassmap(string $class)
{
$file = $this->classmap[$class] ?? '';

if (is_string($file) && $file !== '') {
if (\is_string($file) && $file !== '') {
return $this->includeFile($file);
}

Expand Down Expand Up @@ -237,7 +237,7 @@ protected function loadInNamespace(string $class)
$directory = rtrim($directory, '\\/');

if (strpos($class, $namespace) === 0) {
$filePath = $directory . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen($namespace))) . '.php';
$filePath = $directory . str_replace('\\', \DIRECTORY_SEPARATOR, substr($class, \strlen($namespace))) . '.php';
$filename = $this->includeFile($filePath);

if ($filename) {
Expand Down
8 changes: 4 additions & 4 deletions system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function locateFile(string $file, ?string $folder = null, string $ext = '

// Clears the folder name if it is at the beginning of the filename
if (! empty($folder) && strpos($file, $folder) === 0) {
$file = substr($file, strlen($folder . '/'));
$file = substr($file, \strlen($folder . '/'));
}

// Is not namespaced? Try the application folder.
Expand Down Expand Up @@ -203,7 +203,7 @@ protected function ensureExt(string $path, string $ext): string
if ($ext) {
$ext = '.' . $ext;

if (substr($path, -strlen($ext)) !== $ext) {
if (substr($path, -\strlen($ext)) !== $ext) {
$path .= $ext;
}
}
Expand All @@ -228,15 +228,15 @@ protected function getNamespaces()
if ($prefix === 'CodeIgniter') {
$system = [
'prefix' => $prefix,
'path' => rtrim($path, '\\/') . DIRECTORY_SEPARATOR,
'path' => rtrim($path, '\\/') . \DIRECTORY_SEPARATOR,
];

continue;
}

$namespaces[] = [
'prefix' => $prefix,
'path' => rtrim($path, '\\/') . DIRECTORY_SEPARATOR,
'path' => rtrim($path, '\\/') . \DIRECTORY_SEPARATOR,
];
}
}
Expand Down
48 changes: 24 additions & 24 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ abstract public function chunk(int $size, Closure $userFunc);
*/
public function find($id = null)
{
$singleton = is_numeric($id) || is_string($id);
$singleton = is_numeric($id) || \is_string($id);

if ($this->tempAllowCallbacks) {
// Call the before event and check for a return
Expand Down Expand Up @@ -721,11 +721,11 @@ public function insert($data = null, bool $returnID = true)
// Set created_at and updated_at with same time
$date = $this->setDate();

if ($this->useTimestamps && $this->createdField && ! array_key_exists($this->createdField, $data)) {
if ($this->useTimestamps && $this->createdField && ! \array_key_exists($this->createdField, $data)) {
$data[$this->createdField] = $date;
}

if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $data)) {
if ($this->useTimestamps && $this->updatedField && ! \array_key_exists($this->updatedField, $data)) {
$data[$this->updatedField] = $date;
}

Expand Down Expand Up @@ -773,19 +773,19 @@ public function insert($data = null, bool $returnID = true)
*/
public function insertBatch(?array $set = null, ?bool $escape = null, int $batchSize = 100, bool $testing = false)
{
if (is_array($set)) {
if (\is_array($set)) {
foreach ($set as &$row) {
// If $data is using a custom class with public or protected
// properties representing the collection elements, we need to grab
// them as an array.
if (is_object($row) && ! $row instanceof stdClass) {
if (\is_object($row) && ! $row instanceof stdClass) {
$row = $this->objectToArray($row, false, true);
}

// If it's still a stdClass, go ahead and convert to
// an array so doProtectFields and other model methods
// don't have to do special checks.
if (is_object($row)) {
if (\is_object($row)) {
$row = (array) $row;
}

Expand All @@ -801,11 +801,11 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
// Set created_at and updated_at with same time
$date = $this->setDate();

if ($this->useTimestamps && $this->createdField && ! array_key_exists($this->createdField, $row)) {
if ($this->useTimestamps && $this->createdField && ! \array_key_exists($this->createdField, $row)) {
$row[$this->createdField] = $date;
}

if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $row)) {
if ($this->useTimestamps && $this->updatedField && ! \array_key_exists($this->updatedField, $row)) {
$row[$this->updatedField] = $date;
}
}
Expand All @@ -825,7 +825,7 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
*/
public function update($id = null, $data = null): bool
{
if (is_numeric($id) || is_string($id)) {
if (is_numeric($id) || \is_string($id)) {
$id = [$id];
}

Expand All @@ -846,7 +846,7 @@ public function update($id = null, $data = null): bool
throw DataException::forEmptyDataset('update');
}

if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $data)) {
if ($this->useTimestamps && $this->updatedField && ! \array_key_exists($this->updatedField, $data)) {
$data[$this->updatedField] = $this->setDate();
}

Expand Down Expand Up @@ -889,19 +889,19 @@ public function update($id = null, $data = null): bool
*/
public function updateBatch(?array $set = null, ?string $index = null, int $batchSize = 100, bool $returnSQL = false)
{
if (is_array($set)) {
if (\is_array($set)) {
foreach ($set as &$row) {
// If $data is using a custom class with public or protected
// properties representing the collection elements, we need to grab
// them as an array.
if (is_object($row) && ! $row instanceof stdClass) {
if (\is_object($row) && ! $row instanceof stdClass) {
$row = $this->objectToArray($row, true, true);
}

// If it's still a stdClass, go ahead and convert to
// an array so doProtectFields and other model methods
// don't have to do special checks.
if (is_object($row)) {
if (\is_object($row)) {
$row = (array) $row;
}

Expand All @@ -922,7 +922,7 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
$row[$index] = $updateIndex;
}

if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField, $row)) {
if ($this->useTimestamps && $this->updatedField && ! \array_key_exists($this->updatedField, $row)) {
$row[$this->updatedField] = $this->setDate();
}
}
Expand All @@ -943,7 +943,7 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
*/
public function delete($id = null, bool $purge = false)
{
if ($id && (is_numeric($id) || is_string($id))) {
if ($id && (is_numeric($id) || \is_string($id))) {
$id = [$id];
}

Expand Down Expand Up @@ -1135,7 +1135,7 @@ protected function doProtectFields(array $data): array
}

foreach (array_keys($data) as $key) {
if (! in_array($key, $this->allowedFields, true)) {
if (! \in_array($key, $this->allowedFields, true)) {
unset($data[$key]);
}
}
Expand Down Expand Up @@ -1328,7 +1328,7 @@ public function validate($data): bool
}

//Validation requires array, so cast away.
if (is_object($data)) {
if (\is_object($data)) {
$data = (array) $data;
}

Expand All @@ -1355,7 +1355,7 @@ public function getValidationRules(array $options = []): array

// ValidationRules can be either a string, which is the group name,
// or an array of rules.
if (is_string($rules)) {
if (\is_string($rules)) {
$rules = $this->validation->loadRuleGroup($rules);
}

Expand Down Expand Up @@ -1392,7 +1392,7 @@ protected function cleanValidationRules(array $rules, ?array $data = null): arra
}

foreach (array_keys($rules) as $field) {
if (! array_key_exists($field, $data)) {
if (! \array_key_exists($field, $data)) {
unset($rules[$field]);
}
}
Expand Down Expand Up @@ -1562,7 +1562,7 @@ protected function objectToRawArray($data, bool $onlyChanged = true, bool $recur
*/
protected function transformDataToArray($data, string $type): array
{
if (! in_array($type, ['insert', 'update'], true)) {
if (! \in_array($type, ['insert', 'update'], true)) {
throw new InvalidArgumentException(sprintf('Invalid type "%s" used upon transforming data to array.', $type));
}

Expand All @@ -1573,14 +1573,14 @@ protected function transformDataToArray($data, string $type): array
// If $data is using a custom class with public or protected
// properties representing the collection elements, we need to grab
// them as an array.
if (is_object($data) && ! $data instanceof stdClass) {
if (\is_object($data) && ! $data instanceof stdClass) {
$data = $this->objectToArray($data, true, true);
}

// If it's still a stdClass, go ahead and convert to
// an array so doProtectFields and other model methods
// don't have to do special checks.
if (is_object($data)) {
if (\is_object($data)) {
$data = (array) $data;
}

Expand Down Expand Up @@ -1671,11 +1671,11 @@ protected function fillPlaceholders(array $rules, array $data): array

if (! empty($replacements)) {
foreach ($rules as &$rule) {
if (is_array($rule)) {
if (\is_array($rule)) {
foreach ($rule as &$row) {
// Should only be an `errors` array
// which doesn't take placeholders.
if (is_array($row)) {
if (\is_array($row)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion system/CLI/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function getPad(array $array, int $pad): int
$max = 0;

foreach (array_keys($array) as $key) {
$max = max($max, strlen($key));
$max = max($max, \strlen($key));
}

return $max + $pad;
Expand Down
Loading