Skip to content

Commit 229ecd1

Browse files
committed
More phpstan related fixes.
1 parent 35d5e8d commit 229ecd1

File tree

24 files changed

+52
-45
lines changed

24 files changed

+52
-45
lines changed

phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ parameters:
2020
- '#Result of method Cake\\Http\\Response::send\(\) \(void\) is used#'
2121
- '#Method Cake\\View\\Form\\ContextInterface::val\(\) invoked with 2 parameters, 1 required#'
2222
- '#Access to an undefined property Exception::\$queryString#'
23-
- '#Access to an undefined property PHPUnit\\Framework\\Test::\$fixtureManager#'
2423
- '#Method Redis::#'
2524
- '#Call to an undefined method Traversable::getArrayCopy().#'
2625
earlyTerminatingMethodCalls:

src/Cache/Engine/NullEngine.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public function init(array $config = [])
3737
*/
3838
public function gc($expires = null)
3939
{
40-
return false;
4140
}
4241

4342
/**

src/Controller/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
205205
/**
206206
* Automatically set to the name of a plugin.
207207
*
208-
* @var string
208+
* @var string|null
209209
*/
210210
public $plugin;
211211

src/Core/functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @param bool $double Encode existing html entities.
3232
* @param string|null $charset Character set to use when escaping. Defaults to config value in `mb_internal_encoding()`
3333
* or 'UTF-8'.
34-
* @return string Wrapped text.
34+
* @return string|array Wrapped text.
3535
* @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#h
3636
*/
3737
function h($text, $double = true, $charset = null)
@@ -189,7 +189,7 @@ function pj($var)
189189
*
190190
* @param string $key Environment variable name.
191191
* @param string|null $default Specify a default value in case the environment variable is not defined.
192-
* @return string|null Environment variable setting.
192+
* @return string|bool|null Environment variable setting.
193193
* @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#env
194194
*/
195195
function env($key, $default = null)

