Skip to content

Commit

Permalink
More phpstan related fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Dec 12, 2017
1 parent ac148f5 commit bca167d
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions phpstan.neon
Expand Up @@ -22,6 +22,7 @@ parameters:
- '#Call to an undefined method Traversable::getArrayCopy().#'
- '#Variable \$config in isset\(\) is never defined#'
- '#Call to static method id\(\) on an unknown class PHPUnit_Runner_Version#'
- '#Call to an undefined method DateTimeInterface::i18nFormat\(\)#'
earlyTerminatingMethodCalls:
Cake\Shell\Shell:
- abort
Expand Down
2 changes: 1 addition & 1 deletion src/Core/ObjectRegistry.php
Expand Up @@ -117,6 +117,7 @@ public function load($objectName, $config = [])
*/
protected function _checkDuplicate($name, $config)
{
/** @var \Cake\Core\InstanceConfigTrait $existing */
$existing = $this->_loaded[$name];
$msg = sprintf('The "%s" alias has already been loaded', $name);
$hasConfig = method_exists($existing, 'config');
Expand All @@ -126,7 +127,6 @@ protected function _checkDuplicate($name, $config)
if (empty($config)) {
return;
}
/** @var \Cake\Core\InstanceConfigTrait $existing */
$existingConfig = $existing->getConfig();
unset($config['enabled'], $existingConfig['enabled']);

Expand Down
2 changes: 0 additions & 2 deletions src/I18n/RelativeTimeFormatter.php
Expand Up @@ -115,7 +115,6 @@ public function timeAgoInWords(DateTimeInterface $time, array $options = [])
}

if ($diff > abs($now - (new FrozenTime($options['end']))->format('U'))) {
/** @var \Cake\I18n\DateFormatTrait $time */
return sprintf($options['absoluteString'], $time->i18nFormat($options['format']));
}

Expand Down Expand Up @@ -306,7 +305,6 @@ public function dateAgoInWords(DateTimeInterface $date, array $options = [])
}

if ($diff > abs($now - (new FrozenDate($options['end']))->format('U'))) {
/** @var \Cake\I18n\DateFormatTrait $time */
return sprintf($options['absoluteString'], $date->i18nFormat($options['format']));
}

Expand Down
9 changes: 6 additions & 3 deletions src/ORM/Marshaller.php
Expand Up @@ -240,19 +240,22 @@ protected function _validate($data, $options, $isNew)
if (!$options['validate']) {
return [];
}

$validator = null;
if ($options['validate'] === true) {
$options['validate'] = $this->_table->getValidator();
$validator = $this->_table->getValidator();
}
if (is_string($options['validate'])) {
$options['validate'] = $this->_table->getValidator($options['validate']);
$validator = $this->_table->getValidator($options['validate']);
}
$options['validate'] = $validator;
if (!is_object($options['validate'])) {
throw new RuntimeException(
sprintf('validate must be a boolean, a string or an object. Got %s.', gettype($options['validate']))
);
}

return $options['validate']->errors($data, $isNew);
return $validator->errors($data, $isNew);
}

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

Expand Down Expand Up @@ -495,7 +495,7 @@ public function setConnection(ConnectionInterface $connection)
/**
* Returns the connection instance.
*
* @return \Cake\Database\Connection|\Cake\Datasource\ConnectionInterface
* @return \Cake\Database\Connection
*/
public function getConnection()
{
Expand Down
2 changes: 1 addition & 1 deletion 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|\Cake\Database\Schema\TableSchemaInterface
* @var \Cake\Database\Schema\TableSchema
*/
protected $_schema;

Expand Down
4 changes: 2 additions & 2 deletions src/View/Form/EntityContext.php
Expand Up @@ -17,6 +17,7 @@
use ArrayAccess;
use Cake\Collection\Collection;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\RepositoryInterface;
use Cake\Http\ServerRequest;
use Cake\ORM\TableRegistry;
use Cake\Utility\Inflector;
Expand Down Expand Up @@ -147,7 +148,7 @@ protected function _prepare()
$table = TableRegistry::get($table);
}

if (!is_object($table)) {
if (!($table instanceof RepositoryInterface)) {
throw new RuntimeException(
'Unable to find table class for current entity'
);
Expand All @@ -157,7 +158,6 @@ protected function _prepare()
$entity instanceof Traversable
);

/** @var \Cake\Datasource\RepositoryInterface $table */
$alias = $this->_rootName = $table->getAlias();
$this->_tables[$alias] = $table;
}
Expand Down

0 comments on commit bca167d

Please sign in to comment.