Skip to content

Commit

Permalink
Merge branch 'codeigniter4projects-develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
hex-ci committed Jan 31, 2024
2 parents 65c2146 + fe9ec00 commit 7a5d51f
Show file tree
Hide file tree
Showing 28 changed files with 565 additions and 434 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/infection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV

- name: Cache composer dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpcsfixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV

- name: Cache composer dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV

- name: Cache composer dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
Expand All @@ -64,7 +64,7 @@ jobs:
run: mkdir -p build/phpstan

- name: Cache PHPStan results
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: build/phpstan
key: ${{ runner.os }}-phpstan-${{ github.sha }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV

- name: Cache composer dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV

- name: Cache composer dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ hashFiles('**/composer.lock') }}
Expand Down
3 changes: 1 addition & 2 deletions app/Config/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class App extends BaseConfig
* 'http://accounts.example.com/':
* ['media.example.com', 'accounts.example.com']
*
* @var string[]
* @phpstan-var list<string>
* @var list<string>
*/
public array $allowedHostnames = [];

Expand Down
8 changes: 3 additions & 5 deletions app/Config/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Autoload extends AutoloadConfig
* 'App' => APPPATH
* ];
*
* @var array<string, string>
* @var array<string, list<string>|string>
*/
public $psr4 = [
APP_NAMESPACE => APPPATH, // For custom app namespace
Expand Down Expand Up @@ -80,8 +80,7 @@ class Autoload extends AutoloadConfig
* '/path/to/my/file.php',
* ];
*
* @var string[]
* @phpstan-var list<string>
* @var list<string>
*/
public $files = [];

Expand All @@ -94,8 +93,7 @@ class Autoload extends AutoloadConfig
* 'form',
* ];
*
* @var string[]
* @phpstan-var list<string>
* @var list<string>
*/
public $helpers = [];
}
3 changes: 2 additions & 1 deletion app/Config/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Config;