src/Database/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Represents a database driver containing all specificities for
2222
* a database engine including its SQL dialect.
2323
*
24-
* @property \Cake\Datasource\ConnectionInterface $_connection
24+
* @property \Cake\Datasource\ConnectionInterface|null $_connection
2525
*/
2626
abstract class Driver
2727
{

src/Datasource/FixtureInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function drop(ConnectionInterface $db);
4141
* Should insert all the records into the test database.
4242
*
4343
* @param \Cake\Datasource\ConnectionInterface $db An instance of the connection into which the records will be inserted.
44-
* @return bool on success or if there are no records to insert, or false on failure.
44+
* @return \Cake\Database\StatementInterface|bool on success or if there are no records to insert, or false on failure.
4545
*/
4646
public function insert(ConnectionInterface $db);
4747

src/Datasource/QueryTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ trait QueryTrait
8787
* When called with a Table argument, the default table object will be set
8888
* and this query object will be returned for chaining.
8989
*
90-
* @param \Cake\Datasource\RepositoryInterface|null $table The default table object to use
91-
* @return \Cake\Datasource\RepositoryInterface|$this
90+
* @param \Cake\Datasource\RepositoryInterface|\Cake\ORM\Table|null $table The default table object to use
91+
* @return \Cake\Datasource\RepositoryInterface|\Cake\ORM\Table|$this
9292
*/
9393
public function repository(RepositoryInterface $table = null)
9494
{

src/Filesystem/File.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ class File
4949
/**
5050
* Holds the file handler resource if the file is opened
5151
*
52-
* @var resource
52+
* @var resource|null
5353
* https://book.cakephp.org/3.0/en/core-libraries/file-folder.html#Cake\Filesystem\File::$handle
5454
*/
5555
public $handle;
5656

5757
/**
5858
* Enable locking for file reading and writing
5959
*
60-
* @var bool
60+
* @var bool|null
6161
* https://book.cakephp.org/3.0/en/core-libraries/file-folder.html#Cake\Filesystem\File::$lock
6262
*/
6363
public $lock;
@@ -67,7 +67,7 @@ class File
6767
*
6868
* Current file's absolute path
6969
*
70-
* @var mixed
70+
* @var string|null
7171
* https://book.cakephp.org/3.0/en/core-libraries/file-folder.html#Cake\Filesystem\File::$path
7272
*/
7373
public $path;

src/Http/Response.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class Response implements ResponseInterface
365365
/**
366366
* File object for file to be read out as response
367367
*
368-
* @var \Cake\Filesystem\File
368+
* @var \Cake\Filesystem\File|null
369369
*/
370370
protected $_file;
371371

@@ -493,7 +493,8 @@ public function send()
493493

494494
if ($this->_file) {
495495
$this->_sendFile($this->_file, $this->_fileRange);
496-
$this->_file = $this->_fileRange = null;
496+
$this->_file = null;
497+
$this->_fileRange = [];
497498
} else {
498499
$this->_sendContent($this->body());
499500
}
@@ -809,7 +810,7 @@ protected function _clearHeader($header)
809810
* if $content is null the current buffer is returned
810811
*
811812
* @param string|callable|null $content the string or callable message to be sent
812-
* @return string Current message buffer if $content param is passed as null
813+
* @return string|null Current message buffer if $content param is passed as null
813814
* @deprecated 3.4.0 Mutable response methods are deprecated. Use `withBody()` and `getBody()` instead.
814815
*/
815816
public function body($content = null)
@@ -1843,7 +1844,7 @@ public function length($bytes = null)
18431844
}
18441845

18451846
if ($this->hasHeader('Content-Length')) {
1846-
return $this->getHeaderLine('Content-Length');
1847+
return (int)$this->getHeaderLine('Content-Length');
18471848
}
18481849

18491850
return null;

src/Http/Runner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Runner
3333
/**
3434
* The middleware queue being run.
3535
*
36-
* @var MiddlewareQueue
36+
* @var \Cake\Http\MiddlewareQueue
3737
*/
3838
protected $middleware;
3939

src/I18n/DateFormatTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ trait DateFormatTrait
3737
/**
3838
* In-memory cache of date formatters
3939
*
40-
* @var IntlDateFormatter[]
40+
* @var \IntlDateFormatter[]
4141
*/
4242
protected static $_formatters = [];
4343

src/I18n/Number.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public static function currency($value, $currency = null, array $options = [])
243243
* @param string|bool|null $currency Default currency string to be used by currency()
244244
* if $currency argument is not provided. If boolean false is passed, it will clear the
245245
* currently stored value
246-
* @return string Currency
246+
* @return string|null Currency
247247
*/
248248
public static function defaultCurrency($currency = null)
249249
{

src/Mailer/Email.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,7 @@ public function addAttachments($attachments)
18301830
* Get generated message (used by transport classes)
18311831
*
18321832
* @param string|null $type Use MESSAGE_* constants or null to return the full message as array
1833-
* @return string|array String if have type, array if type is null
1833+
* @return string|array String if type is given, array if type is null
18341834
*/
18351835
public function message($type = null)
18361836
{
@@ -2218,7 +2218,7 @@ public function reset()
22182218
$this->_headers = [];
22192219
$this->_textMessage = '';
22202220
$this->_htmlMessage = '';
2221-
$this->_message = '';
2221+
$this->_message = [];
22222222
$this->_emailFormat = 'text';
22232223
$this->_transport = null;
22242224
$this->_priority = null;

src/Mailer/Mailer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ abstract class Mailer implements EventListenerInterface
179179
* Cloned Email instance for restoring instance after email is sent by
180180
* mailer action.
181181
*
182-
* @var string
182+
* @var \Cake\Mailer\Email
183183
*/
184184
protected $_clonedEmail;
185185

@@ -245,7 +245,7 @@ public function viewBuilder()
245245
*
246246
* @param string $method Method name.
247247
* @param array $args Method arguments
248-
* @return $this
248+
* @return $this|mixed
249249
*/
250250
public function __call($method, $args)
251251
{

src/Network/Socket.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,11 @@ public function setLastError($errNum, $errStr)
327327
/**
328328
* Write data to the socket.
329329
*
330+
* The bool false return value is deprecated and will be int 0 in the next major.
331+
* Please code respectively to be future proof.
332+
*
330333
* @param string $data The data to write to the socket.
331-
* @return int Bytes written.
334+
* @return int|false Bytes written.
332335
*/
333336
public function write($data)
334337
{
@@ -352,6 +355,9 @@ public function write($data)
352355
* Read data from the socket. Returns false if no data is available or no connection could be
353356
* established.
354357
*
358+
* The bool false return value is deprecated and will be null in the next major.
359+
* Please code respectively to be future proof.
360+
*
355361
* @param int $length Optional buffer length to read; defaults to 1024
356362
* @return mixed Socket data
357363
*/

src/ORM/Association.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ public function exists($conditions)
10591059
* @param mixed $conditions Conditions to be used, accepts anything Query::where()
10601060
* can take.
10611061
* @see \Cake\ORM\Table::updateAll()
1062-
* @return bool Success Returns true if one or more rows are affected.
1062+
* @return int Count Returns the affected rows.
10631063
*/
10641064
public function updateAll($fields, $conditions)
10651065
{

src/ORM/Association/BelongsToMany.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,9 @@ public function cascadeDelete(EntityInterface $entity, array $options = [])
609609

610610
$conditions = array_merge($conditions, $hasMany->getConditions());
611611

612-
return $table->deleteAll($conditions);
612+
$table->deleteAll($conditions);
613+
614+
return true;
613615
}
614616

615617
/**

src/ORM/Table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
170170
/**
171171
* Connection instance
172172
*
173-
* @var \Cake\Database\Connection
173+
* @var \Cake\Database\Connection|\Cake\Datasource\ConnectionInterface
174174
*/
175175
protected $_connection;
176176

@@ -482,7 +482,7 @@ public function registryAlias($registryAlias = null)
482482
/**
483483
* Sets the connection instance.
484484
*
485-
* @param \Cake\Datasource\ConnectionInterface $connection The connection instance
485+
* @param \Cake\Database\Connection|\Cake\Datasource\ConnectionInterface $connection The connection instance
486486
* @return $this
487487
*/
488488
public function setConnection(ConnectionInterface $connection)
@@ -495,7 +495,7 @@ public function setConnection(ConnectionInterface $connection)
495495
/**
496496
* Returns the connection instance.
497497
*
498-
* @return \Cake\Database\Connection
498+
* @return \Cake\Database\Connection|\Cake\Datasource\ConnectionInterface
499499
*/
500500
public function getConnection()
501501
{

src/TestSuite/ConsoleIntegrationTestCase.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,28 @@ class ConsoleIntegrationTestCase extends TestCase
3535
/**
3636
* Last exit code
3737
*
38-
* @var int
38+
* @var int|null
3939
*/
4040
protected $_exitCode;
4141

4242
/**
4343
* Console output stub
4444
*
45-
* @var ConsoleOutput
45+
* @var \Cake\Console\ConsoleOutput|\PHPUnit_Framework_MockObject_MockObject|null
4646
*/
4747
protected $_out;
4848

4949
/**
5050
* Console error output stub
5151
*
52-
* @var ConsoleOutput
52+
* @var \Cake\Console\ConsoleOutput|\PHPUnit_Framework_MockObject_MockObject|null
5353
*/
5454
protected $_err;
5555

5656
/**
5757
* Console input mock
5858
*
59-
* @var ConsoleInput
59+
* @var \Cake\Console\ConsoleInput|\PHPUnit_Framework_MockObject_MockObject|null
6060
*/
6161
protected $_in;
6262

@@ -190,7 +190,7 @@ protected function assertOutputContainsRow(array $row, $message = '')
190190
}, $row);
191191
$cells = implode('\s+\|\s+', $row);
192192
$pattern = '/' . $cells . '/';
193-
$this->assertOutputRegexp($pattern);
193+
$this->assertOutputRegExp($pattern);
194194
}
195195

196196
/**

src/TestSuite/Constraint/EventFired.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ class EventFired extends Constraint
1919
/**
2020
* Array of fired events
2121
*
22-
* @var EventManager
22+
* @var \Cake\Event\EventManager
2323
*/
2424
protected $_eventManager;
2525

2626
/**
2727
* Constructor
2828
*
29-
* @param EventManager $eventManager Event manager to check
29+
* @param \Cake\Event\EventManager $eventManager Event manager to check
3030
*/
3131
public function __construct($eventManager)
3232
{

src/TestSuite/Constraint/EventFiredWith.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class EventFiredWith extends Constraint
2222
/**
2323
* Array of fired events
2424
*
25-
* @var EventManager
25+
* @var \Cake\Event\EventManager
2626
*/
2727
protected $_eventManager;
2828

@@ -43,7 +43,7 @@ class EventFiredWith extends Constraint
4343
/**
4444
* Constructor
4545
*
46-
* @param EventManager $eventManager Event manager to check
46+
* @param \Cake\Event\EventManager $eventManager Event manager to check
4747
* @param string $dataKey Data key
4848
* @param string $dataValue Data value
4949
*/

src/TestSuite/Fixture/TestFixture.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class TestFixture implements FixtureInterface, TableSchemaInterface, TableSchema
7979
/**
8080
* The schema for this fixture.
8181
*
82-
* @var \Cake\Database\Schema\TableSchema
82+
* @var \Cake\Database\Schema\TableSchema|\Cake\Database\Schema\TableSchemaInterface
8383
*/
8484
protected $_schema;
8585

@@ -264,8 +264,8 @@ protected function _schemaFromReflection()
264264
/**
265265
* Gets/Sets the TableSchema instance used by this fixture.
266266
*
267-
* @param \Cake\Database\Schema\TableSchema|null $schema The table to set.
268-
* @return \Cake\Database\Schema\TableSchema|null
267+
* @param \Cake\Database\Schema\TableSchema|\Cake\Database\Schema\TableSchemaInterface|null $schema The table to set.
268+
* @return \Cake\Database\Schema\TableSchema|\Cake\Database\Schema\TableSchemaInterface|null
269269
* @deprecated 3.5.0 Use getTableSchema/setTableSchema instead.
270270
*/
271271
public function schema(TableSchema $schema = null)

src/View/Helper/FormHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ public function create($context = null, array $options = [])
476476
*
477477
* @param \Cake\View\Form\ContextInterface $context The context object to use.
478478
* @param array $options An array of options from create()
479-
* @return string The action attribute for the form.
479+
* @return string|array The action attribute for the form.
480480
*/
481481
protected function _formUrl($context, $options)
482482
{

tests/TestCase/Shell/Helper/TableHelperTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525
class TableHelperTest extends TestCase
2626
{
2727
/**
28-
* @var ConsoleOutput
28+
* @var \Cake\Console\ConsoleOutput
2929
*/
3030
public $stub;
3131

3232
/**
33-
* @var ConsoleIo
33+
* @var \Cake\Console\ConsoleIo
3434
*/
3535
public $io;
3636

3737
/**
38-
* @var TableHelper
38+
* @var \Cake\Shell\Helper\TableHelper
3939
*/
4040
public $helper;
4141

0 commit comments

Comments
 (0)