Skip to content

Commit

Permalink
Fix type errors reported by psalm.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Sep 1, 2019
1 parent 82626d6 commit c8c0e6d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 30 deletions.
14 changes: 0 additions & 14 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -966,20 +966,6 @@
<code>$query-&gt;isAutoFieldsEnabled()</code>
</PossiblyNullPropertyAssignmentValue>
</file>
<file src="src/ORM/Table.php">
<MoreSpecificImplementedParamType occurrences="1">
<code>$options</code>
</MoreSpecificImplementedParamType>
<PossiblyInvalidArgument occurrences="3">
<code>$options</code>
<code>$options</code>
<code>$options</code>
</PossiblyInvalidArgument>
<PossiblyNullArgument occurrences="2">
<code>$type</code>
<code>$typeName</code>
</PossiblyNullArgument>
</file>
<file src="src/Routing/Exception/DuplicateNamedRouteException.php">
<MissingParamType occurrences="1">
<code>$message</code>
Expand Down
8 changes: 4 additions & 4 deletions src/Datasource/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public function hasField(string $field): bool;
* type of search that was selected.
*
* @param string $type the type of query to perform
* @param array|\ArrayAccess $options An array that will be passed to Query::applyOptions()
* @param array $options An array that will be passed to Query::applyOptions()
* @return \Cake\Datasource\QueryInterface
*/
public function find(string $type = 'all', $options = []);
public function find(string $type = 'all', array $options = []);

/**
* Returns a single record after finding it by its primary key, if no record is
Expand All @@ -84,13 +84,13 @@ public function find(string $type = 'all', $options = []);
* ```
*
* @param mixed $primaryKey primary key value to find
* @param array|\ArrayAccess $options options accepted by `Table::find()`
* @param array $options options accepted by `Table::find()`
* @throws \Cake\Datasource\Exception\RecordNotFoundException if the record with such id
* could not be found
* @return \Cake\Datasource\EntityInterface
* @see \Cake\Datasource\RepositoryInterface::find()
*/
public function get($primaryKey, $options = []): EntityInterface;
public function get($primaryKey, array $options = []): EntityInterface;

/**
* Creates a new Query instance for this repository
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/BehaviorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ public function call(string $method, array $args = [])
*
* @param string $type The finder type to invoke.
* @param array $args The arguments you want to invoke the method with.
* @return mixed The return value depends on the underlying behavior method.
* @return \Cake\ORM\Query The return value depends on the underlying behavior method.
* @throws \BadMethodCallException When the method is unknown.
*/
public function callFinder(string $type, array $args = [])
public function callFinder(string $type, array $args = []): Query
{
$type = strtolower($type);

Expand Down
12 changes: 7 additions & 5 deletions src/ORM/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1185,10 +1185,10 @@ public function belongsToMany(string $associated, array $options = []): BelongsT
* Would invoke the `findPublished` method.
*
* @param string $type the type of query to perform
* @param array|\ArrayAccess $options An array that will be passed to Query::applyOptions()
* @param array $options An array that will be passed to Query::applyOptions()
* @return \Cake\ORM\Query The query builder
*/
public function find(string $type = 'all', $options = []): Query
public function find(string $type = 'all', array $options = []): Query
{
$query = $this->query();
$query->select();
Expand Down Expand Up @@ -1730,7 +1730,7 @@ public function exists($conditions): bool
* ```
*
* @param \Cake\Datasource\EntityInterface $entity
* @param array $options
* @param array|\ArrayAccess|\Cake\ORM\SaveOptionsBuilder $options
* @return \Cake\Datasource\EntityInterface|false
* @throws \Cake\ORM\Exception\RolledbackTransactionException If the transaction is aborted in the afterSave event.
*/
Expand Down Expand Up @@ -1962,6 +1962,7 @@ protected function _insert(EntityInterface $entity, array $data)
foreach ($primary as $key => $v) {
if (!isset($data[$key])) {
$id = $statement->lastInsertId($this->getTable(), $key);
/** @var string $type */
$type = $schema->getColumnType($key);
$entity->set($key, TypeFactory::build($type)->toPHP($id, $driver));
break;
Expand Down Expand Up @@ -1991,6 +1992,7 @@ protected function _newId(array $primary)
if (!$primary || count((array)$primary) > 1) {
return null;
}
/** @var string $typeName */
$typeName = $this->getSchema()->getColumnType($primary[0]);
$type = TypeFactory::build($typeName);

Expand Down Expand Up @@ -2051,7 +2053,7 @@ protected function _update(EntityInterface $entity, array $data)
* error.
*
* @param \Cake\Datasource\EntityInterface[]|\Cake\Datasource\ResultSetInterface $entities Entities to save.
* @param array|\ArrayAccess $options Options used when calling Table::save() for each entity.
* @param array|\ArrayAccess|\Cake\ORM\SaveOptionsBuilder $options Options used when calling Table::save() for each entity.
* @return \Cake\Datasource\EntityInterface[]|\Cake\Datasource\ResultSetInterface|false False on failure, entities list on success.
* @throws \Exception
*/
Expand Down Expand Up @@ -2084,7 +2086,7 @@ public function saveManyOrFail(iterable $entities, $options = []): iterable

/**
* @param \Cake\Datasource\EntityInterface[]|\Cake\Datasource\ResultSetInterface $entities Entities to save.
* @param array|\ArrayAccess $options Options used when calling Table::save() for each entity.
* @param array|\ArrayAccess|\Cake\ORM\SaveOptionsBuilder $options Options used when calling Table::save() for each entity.
* @return \Cake\Datasource\EntityInterface[]|\Cake\Datasource\ResultSetInterface Entities list.
* @throws \Cake\ORM\Exception\PersistenceFailedException If an entity couldn't be saved.
*/
Expand Down
9 changes: 4 additions & 5 deletions tests/TestCase/ORM/BehaviorRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Cake\Test\TestCase\ORM;

use Cake\ORM\BehaviorRegistry;
use Cake\ORM\Query;
use Cake\ORM\Table;
use Cake\TestSuite\TestCase;

Expand Down Expand Up @@ -317,16 +318,14 @@ public function testCallFinder()
->getMock();
$this->Behaviors->set('Sluggable', $mockedBehavior);

$query = $this->getMockBuilder('Cake\ORM\Query')
->disableOriginalConstructor()
->getMock();
$query = new Query($this->Table->getConnection(), $this->Table);
$mockedBehavior
->expects($this->once())
->method('findNoSlug')
->with($query, [])
->will($this->returnValue('example'));
->will($this->returnValue($query));
$return = $this->Behaviors->callFinder('noSlug', [$query, []]);
$this->assertSame('example', $return);
$this->assertSame($query, $return);
}

/**
Expand Down

0 comments on commit c8c0e6d

Please sign in to comment.