use CodeIgniter\Cache\CacheInterface;
use CodeIgniter\Cache\Handlers\DummyHandler;
use CodeIgniter\Cache\Handlers\FileHandler;
use CodeIgniter\Cache\Handlers\MemcachedHandler;
Expand Down Expand Up @@ -156,7 +157,7 @@ class Cache extends BaseConfig
* This is an array of cache engine alias' and class names. Only engines
* that are listed here are allowed to be used.
*
* @var array<string, string>
* @var array<string, class-string<CacheInterface>>
*/
public array $validHandlers = [
'dummy' => DummyHandler::class,
Expand Down
2 changes: 1 addition & 1 deletion app/Config/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Email extends BaseConfig
public string $mailPath = '/usr/sbin/sendmail';

/**
* SMTP Server Address
* SMTP Server Hostname
*/
public string $SMTPHost = '';

Expand Down
7 changes: 3 additions & 4 deletions app/Config/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class Filters extends BaseConfig
* Configures aliases for Filter classes to
* make reading things nicer and simpler.
*
* @var array<string, string>
* @phpstan-var array<string, class-string>
* @var array<string, class-string|list<class-string>> [filter_name => classname]
* or [filter_name => [classname1, classname2, ...]]
*/
public array $aliases = [
'csrf' => CSRF::class,
Expand All @@ -30,8 +30,7 @@ class Filters extends BaseConfig
* List of filter aliases that are always
* applied before and after every request.
*
* @var array<string, array<string, array<string, string>>>|array<string, array<string>>
* @phpstan-var array<string, list<string>>|array<string, array<string, array<string, string>>>
* @var array<string, array<string, array<string, string>>>|array<string, list<string>>
*/
public array $globals = [
'before' => [
Expand Down
16 changes: 13 additions & 3 deletions app/Config/Kint.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace Config;

use CodeIgniter\Config\BaseConfig;
use Kint\Parser\ConstructablePluginInterface;
use Kint\Renderer\AbstractRenderer;
use Kint\Renderer\Rich\TabPluginInterface;
use Kint\Renderer\Rich\ValuePluginInterface;

/**
* --------------------------------------------------------------------------
Expand All @@ -23,7 +26,11 @@ class Kint extends BaseConfig
|--------------------------------------------------------------------------
*/

/**
* @var list<class-string<ConstructablePluginInterface>|ConstructablePluginInterface>|null
*/
public $plugins;

public int $maxDepth = 6;
public bool $displayCalledFrom = true;
public bool $expanded = false;
Expand All @@ -35,13 +42,16 @@ class Kint extends BaseConfig
*/
public string $richTheme = 'aante-light.css';
public bool $richFolder = false;
public int $richSort = AbstractRenderer::SORT_FULL;

/**
* @psalm-suppress UndefinedClass
* @var array<string, class-string<ValuePluginInterface>>|null
*/
public int $richSort = AbstractRenderer::SORT_FULL;

public $richObjectPlugins;

/**
* @var array<string, class-string<TabPluginInterface>>|null
*/
public $richTabPlugins;

/*
Expand Down
4 changes: 1 addition & 3 deletions app/Config/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class Migrations extends BaseConfig
*
* This is the name of the table that will store the current migrations state.
* When migrations runs it will store in a database table which migration
* level the system is at. It then compares the migration level in this
* table to the $config['migration_version'] if they are not the same it
* will migrate up. This must be set.
* files have already been run.
*/
public string $table = 'migrations';

Expand Down
4 changes: 2 additions & 2 deletions app/Config/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Modules extends BaseModules
* ],
* ]
*
* @var array
* @var array{only?: list<string>, exclude?: list<string>}
*/
public $composerPackages = [];

Expand All @@ -72,7 +72,7 @@ class Modules extends BaseModules
*
* If it is not listed, only the base application elements will be used.
*
* @var string[]
* @var list<string>
*/
public $aliases = [
'events',
Expand Down
2 changes: 1 addition & 1 deletion app/Config/Publisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Publisher extends BasePublisher
* result in a PublisherException. Files that do no fit the
* pattern will cause copy/merge to fail.
*
* @var array<string,string>
* @var array<string, string>
*/
public $restrictions = [
ROOTPATH => '*',
Expand Down
2 changes: 1 addition & 1 deletion app/Config/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Session extends BaseConfig
* - `CodeIgniter\Session\Handlers\MemcachedHandler`
* - `CodeIgniter\Session\Handlers\RedisHandler`
*
* @phpstan-var class-string<BaseHandler>
* @var class-string<BaseHandler>
*/
public string $driver = FileHandler::class;

Expand Down
10 changes: 7 additions & 3 deletions app/Config/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
use CodeIgniter\Config\View as BaseView;
use CodeIgniter\View\ViewDecoratorInterface;

/**
* @phpstan-type ParserCallable (callable(mixed): mixed)
* @phpstan-type ParserCallableString (callable(mixed): mixed)&string
*/
class View extends BaseView
{
/**
Expand All @@ -31,7 +35,7 @@ class View extends BaseView
* { created_on|date(Y-m-d)|esc(attr) }
*
* @var array<string, string>
* @phpstan-var array<string, callable-string>
* @phpstan-var array<string, ParserCallableString>
*/
public $filters = [];

Expand All @@ -40,8 +44,8 @@ class View extends BaseView
* by the core Parser by creating aliases that will be replaced with
* any callable. Can be single or tag pair.
*
* @var array<string, string>
* @phpstan-var array<string, callable-string>
* @var array<string, array<string>|callable|string>
* @phpstan-var array<string, array<ParserCallableString>|ParserCallableString|ParserCallable>
*/
public $plugins = [];

Expand Down
2 changes: 1 addition & 1 deletion app/Entities/GitHub/URITrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __get(string $key)
$result = parent::__get($key);

if (is_string($result) && is_int(strpos($key, 'url'))) {
return empty($result) ? null : new URI($result);
return ($result === '') ? null : new URI($result);
}

return $result;
Expand Down
6 changes: 3 additions & 3 deletions app/Libraries/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function getRecentPosts(int $limit = 5, int $offset = 0, ?string $categor
$temp = $this->readPost($this->config->contentPath, $file);

// Only collect from the correct category.
if (! empty($category) && ! in_array($category, $temp->tags, true)) {
if ($category !== null && ! in_array($category, $temp->tags, true)) {
continue;
}

Expand Down Expand Up @@ -146,7 +146,7 @@ public function getPost(string $slug)
if (! $post = cache($cacheKey)) {
$files = glob("{$this->config->contentPath}*.{$slug}.md");

if (empty($files)) {
if ($files === [] || $files === false) {
throw PageNotFoundException::forPageNotFound();
}

Expand Down Expand Up @@ -227,7 +227,7 @@ protected function readPost(string $folder, string $filename)
{
$contents = file($folder . $filename);

if (empty($contents)) {
if ($contents === [] || $contents === false) {
return null;
}

Expand Down
17 changes: 13 additions & 4 deletions app/Views/errors/cli/error_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
use CodeIgniter\CLI\CLI;

// The main Exception
CLI::newLine();
CLI::write('[' . get_class($exception) . ']', 'light_gray', 'red');
CLI::newLine();
CLI::write($message);
CLI::newLine();
CLI::write('at ' . CLI::color(clean_path($exception->getFile()) . ':' . $exception->getLine(), 'green'));
CLI::newLine();

$last = $exception;

while ($prevException = $last->getPrevious()) {
$last = $prevException;

CLI::write(' Caused by:');
CLI::write(' [' . get_class($prevException) . ']', 'red');
CLI::write(' ' . $prevException->getMessage());
CLI::write(' at ' . CLI::color(clean_path($prevException->getFile()) . ':' . $prevException->getLine(), 'green'));
CLI::newLine();
}

// The backtrace
if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE) {
$backtraces = $exception->getTrace();
$backtraces = $last->getTrace();

if ($backtraces) {
CLI::write('Backtrace:', 'green');
Expand Down
30 changes: 28 additions & 2 deletions app/Views/errors/html/error_exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@
<?php endif; ?>
</div>

<div class="container">
<?php
$last = $exception;

while ($prevException = $last->getPrevious()) {
$last = $prevException;
?>

<pre>
Caused by:
<?= esc(get_class($prevException)), esc($prevException->getCode() ? ' #' . $prevException->getCode() : '') ?>

<?= nl2br(esc($prevException->getMessage())) ?>
<a href="https://www.duckduckgo.com/?q=<?= urlencode(get_class($prevException) . ' ' . preg_replace('#\'.*\'|".*"#Us', '', $prevException->getMessage())) ?>"
rel="noreferrer" target="_blank">search &rarr;</a>
<?= esc(clean_path($prevException->getFile()) . ':' . $prevException->getLine()) ?>
</pre>

<?php
}
?>
</div>

<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE) : ?>
<div class="container">

<ul class="tabs" id="tabs">
Expand All @@ -66,7 +90,7 @@
<li>
<p>
<!-- Trace info -->
<?php if (isset($row['file']) && is_file($row['file'])) :?>
<?php if (isset($row['file']) && is_file($row['file'])) : ?>
<?php
if (isset($row['function']) && in_array($row['function'], ['include', 'include_once', 'require', 'require_once'], true)) {
echo esc($row['function'] . ' ' . clean_path($row['file']));
Expand Down Expand Up @@ -375,14 +399,16 @@
</div> <!-- /tab-content -->

</div> <!-- /container -->
<?php endif; ?>

<div class="footer">
<div class="container">

<p>
Displayed at <?= esc(date('H:i:sa')) ?> &mdash;
PHP: <?= esc(PHP_VERSION) ?> &mdash;
CodeIgniter: <?= esc(CodeIgniter::CI_VERSION) ?>
CodeIgniter: <?= esc(CodeIgniter::CI_VERSION) ?> --
Environment: <?= ENVIRONMENT ?>
</p>

</div>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"slack": "https://codeigniterchat.slack.com"
},
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"codeigniter4/cache": "^1.0",
"codeigniter4/framework": "^4.2",
"guzzlehttp/guzzle": "^7.0.1",
Expand Down
Loading

0 comments on commit 7a5d51f

Please sign in to comment.