Skip to content

Commit 3afc62e

Browse files
authored
Merge pull request #994 from cakephp/5.x-phpstan-7
5.x phpstan 7
2 parents 8dbb82e + cea4563 commit 3afc62e

File tree

11 files changed

+37
-23
lines changed

11 files changed

+37
-23
lines changed

psalm-baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@
6868
<NullArgument>
6969
<code><![CDATA[$this->emailLog]]></code>
7070
</NullArgument>
71-
<PropertyTypeCoercion>
72-
<code>new $className($config)</code>
73-
</PropertyTypeCoercion>
7471
</file>
7572
<file src="src/Model/Table/LazyTableTrait.php">
7673
<RiskyTruthyFalsyComparison>

src/Controller/ComposerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private function executeComposerCommand(ArrayInput $input): BufferedOutput
8585
putenv('COMPOSER_HOME=' . $bin);
8686
putenv('COMPOSER_CACHE_DIR=' . CACHE);
8787

88-
$dir = getcwd();
88+
$dir = (string)getcwd();
8989
chdir(ROOT);
9090
$timeLimit = ini_get('max_execution_time');
9191
set_time_limit(300);

src/Controller/MailPreviewController.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ protected function getMailPreviewClasses(): CollectionInterface
203203
}
204204
})
205205
->unfold(function ($path, $plugin) {
206-
foreach (glob($path . '*Preview.php') as $file) {
206+
/** @var list<string> $files */
207+
$files = glob($path . '*Preview.php');
208+
foreach ($files as $file) {
207209
$base = str_replace('.php', '', basename($file));
208210
$class = App::className($plugin . $base, 'Mailer/Preview');
209211
if ($class) {
@@ -271,16 +273,17 @@ protected function findPreview(string $previewName, string $emailName, string $p
271273
$plugin = "$plugin.";
272274
}
273275

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

280283
$email = $mailPreview->find($emailName);
281-
if (!$email) {
284+
if ($email === null) {
282285
throw new NotFoundException(sprintf(
283-
'Mailer preview %s::%s not found',
286+
'Mailer preview `%s::%s` not found',
284287
$previewName,
285288
$emailName
286289
));

src/DebugInclude.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public function __construct()
8282
*/
8383
public function includePaths(): array
8484
{
85-
$paths = explode(PATH_SEPARATOR, get_include_path());
85+
/** @psalm-suppress RedundantCast */
86+
$paths = explode(PATH_SEPARATOR, (string)get_include_path());
8687
$paths = array_filter($paths, function ($path) {
8788
if ($path === '.' || strlen($path) === 0) {
8889
return false;

src/DebugSql.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public static function sql(
9696
if (defined('CAKE_CORE_INCLUDE_PATH')) {
9797
array_unshift($search, CAKE_CORE_INCLUDE_PATH);
9898
}
99+
/** @var string $file */
99100
$file = str_replace($search, '', $file);
100101
}
101102

src/Mailer/Transport/DebugKitTransport.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function __construct(array $config = [], ?AbstractTransport $originalTran
4747

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

5758
if ($className) {
5859
unset($config['originalClassName'], $config['debugKitLog']);
60+
/** @psalm-suppress UnsafeInstantiation */
5961
$this->originalTransport = new $className($config);
6062
}
6163
}
@@ -91,7 +93,10 @@ public function send(Message $message): array
9193
*/
9294
public function __call(string $method, array $args): mixed
9395
{
94-
return call_user_func_array([$this->originalTransport, $method], $args);
96+
/** @var callable $callable */
97+
$callable = [$this->originalTransport, $method];
98+
99+
return call_user_func_array($callable, $args);
95100
}
96101

97102
/**

src/Model/Behavior/TimedBehavior.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class TimedBehavior extends Behavior
3434
*/
3535
public function beforeFind(EventInterface $event, SelectQuery $query): SelectQuery
3636
{
37-
$alias = $event->getSubject()->getAlias();
37+
/** @var \Cake\Datasource\RepositoryInterface $table */
38+
$table = $event->getSubject();
39+
$alias = $table->getAlias();
3840
DebugTimer::start($alias . '_find', $alias . '->find()');
3941

4042
return $query->formatResults(function ($results) use ($alias) {
@@ -52,7 +54,9 @@ public function beforeFind(EventInterface $event, SelectQuery $query): SelectQue
5254
*/
5355
public function beforeSave(EventInterface $event): void
5456
{
55-
$alias = $event->getSubject()->getAlias();
57+
/** @var \Cake\Datasource\RepositoryInterface $table */
58+
$table = $event->getSubject();
59+
$alias = $table->getAlias();
5660
DebugTimer::start($alias . '_save', $alias . '->save()');
5761
}
5862

@@ -64,7 +68,9 @@ public function beforeSave(EventInterface $event): void
6468
*/
6569
public function afterSave(EventInterface $event): void
6670
{
67-
$alias = $event->getSubject()->getAlias();
71+
/** @var \Cake\Datasource\RepositoryInterface $table */
72+
$table = $event->getSubject();
73+
$alias = $table->getAlias();
6874
DebugTimer::stop($alias . '_save');
6975
}
7076
}

src/Model/Entity/Panel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Panel extends Entity
3131
/**
3232
* Some fields should not be in JSON/array exports.
3333
*
34-
* @var array<string>
34+
* @var list<string>
3535
*/
3636
protected array $_hidden = ['content'];
3737

@@ -47,7 +47,7 @@ class Panel extends Entity
4747
protected function _getContent(mixed $content): string
4848
{
4949
if (is_resource($content)) {
50-
return stream_get_contents($content);
50+
return (string)stream_get_contents($content);
5151
}
5252

5353
return $content;

src/Panel/SessionPanel.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ class SessionPanel extends DebugPanel
3232
*/
3333
public function shutdown(EventInterface $event): void
3434
{
35-
/** @var \Cake\Http\ServerRequest|null $request */
36-
$request = $event->getSubject()->getRequest();
37-
if ($request) {
38-
$maxDepth = Configure::read('DebugKit.maxDepth', 5);
39-
$content = Debugger::exportVarAsNodes($request->getSession()->read(), $maxDepth);
40-
$this->_data = compact('content');
41-
}
35+
/** @var \Cake\Controller\Controller $controller */
36+
$controller = $event->getSubject();
37+
$request = $controller->getRequest();
38+
39+
$maxDepth = Configure::read('DebugKit.maxDepth', 5);
40+
$content = Debugger::exportVarAsNodes($request->getSession()->read(), $maxDepth);
41+
$this->_data = compact('content');
4242
}
4343
}

src/Panel/SqlLogPanel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public function initialize(): void
7474
}
7575
$logger = new DebugLog($logger, $name, $includeSchemaReflection);
7676

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

7980
$this->_loggers[] = $logger;
8081
}

0 commit comments

Comments
 (0)