Skip to content

Commit

Permalink
More phpstan related fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Nov 21, 2017
1 parent 35d5e8d commit 229ecd1
Show file tree
Hide file tree
Showing 24 changed files with 52 additions and 45 deletions.
1 change: 0 additions & 1 deletion phpstan.neon
Expand Up @@ -20,7 +20,6 @@ parameters:
- '#Result of method Cake\\Http\\Response::send\(\) \(void\) is used#'
- '#Method Cake\\View\\Form\\ContextInterface::val\(\) invoked with 2 parameters, 1 required#'
- '#Access to an undefined property Exception::\$queryString#'
- '#Access to an undefined property PHPUnit\\Framework\\Test::\$fixtureManager#'
- '#Method Redis::#'
- '#Call to an undefined method Traversable::getArrayCopy().#'
earlyTerminatingMethodCalls:
Expand Down
1 change: 0 additions & 1 deletion src/Cache/Engine/NullEngine.php
Expand Up @@ -37,7 +37,6 @@ public function init(array $config = [])
*/
public function gc($expires = null)
{
return false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Controller.php
Expand Up @@ -205,7 +205,7 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
/**
* Automatically set to the name of a plugin.
*
* @var string
* @var string|null
*/
public $plugin;

Expand Down
4 changes: 2 additions & 2 deletions src/Core/functions.php
Expand Up @@ -31,7 +31,7 @@
* @param bool $double Encode existing html entities.
* @param string|null $charset Character set to use when escaping. Defaults to config value in `mb_internal_encoding()`
* or 'UTF-8'.
* @return string Wrapped text.
* @return string|array Wrapped text.
* @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#h
*/
function h($text, $double = true, $charset = null)
Expand Down Expand Up @@ -189,7 +189,7 @@ function pj($var)
*
* @param string $key Environment variable name.
* @param string|null $default Specify a default value in case the environment variable is not defined.
* @return string|null Environment variable setting.
* @return string|bool|null Environment variable setting.
* @link https://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#env
*/
function env($key, $default = null)
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Driver.php
Expand Up @@ -21,7 +21,7 @@
* Represents a database driver containing all specificities for
* a database engine including its SQL dialect.
*
* @property \Cake\Datasource\ConnectionInterface $_connection
* @property \Cake\Datasource\ConnectionInterface|null $_connection
*/
abstract class Driver
{
Expand Down
2 changes: 1 addition & 1 deletion src/Datasource/FixtureInterface.php
Expand Up @@ -41,7 +41,7 @@ public function drop(ConnectionInterface $db);
* Should insert all the records into the test database.
*
* @param \Cake\Datasource\ConnectionInterface $db An instance of the connection into which the records will be inserted.
* @return bool on success or if there are no records to insert, or false on failure.
* @return \Cake\Database\StatementInterface|bool on success or if there are no records to insert, or false on failure.
*/
public function insert(ConnectionInterface $db);

Expand Down
4 changes: 2 additions & 2 deletions src/Datasource/QueryTrait.php
Expand Up @@ -87,8 +87,8 @@ trait QueryTrait
* When called with a Table argument, the default table object will be set
* and this query object will be returned for chaining.
*
* @param \Cake\Datasource\RepositoryInterface|null $table The default table object to use
* @return \Cake\Datasource\RepositoryInterface|$this
* @param \Cake\Datasource\RepositoryInterface|\Cake\ORM\Table|null $table The default table object to use
* @return \Cake\Datasource\RepositoryInterface|\Cake\ORM\Table|$this
*/
public function repository(RepositoryInterface $table = null)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Filesystem/File.php
Expand Up @@ -49,15 +49,15 @@ class File
/**
* Holds the file handler resource if the file is opened
*
* @var resource
* @var resource|null
* https://book.cakephp.org/3.0/en/core-libraries/file-folder.html#Cake\Filesystem\File::$handle
*/
public $handle;

/**
* Enable locking for file reading and writing
*
* @var bool
* @var bool|null
* https://book.cakephp.org/3.0/en/core-libraries/file-folder.html#Cake\Filesystem\File::$lock
*/
public $lock;
Expand All @@ -67,7 +67,7 @@ class File
*
* Current file's absolute path
*
* @var mixed
* @var string|null
* https://book.cakephp.org/3.0/en/core-libraries/file-folder.html#Cake\Filesystem\File::$path
*/
public $path;
Expand Down
9 changes: 5 additions & 4 deletions src/Http/Response.php
Expand Up @@ -365,7 +365,7 @@ class Response implements ResponseInterface
/**
* File object for file to be read out as response
*
* @var \Cake\Filesystem\File
* @var \Cake\Filesystem\File|null
*/
protected $_file;

Expand Down Expand Up @@ -493,7 +493,8 @@ public function send()

if ($this->_file) {
$this->_sendFile($this->_file, $this->_fileRange);
$this->_file = $this->_fileRange = null;
$this->_file = null;
$this->_fileRange = [];
} else {
$this->_sendContent($this->body());
}
Expand Down Expand Up @@ -809,7 +810,7 @@ protected function _clearHeader($header)
* if $content is null the current buffer is returned
*
* @param string|callable|null $content the string or callable message to be sent
* @return string Current message buffer if $content param is passed as null
* @return string|null Current message buffer if $content param is passed as null
* @deprecated 3.4.0 Mutable response methods are deprecated. Use `withBody()` and `getBody()` instead.
*/
public function body($content = null)
Expand Down Expand Up @@ -1843,7 +1844,7 @@ public function length($bytes = null)
}

if ($this->hasHeader('Content-Length')) {
return $this->getHeaderLine('Content-Length');
return (int)$this->getHeaderLine('Content-Length');
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Runner.php
Expand Up @@ -33,7 +33,7 @@ class Runner
/**
* The middleware queue being run.
*
* @var MiddlewareQueue
* @var \Cake\Http\MiddlewareQueue
*/
protected $middleware;

Expand Down
2 changes: 1 addition & 1 deletion src/I18n/DateFormatTrait.php
Expand Up @@ -37,7 +37,7 @@ trait DateFormatTrait
/**
* In-memory cache of date formatters
*
* @var IntlDateFormatter[]
* @var \IntlDateFormatter[]
*/
protected static $_formatters = [];

Expand Down
2 changes: 1 addition & 1 deletion src/I18n/Number.php
Expand Up @@ -243,7 +243,7 @@ public static function currency($value, $currency = null, array $options = [])
* @param string|bool|null $currency Default currency string to be used by currency()
* if $currency argument is not provided. If boolean false is passed, it will clear the
* currently stored value
* @return string Currency
* @return string|null Currency
*/
public static function defaultCurrency($currency = null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Mailer/Email.php
Expand Up @@ -1830,7 +1830,7 @@ public function addAttachments($attachments)
* Get generated message (used by transport classes)
*
* @param string|null $type Use MESSAGE_* constants or null to return the full message as array
* @return string|array String if have type, array if type is null
* @return string|array String if type is given, array if type is null
*/
public function message($type = null)
{
Expand Down Expand Up @@ -2218,7 +2218,7 @@ public function reset()
$this->_headers = [];
$this->_textMessage = '';
$this->_htmlMessage = '';
$this->_message = '';
$this->_message = [];
$this->_emailFormat = 'text';
$this->_transport = null;
$this->_priority = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Mailer/Mailer.php
Expand Up @@ -179,7 +179,7 @@ abstract class Mailer implements EventListenerInterface
* Cloned Email instance for restoring instance after email is sent by
* mailer action.
*
* @var string
* @var \Cake\Mailer\Email
*/
protected $_clonedEmail;

Expand Down Expand Up @@ -245,7 +245,7 @@ public function viewBuilder()
*
* @param string $method Method name.
* @param array $args Method arguments
* @return $this
* @return $this|mixed
*/
public function __call($method, $args)
{
Expand Down
8 changes: 7 additions & 1 deletion src/Network/Socket.php
Expand Up @@ -327,8 +327,11 @@ public function setLastError($errNum, $errStr)
/**
* Write data to the socket.
*
* The bool false return value is deprecated and will be int 0 in the next major.
* Please code respectively to be future proof.
*
* @param string $data The data to write to the socket.
* @return int Bytes written.
* @return int|false Bytes written.
*/
public function write($data)
{
Expand All @@ -352,6 +355,9 @@ public function write($data)
* Read data from the socket. Returns false if no data is available or no connection could be
* established.
*
* The bool false return value is deprecated and will be null in the next major.
* Please code respectively to be future proof.
*
* @param int $length Optional buffer length to read; defaults to 1024
* @return mixed Socket data
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Association.php
Expand Up @@ -1059,7 +1059,7 @@ public function exists($conditions)
* @param mixed $conditions Conditions to be used, accepts anything Query::where()
* can take.
* @see \Cake\ORM\Table::updateAll()
* @return bool Success Returns true if one or more rows are affected.
* @return int Count Returns the affected rows.
*/
public function updateAll($fields, $conditions)
{
Expand Down
4 changes: 3 additions & 1 deletion src/ORM/Association/BelongsToMany.php
Expand Up @@ -609,7 +609,9 @@ public function cascadeDelete(EntityInterface $entity, array $options = [])

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

return $table->deleteAll($conditions);
$table->deleteAll($conditions);

return true;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/ORM/Table.php
Expand Up @@ -170,7 +170,7 @@ class Table implements RepositoryInterface, EventListenerInterface, EventDispatc
/**
* Connection instance
*
* @var \Cake\Database\Connection
* @var \Cake\Database\Connection|\Cake\Datasource\ConnectionInterface
*/
protected $_connection;

Expand Down Expand Up @@ -482,7 +482,7 @@ public function registryAlias($registryAlias = null)
/**
* Sets the connection instance.
*
* @param \Cake\Datasource\ConnectionInterface $connection The connection instance
* @param \Cake\Database\Connection|\Cake\Datasource\ConnectionInterface $connection The connection instance
* @return $this
*/
public function setConnection(ConnectionInterface $connection)
Expand All @@ -495,7 +495,7 @@ public function setConnection(ConnectionInterface $connection)
/**
* Returns the connection instance.
*
* @return \Cake\Database\Connection
* @return \Cake\Database\Connection|\Cake\Datasource\ConnectionInterface
*/
public function getConnection()
{
Expand Down
10 changes: 5 additions & 5 deletions src/TestSuite/ConsoleIntegrationTestCase.php
Expand Up @@ -35,28 +35,28 @@ class ConsoleIntegrationTestCase extends TestCase
/**
* Last exit code
*
* @var int
* @var int|null
*/
protected $_exitCode;

/**
* Console output stub
*
* @var ConsoleOutput
* @var \Cake\Console\ConsoleOutput|\PHPUnit_Framework_MockObject_MockObject|null
*/
protected $_out;

/**
* Console error output stub
*
* @var ConsoleOutput
* @var \Cake\Console\ConsoleOutput|\PHPUnit_Framework_MockObject_MockObject|null
*/
protected $_err;

/**
* Console input mock
*
* @var ConsoleInput
* @var \Cake\Console\ConsoleInput|\PHPUnit_Framework_MockObject_MockObject|null
*/
protected $_in;

Expand Down Expand Up @@ -190,7 +190,7 @@ protected function assertOutputContainsRow(array $row, $message = '')
}, $row);
$cells = implode('\s+\|\s+', $row);
$pattern = '/' . $cells . '/';
$this->assertOutputRegexp($pattern);
$this->assertOutputRegExp($pattern);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/TestSuite/Constraint/EventFired.php
Expand Up @@ -19,14 +19,14 @@ class EventFired extends Constraint
/**
* Array of fired events
*
* @var EventManager
* @var \Cake\Event\EventManager
*/
protected $_eventManager;

/**
* Constructor
*
* @param EventManager $eventManager Event manager to check
* @param \Cake\Event\EventManager $eventManager Event manager to check
*/
public function __construct($eventManager)
{
Expand Down
4 changes: 2 additions & 2 deletions src/TestSuite/Constraint/EventFiredWith.php
Expand Up @@ -22,7 +22,7 @@ class EventFiredWith extends Constraint
/**
* Array of fired events
*
* @var EventManager
* @var \Cake\Event\EventManager
*/
protected $_eventManager;

Expand All @@ -43,7 +43,7 @@ class EventFiredWith extends Constraint
/**
* Constructor
*
* @param EventManager $eventManager Event manager to check
* @param \Cake\Event\EventManager $eventManager Event manager to check
* @param string $dataKey Data key
* @param string $dataValue Data value
*/
Expand Down
6 changes: 3 additions & 3 deletions src/TestSuite/Fixture/TestFixture.php
Expand Up @@ -79,7 +79,7 @@ class TestFixture implements FixtureInterface, TableSchemaInterface, TableSchema
/**
* The schema for this fixture.
*
* @var \Cake\Database\Schema\TableSchema
* @var \Cake\Database\Schema\TableSchema|\Cake\Database\Schema\TableSchemaInterface
*/
protected $_schema;

Expand Down Expand Up @@ -264,8 +264,8 @@ protected function _schemaFromReflection()
/**
* Gets/Sets the TableSchema instance used by this fixture.
*
* @param \Cake\Database\Schema\TableSchema|null $schema The table to set.
* @return \Cake\Database\Schema\TableSchema|null
* @param \Cake\Database\Schema\TableSchema|\Cake\Database\Schema\TableSchemaInterface|null $schema The table to set.
* @return \Cake\Database\Schema\TableSchema|\Cake\Database\Schema\TableSchemaInterface|null
* @deprecated 3.5.0 Use getTableSchema/setTableSchema instead.
*/
public function schema(TableSchema $schema = null)
Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/FormHelper.php
Expand Up @@ -476,7 +476,7 @@ public function create($context = null, array $options = [])
*
* @param \Cake\View\Form\ContextInterface $context The context object to use.
* @param array $options An array of options from create()
* @return string The action attribute for the form.
* @return string|array The action attribute for the form.
*/
protected function _formUrl($context, $options)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Shell/Helper/TableHelperTest.php
Expand Up @@ -25,17 +25,17 @@
class TableHelperTest extends TestCase
{
/**
* @var ConsoleOutput
* @var \Cake\Console\ConsoleOutput
*/
public $stub;

/**
* @var ConsoleIo
* @var \Cake\Console\ConsoleIo
*/
public $io;

/**
* @var TableHelper
* @var \Cake\Shell\Helper\TableHelper
*/
public $helper;

Expand Down

0 comments on commit 229ecd1

Please sign in to comment.