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

5.x phpstan 7 #994

Merged
merged 2 commits into from
Mar 4, 2024
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
3 changes: 0 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@
<NullArgument>
<code><![CDATA[$this->emailLog]]></code>
</NullArgument>
<PropertyTypeCoercion>
<code>new $className($config)</code>
</PropertyTypeCoercion>
</file>
<file src="src/Model/Table/LazyTableTrait.php">
<RiskyTruthyFalsyComparison>
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/ComposerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function executeComposerCommand(ArrayInput $input): BufferedOutput
putenv('COMPOSER_HOME=' . $bin);
putenv('COMPOSER_CACHE_DIR=' . CACHE);

$dir = getcwd();
$dir = (string)getcwd();
chdir(ROOT);
$timeLimit = ini_get('max_execution_time');
set_time_limit(300);
Expand Down
9 changes: 6 additions & 3 deletions src/Controller/MailPreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@
}
})
->unfold(function ($path, $plugin) {
foreach (glob($path . '*Preview.php') as $file) {
/** @var list<string> $files */
$files = glob($path . '*Preview.php');
foreach ($files as $file) {

Check warning on line 208 in src/Controller/MailPreviewController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/MailPreviewController.php#L207-L208

Added lines #L207 - L208 were not covered by tests
$base = str_replace('.php', '', basename($file));
$class = App::className($plugin . $base, 'Mailer/Preview');
if ($class) {
Expand Down Expand Up @@ -271,16 +273,17 @@
$plugin = "$plugin.";
}

/** @var \DebugKit\Mailer\MailPreview $realClass */
$realClass = App::className($plugin . $previewName, 'Mailer/Preview');
if (!$realClass) {
throw new NotFoundException("Mailer preview $previewName not found");
}
$mailPreview = new $realClass();

$email = $mailPreview->find($emailName);
if (!$email) {
if ($email === null) {
throw new NotFoundException(sprintf(
'Mailer preview %s::%s not found',
'Mailer preview `%s::%s` not found',

Check warning on line 286 in src/Controller/MailPreviewController.php

View check run for this annotation

Codecov / codecov/patch

src/Controller/MailPreviewController.php#L286

Added line #L286 was not covered by tests
$previewName,
$emailName
));
Expand Down
3 changes: 2 additions & 1 deletion src/DebugInclude.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public function __construct()
*/
public function includePaths(): array
{
$paths = explode(PATH_SEPARATOR, get_include_path());
/** @psalm-suppress RedundantCast */
$paths = explode(PATH_SEPARATOR, (string)get_include_path());
$paths = array_filter($paths, function ($path) {
if ($path === '.' || strlen($path) === 0) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/DebugSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public static function sql(
if (defined('CAKE_CORE_INCLUDE_PATH')) {
array_unshift($search, CAKE_CORE_INCLUDE_PATH);
}
/** @var string $file */
$file = str_replace($search, '', $file);
}

Expand Down
7 changes: 6 additions & 1 deletion src/Mailer/Transport/DebugKitTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function __construct(array $config = [], ?AbstractTransport $originalTran

$className = false;
if (!empty($config['originalClassName'])) {
/** @var class-string<\Cake\Mailer\AbstractTransport> $className */
$className = App::className(
$config['originalClassName'],
'Mailer/Transport',
Expand All @@ -56,6 +57,7 @@ public function __construct(array $config = [], ?AbstractTransport $originalTran

if ($className) {
unset($config['originalClassName'], $config['debugKitLog']);
/** @psalm-suppress UnsafeInstantiation */
$this->originalTransport = new $className($config);
}
}
Expand Down Expand Up @@ -91,7 +93,10 @@ public function send(Message $message): array
*/
public function __call(string $method, array $args): mixed
{
return call_user_func_array([$this->originalTransport, $method], $args);
/** @var callable $callable */
$callable = [$this->originalTransport, $method];

return call_user_func_array($callable, $args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could replace this with a first-class callable. $this->originalTransport->$method(...).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, u wanna add the commit on top? Currently not on the computer

}

/**
Expand Down
12 changes: 9 additions & 3 deletions src/Model/Behavior/TimedBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class TimedBehavior extends Behavior
*/
public function beforeFind(EventInterface $event, SelectQuery $query): SelectQuery
{
$alias = $event->getSubject()->getAlias();
/** @var \Cake\Datasource\RepositoryInterface $table */
$table = $event->getSubject();
$alias = $table->getAlias();
DebugTimer::start($alias . '_find', $alias . '->find()');

return $query->formatResults(function ($results) use ($alias) {
Expand All @@ -52,7 +54,9 @@ public function beforeFind(EventInterface $event, SelectQuery $query): SelectQue
*/
public function beforeSave(EventInterface $event): void
{
$alias = $event->getSubject()->getAlias();
/** @var \Cake\Datasource\RepositoryInterface $table */
$table = $event->getSubject();
$alias = $table->getAlias();
DebugTimer::start($alias . '_save', $alias . '->save()');
}

Expand All @@ -64,7 +68,9 @@ public function beforeSave(EventInterface $event): void
*/
public function afterSave(EventInterface $event): void
{
$alias = $event->getSubject()->getAlias();
/** @var \Cake\Datasource\RepositoryInterface $table */
$table = $event->getSubject();
$alias = $table->getAlias();
DebugTimer::stop($alias . '_save');
}
}
4 changes: 2 additions & 2 deletions src/Model/Entity/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Panel extends Entity
/**
* Some fields should not be in JSON/array exports.
*
* @var array<string>
* @var list<string>
*/
protected array $_hidden = ['content'];

Expand All @@ -47,7 +47,7 @@ class Panel extends Entity
protected function _getContent(mixed $content): string
{
if (is_resource($content)) {
return stream_get_contents($content);
return (string)stream_get_contents($content);
}

return $content;
Expand Down
14 changes: 7 additions & 7 deletions src/Panel/SessionPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ class SessionPanel extends DebugPanel
*/
public function shutdown(EventInterface $event): void
{
/** @var \Cake\Http\ServerRequest|null $request */
$request = $event->getSubject()->getRequest();
if ($request) {
$maxDepth = Configure::read('DebugKit.maxDepth', 5);
$content = Debugger::exportVarAsNodes($request->getSession()->read(), $maxDepth);
$this->_data = compact('content');
}
/** @var \Cake\Controller\Controller $controller */
$controller = $event->getSubject();
$request = $controller->getRequest();

$maxDepth = Configure::read('DebugKit.maxDepth', 5);
$content = Debugger::exportVarAsNodes($request->getSession()->read(), $maxDepth);
$this->_data = compact('content');
}
}
3 changes: 2 additions & 1 deletion src/Panel/SqlLogPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public function initialize(): void
}
$logger = new DebugLog($logger, $name, $includeSchemaReflection);

$connection->getDriver()->setLogger($logger);
/** @var \Cake\Database\Driver $driver */
$driver->setLogger($logger);

$this->_loggers[] = $logger;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ToolbarService.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function isEnabled(): bool
protected function isSuspiciouslyProduction(): bool
{
$host = parse_url('http://' . env('HTTP_HOST'), PHP_URL_HOST);
if ($host === false) {
if ($host === false || $host === null) {
return false;
}

Expand Down
Loading