Phpstan fixes

This commit is contained in:
Matias Griese 2021-09-24 13:18:26 +03:00
parent c220aa746a
commit 8aee574069
15 changed files with 27 additions and 15 deletions

View File

@ -108,7 +108,7 @@ trait MediaUploadTrait
*
* @param array $metadata
* @param array|null $settings
* @return string|null
* @return string
* @throws RuntimeException
*/
public function checkFileMetadata(array $metadata, string $filename = null, array $settings = null): string

View File

@ -24,7 +24,7 @@ use function array_slice;
* Collection of objects stored into a filesystem.
*
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends AbstractLazyCollection<TKey,T>
* @mplements FileCollectionInterface<TKey,T>

View File

@ -20,7 +20,7 @@ use function count;
/**
* Abstract Index Collection.
* @template TKey
* @template TKey of array-key
* @template T
* @implements CollectionInterface<TKey,T>
*/
@ -361,6 +361,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
* @param int $start
* @param int|null $limit
* @return static
* @phpstan-return static<TKey,T>
*/
public function limit($start, $limit = null)
{
@ -371,6 +372,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
* Reverse the order of the items.
*
* @return static
* @phpstan-return static<TKey,T>
*/
public function reverse()
{
@ -381,6 +383,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
* Shuffle items.
*
* @return static
* @phpstan-return static<TKey,T>
*/
public function shuffle()
{
@ -397,6 +400,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @param array $keys
* @return static
* @phpstan-return static<TKey,T>
*/
public function select(array $keys)
{
@ -415,6 +419,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @param array $keys
* @return static
* @phpstan-return static<TKey,T>
*/
public function unselect(array $keys)
{
@ -469,6 +474,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
*
* @param array $entries Elements.
* @return static
* @phpstan-return static<TKey,T>
*/
protected function createFrom(array $entries)
{
@ -521,6 +527,7 @@ abstract class AbstractIndexCollection implements CollectionInterface
/**
* @param array|null $entries
* @return CollectionInterface
* @phpstan-return T
*/
abstract protected function loadCollection(array $entries = null): CollectionInterface;

View File

@ -15,7 +15,7 @@ use Doctrine\Common\Collections\AbstractLazyCollection as BaseAbstractLazyCollec
* General JSON serializable collection.
*
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends BaseAbstractLazyCollection<TKey,T>
* @implements CollectionInterface<TKey,T>

View File

@ -15,7 +15,7 @@ use Doctrine\Common\Collections\ArrayCollection as BaseArrayCollection;
* General JSON serializable collection.
*
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends BaseArrayCollection<TKey,T>
* @implements CollectionInterface<TKey,T>

View File

@ -16,7 +16,7 @@ use JsonSerializable;
* Collection Interface.
*
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends Collection<TKey,T>
*/

View File

@ -13,7 +13,7 @@ namespace Grav\Framework\Collection;
* Collection of objects stored into a filesystem.
*
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends AbstractFileCollection<TKey,T>
*/

View File

@ -15,7 +15,7 @@ use Doctrine\Common\Collections\Selectable;
* Collection of objects stored into a filesystem.
*
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends CollectionInterface<TKey,T>
* @extends Selectable<TKey,T>

View File

@ -540,6 +540,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
*/
protected function createFrom(array $entries, string $keyField = null)
{
/** @phpstan-var static<T,C> $index */
$index = new static($entries, $this->getFlexDirectory());
$index->setKeyField($keyField ?? $this->_keyField);
@ -630,7 +631,10 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde
*/
protected function loadCollection(array $entries = null): CollectionInterface
{
return $this->getFlexDirectory()->loadCollection($entries ?? $this->getEntries(), $this->_keyField);
/** @var C $collection */
$collection = $this->getFlexDirectory()->loadCollection($entries ?? $this->getEntries(), $this->_keyField);
return $collection;
}
/**

View File

@ -51,6 +51,7 @@ interface FlexIndexInterface extends FlexCollectionInterface
*
* @param string|null $keyField Switch key field of the collection.
* @return static Returns a new Flex Collection with new key field.
* @phpstan-return static<T>
* @api
*/
public function withKeyField(string $keyField = null);

View File

@ -207,8 +207,6 @@ trait ObjectCollectionTrait
/**
* Create a copy from this collection by cloning all objects in the collection.
*
* @return static
*/
public function copy()
{

View File

@ -15,7 +15,7 @@ use RuntimeException;
* Common Interface for both Objects and Collections
* @package Grav\Framework\Object
*
* @template TKey
* @template TKey of array-key
* @template T
* @extends ObjectCollectionInterface<TKey,T>
*/

View File

@ -16,7 +16,7 @@ use Serializable;
/**
* ObjectCollection Interface
* @package Grav\Framework\Collection
* @template TKey
* @template TKey of array-key
* @template T
* @extends CollectionInterface<TKey,T>
* @extends Selectable<TKey,T>
@ -76,6 +76,7 @@ interface ObjectCollectionInterface extends CollectionInterface, Selectable, Ser
* Create a copy from this collection by cloning all objects in the collection.
*
* @return static
* @phpstan-return static<TKey,T>
*/
public function copy();

View File

@ -21,7 +21,7 @@ use function array_slice;
/**
* Class contains a collection of objects.
*
* @template TKey
* @template TKey of array-key
* @template T
* @extends ArrayCollection<TKey,T>
* @implements NestedObjectCollectionInterface<TKey,T>

View File

@ -23,7 +23,7 @@ use function is_object;
* This is an abstract class and has some protected abstract methods to load objects which you need to implement in
* order to use the class.
*
* @template TKey
* @template TKey of array-key
* @template T
* @extends AbstractIndexCollection<TKey,T>
* @implements NestedObjectCollectionInterface<TKey,T>
@ -176,6 +176,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements NestedObje
* Create a copy from this collection by cloning all objects in the collection.
*
* @return static
* @return static<TKey,T>
*/
public function copy()
{