Skip to content

Commit fb177fb

Browse files
committed
Merge branch '4.x'
2 parents 417678a + 8809e11 commit fb177fb

28 files changed

+277
-262
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ env:
2222
matrix:
2323
fast_finish: true
2424

25+
include:
26+
- php: 7.2
27+
env: STATIC_ANALYSIS=1 DEFAULT=0
28+
2529
allow_failures:
2630
- php: 7.4snapshot
2731

@@ -31,10 +35,12 @@ install:
3135
before_script:
3236
- if [ $DB = 'mysql' ]; then mysql -u root -e 'CREATE DATABASE cakephp_test;'; fi
3337
- if [ $DB = 'pgsql' ]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi
38+
- if [[ $STATIC_ANALYSIS == 1 ]]; then composer require --dev psalm/phar:^3.6; fi
3439

3540
script:
3641
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi
3742
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.1 ]]; then vendor/bin/phpunit; fi
43+
- if [[ $STATIC_ANALYSIS == 1 ]]; then vendor/bin/psalm.phar --show-info=false; fi
3844

3945
after_success:
4046
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.1 ]]; then bash <(curl -s https://codecov.io/bash); fi

psalm-baseline.xml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<files psalm-version="3.6.5@b1aae0d1a5a11908e0e5f9eb6795ab7bb3f43577">
3+
<file src="src/Controller/DashboardController.php">
4+
<InvalidNullableReturnType occurrences="1">
5+
<code>\Cake\Http\Response</code>
6+
</InvalidNullableReturnType>
7+
<NullableReturnStatement occurrences="1">
8+
<code>$this-&gt;redirect(['action' =&gt; 'index'])</code>
9+
</NullableReturnStatement>
10+
</file>
11+
<file src="src/Controller/MailPreviewController.php">
12+
<PossiblyInvalidArgument occurrences="1">
13+
<code>$partType</code>
14+
</PossiblyInvalidArgument>
15+
</file>
16+
<file src="src/Database/Log/DebugLog.php">
17+
<InternalProperty occurrences="1">
18+
<code>$query-&gt;query</code>
19+
</InternalProperty>
20+
</file>
21+
<file src="src/DebugInclude.php">
22+
<InvalidNullableReturnType occurrences="1">
23+
<code>string</code>
24+
</InvalidNullableReturnType>
25+
<PossiblyNullArrayOffset occurrences="2">
26+
<code>$this-&gt;_pluginPaths</code>
27+
<code>$this-&gt;_composerPaths</code>
28+
</PossiblyNullArrayOffset>
29+
<PossiblyNullOperand occurrences="1">
30+
<code>$name</code>
31+
</PossiblyNullOperand>
32+
</file>
33+
<file src="src/DebugSql.php">
34+
<InternalMethod occurrences="1">
35+
<code>bindings</code>
36+
</InternalMethod>
37+
</file>
38+
<file src="src/DebugTimer.php">
39+
<PossiblyNullArrayOffset occurrences="1">
40+
<code>self::$_timers</code>
41+
</PossiblyNullArrayOffset>
42+
</file>
43+
<file src="src/Log/Engine/DebugKitLog.php">
44+
<MoreSpecificImplementedParamType occurrences="1">
45+
<code>$type</code>
46+
</MoreSpecificImplementedParamType>
47+
</file>
48+
<file src="src/Mailer/MailPreview.php">
49+
<PossiblyFalseOperand occurrences="1">
50+
<code>$pos</code>
51+
</PossiblyFalseOperand>
52+
</file>
53+
<file src="src/Mailer/Transport/DebugKitTransport.php">
54+
<InvalidReturnStatement occurrences="1">
55+
<code>$result</code>
56+
</InvalidReturnStatement>
57+
<MoreSpecificReturnType occurrences="1">
58+
<code>array</code>
59+
</MoreSpecificReturnType>
60+
<PropertyTypeCoercion occurrences="1">
61+
<code>new $className($config)</code>
62+
</PropertyTypeCoercion>
63+
</file>
64+
<file src="src/Middleware/DebugKitMiddleware.php">
65+
<ArgumentTypeCoercion occurrences="1">
66+
<code>$request</code>
67+
</ArgumentTypeCoercion>
68+
</file>
69+
<file src="src/Model/Table/LazyTableTrait.php">
70+
<UndefinedClass occurrences="1">
71+
<code>new $class($connection-&gt;configName())</code>
72+
</UndefinedClass>
73+
</file>
74+
<file src="src/Panel/DeprecationsPanel.php">
75+
<InvalidScalarArgument occurrences="4">
76+
<code>$pluginName</code>
77+
<code>$vendorName</code>
78+
<code>$return['plugins']</code>
79+
<code>$return['vendor']</code>
80+
</InvalidScalarArgument>
81+
</file>
82+
<file src="src/Panel/EnvironmentPanel.php">
83+
<PossiblyInvalidArgument occurrences="1">
84+
<code>$var['user']</code>
85+
</PossiblyInvalidArgument>
86+
</file>
87+
<file src="src/Panel/IncludePanel.php">
88+
<InvalidScalarArgument occurrences="4">
89+
<code>$pluginName</code>
90+
<code>$vendorName</code>
91+
<code>$return['plugins']</code>
92+
<code>$return['vendor']</code>
93+
</InvalidScalarArgument>
94+
</file>
95+
<file src="src/Panel/LogPanel.php">
96+
<UndefinedInterfaceMethod occurrences="1">
97+
<code>count</code>
98+
</UndefinedInterfaceMethod>
99+
</file>
100+
<file src="src/Panel/MailPanel.php">
101+
<ArgumentTypeCoercion occurrences="1">
102+
<code>$transport</code>
103+
</ArgumentTypeCoercion>
104+
</file>
105+
<file src="src/Panel/PanelRegistry.php">
106+
<ArgumentTypeCoercion occurrences="1">
107+
<code>$instance</code>
108+
</ArgumentTypeCoercion>
109+
<LessSpecificImplementedReturnType occurrences="1">
110+
<code>string|null</code>
111+
</LessSpecificImplementedReturnType>
112+
<LessSpecificReturnStatement occurrences="1">
113+
<code>$instance</code>
114+
</LessSpecificReturnStatement>
115+
<MoreSpecificImplementedParamType occurrences="1">
116+
<code>$class</code>
117+
</MoreSpecificImplementedParamType>
118+
<MoreSpecificReturnType occurrences="1">
119+
<code>\DebugKit\DebugPanel</code>
120+
</MoreSpecificReturnType>
121+
</file>
122+
<file src="src/Panel/SqlLogPanel.php">
123+
<UndefinedInterfaceMethod occurrences="1">
124+
<code>genericInstances</code>
125+
</UndefinedInterfaceMethod>
126+
</file>
127+
<file src="src/Panel/VariablesPanel.php">
128+
<InvalidArgument occurrences="1">
129+
<code>$item</code>
130+
</InvalidArgument>
131+
<PossiblyInvalidArgument occurrences="3">
132+
<code>$item</code>
133+
<code>$item</code>
134+
<code>$item</code>
135+
</PossiblyInvalidArgument>
136+
</file>
137+
<file src="src/Plugin.php">
138+
<InvalidArgument occurrences="1"/>
139+
</file>
140+
<file src="src/ToolbarService.php">
141+
<InvalidScalarArgument occurrences="1">
142+
<code>$row-&gt;id</code>
143+
</InvalidScalarArgument>
144+
<PossiblyNullOperand occurrences="1">
145+
<code>env('HTTP_HOST')</code>
146+
</PossiblyNullOperand>
147+
<TypeDoesNotContainType occurrences="1">
148+
<code>$url === false</code>
149+
</TypeDoesNotContainType>
150+
</file>
151+
<file src="src/View/Helper/ToolbarHelper.php">
152+
<InvalidArgument occurrences="1">
153+
<code>$value</code>
154+
</InvalidArgument>
155+
</file>
156+
</files>

psalm.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
totallyTyped="false"
4+
resolveFromConfigFile="true"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xmlns="https://getpsalm.org/schema/config"
7+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
8+
autoloader="tests/bootstrap.php"
9+
usePhpDocMethodsWithoutMagicCall="true"
10+
errorBaseline="psalm-baseline.xml"
11+
>
12+
<projectFiles>
13+
<directory name="src" />
14+
<ignoreFiles>
15+
<directory name="vendor" />
16+
</ignoreFiles>
17+
</projectFiles>
18+
19+
<issueHandlers>
20+
<LessSpecificReturnType errorLevel="info" />
21+
22+
<MissingClosureReturnType errorLevel="info" />
23+
24+
<PropertyNotSetInConstructor errorLevel="info" />
25+
<MissingConstructor errorLevel="info" />
26+
<MissingClosureParamType errorLevel="info" />
27+
<MissingParamType errorLevel="info" />
28+
29+
<DocblockTypeContradiction errorLevel="info" />
30+
<RedundantConditionGivenDocblockType errorLevel="info" />
31+
</issueHandlers>
32+
</psalm>

src/Cache/Engine/DebugEngine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function get($key, $default = null)
161161
/**
162162
* {@inheritDoc}
163163
*/
164-
public function getMultiple($keys, $default = null): array
164+
public function getMultiple($keys, $default = null): iterable
165165
{
166166
$this->_track('get');
167167
DebugTimer::start('Cache.getMultiple');

src/Command/BenchmarkCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
*/
1616
namespace DebugKit\Command;
1717

18+
use Cake\Command\Command;
1819
use Cake\Console\Arguments;
19-
use Cake\Console\Command;
2020
use Cake\Console\ConsoleIo;
2121
use Cake\Console\ConsoleOptionParser;
2222
use Cake\Utility\Text;
@@ -51,6 +51,7 @@ class BenchmarkCommand extends Command
5151
public function execute(Arguments $args, ConsoleIo $io): ?int
5252
{
5353
$this->io = $io;
54+
/** @var string $url */
5455
$url = $args->getArgumentAt(0);
5556
$defaults = ['t' => 100, 'n' => 10];
5657
$options = array_merge($defaults, $args->getOptions());

src/Controller/ComposerController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function initialize(): void
4242
/**
4343
* Before filter handler.
4444
*
45-
* @param \Cake\Event\Event $event The event.
45+
* @param \Cake\Event\EventInterface $event The event.
4646
* @return void
4747
* @throws \Cake\Http\Exception\NotFoundException
4848
*/

src/Controller/DashboardController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919

2020
/**
2121
* Dashboard and common DebugKit backend.
22+
*
23+
* @property \DebugKit\Model\Table\RequestsTable $Requests
2224
*/
2325
class DashboardController extends Controller
2426
{
2527
/**
2628
* Before filter handler.
2729
*
28-
* @param \Cake\Event\Event $event The event.
30+
* @param \Cake\Event\EventInterface $event The event.
2931
* @return void
3032
* @throws \Cake\Http\Exception\NotFoundException
3133
*/
@@ -43,7 +45,7 @@ public function beforeFilter(EventInterface $event)
4345
* Dashboard.
4446
*
4547
* @return void
46-
* @throws \Cake\Network\Exception\NotFoundException
48+
* @throws \Cake\Http\Exception\NotFoundException
4749
*/
4850
public function index()
4951
{

src/Controller/MailPreviewController.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function index()
7575
*
7676
* @param string $panelId The Mail panel id where the email data is stored.
7777
* @param string $number The email number as stored in the logs.
78-
* @return \Psr\Http\Message\ResponseInterface|null.
78+
* @return \Psr\Http\Message\ResponseInterface|null
7979
*/
8080
public function sent($panelId, $number)
8181
{
@@ -93,16 +93,21 @@ public function sent($panelId, $number)
9393
$email = $content['emails'][$number];
9494
$email = new SentMailResult(array_filter($email['headers']), $email['message']);
9595

96+
/** @var string $partType */
9697
$partType = $this->request->getQuery('part');
9798
if ($partType) {
9899
return $this->respondWithPart($email, $partType);
99100
}
100101

102+
/** @var string $part */
103+
$part = $this->request->getQuery('part');
101104
$this->set('noHeader', true);
102105
$this->set('email', $email);
103106
$this->set('plugin', '');
104-
$this->set('part', $this->findPreferredPart($email, $this->request->getQuery('part')));
107+
$this->set('part', $this->findPreferredPart($email, $part));
105108
$this->viewBuilder()->setTemplate('email');
109+
110+
return null;
106111
}
107112

108113
/**
@@ -120,6 +125,7 @@ public function email($name, $method)
120125
// in a plugin less request context.
121126
Router::setRequest($this->request->withParam('plugin', null));
122127

128+
/** @var string $plugin */
123129
$plugin = $this->request->getQuery('plugin');
124130
$email = $this->findPreview($name, $method, $plugin);
125131
$partType = $this->request->getQuery('part');
@@ -128,25 +134,31 @@ public function email($name, $method)
128134

129135
if ($partType) {
130136
$result = $this->respondWithPart($email, $partType);
131-
Router::setRequest($restore);
137+
if ($restore) {
138+
Router::setRequest($restore);
139+
}
132140

133141
return $result;
134142
}
135143

136144
$humanName = Inflector::humanize(Inflector::underscore($name) . "_$method");
145+
/** @var string $part */
146+
$part = $this->request->getQuery('part');
137147
$this->set('title', $humanName);
138148
$this->set('email', $email);
139149
$this->set('plugin', $plugin);
140-
$this->set('part', $this->findPreferredPart($email, $this->request->getQuery('part')));
150+
$this->set('part', $this->findPreferredPart($email, $part));
141151

142-
Router::setRequest($restore);
152+
if ($restore) {
153+
Router::setRequest($restore);
154+
}
143155
}
144156

145157
/**
146158
* Returns a response object with the requested part type for the
147159
* email or throws an exception, if no such part exists.
148160
*
149-
* @param \Debugkit\Mailer\AbstractResult $email the email to preview
161+
* @param \DebugKit\Mailer\AbstractResult $email the email to preview
150162
* @param string $partType The email part to retrieve
151163
* @return \Psr\Http\Message\ResponseInterface
152164
*/
@@ -160,7 +172,7 @@ protected function respondWithPart($email, $partType)
160172

161173
$response = $this->response->withType($partType);
162174
if ($partType === 'text') {
163-
$part = '<pre>' . $part . "</pre>";
175+
$part = '<pre>' . (string)$part . "</pre>";
164176
}
165177
$response = $response->withStringBody($part);
166178

@@ -170,7 +182,7 @@ protected function respondWithPart($email, $partType)
170182
/**
171183
* Retrieves an array of MailPreview objects
172184
*
173-
* @return \Cake\Core\CollectionInterface
185+
* @return \Cake\Collection\CollectionInterface
174186
*/
175187
protected function getMailPreviews()
176188
{
@@ -180,7 +192,7 @@ protected function getMailPreviews()
180192
/**
181193
* Returns an array of MailPreview class names for the app and plugins
182194
*
183-
* @return \Cake\Core\CollectionInterface
195+
* @return \Cake\Collection\CollectionInterface
184196
*/
185197
protected function getMailPreviewClasses()
186198
{
@@ -260,11 +272,11 @@ protected function findPreferredPart(AbstractResult $email, $partType)
260272
*
261273
* @param string $previewName The Mailer name
262274
* @param string $emailName The mailer preview method
263-
* @param string|null $plugin The plugin where the mailer preview should be found
275+
* @param string $plugin The plugin where the mailer preview should be found
264276
* @return \DebugKit\Mailer\PreviewResult The result of the email preview
265277
* @throws \Cake\Http\Exception\NotFoundException
266278
*/
267-
protected function findPreview($previewName, $emailName, $plugin = null)
279+
protected function findPreview($previewName, $emailName, $plugin = '')
268280
{
269281
if ($plugin) {
270282
$plugin = "$plugin.";

0 commit comments

Comments
 (0)