Skip to content

Commit

Permalink
Fix static analysis errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jul 30, 2023
1 parent 10d970f commit 486b932
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/Datasource/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@

class Connection implements ConnectionInterface
{
/**
* Compatibility shim for ConnectionInterface
*/
public const ROLE_WRITE = 'write';

/**
* Whether or not query logging is enabled.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/Datasource/IndexLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ class IndexLocator extends AbstractLocator
* Fallback class to use
*
* @var string
* @psalm-var class-string<\Cake\Elasticsearch\Index>
* @psalm-var class-string<\Cake\ElasticSearch\Index>
*/
protected $fallbackClassName = Index::class;
protected string $fallbackClassName = Index::class;

/**
* Whether fallback class should be used if a Index class could not be found.
*
* @var bool
*/
protected $allowFallbackClass = true;
protected bool $allowFallbackClass = true;

/**
* Set fallback class name.
Expand All @@ -53,7 +53,7 @@ class IndexLocator extends AbstractLocator
*
* @param string $className Fallback class name
* @return $this
* @psalm-param class-string<\Cake\Elasticsearch\Index> $className
* @psalm-param class-string<\Cake\ElasticSearch\Index> $className
*/
public function setFallbackClassName(string $className)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Datasource/Log/ElasticLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Cake\Database\Log\LoggedQuery;
use Cake\Database\Log\QueryLogger;
use Cake\ElasticSearch\Datasource\Connection;
use Exception;
use Psr\Log\AbstractLogger;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
Expand Down Expand Up @@ -142,7 +143,7 @@ protected function _log(string $level, string $message, array $context = []): vo
$context['query'] = $message;
}
$exception = $context['exception'] ?? null;
if ($exception instanceof \Exception) {
if ($exception instanceof Exception) {
throw $exception;
}
$this->getLogger()->log($level, $logData, $context);
Expand Down
5 changes: 0 additions & 5 deletions src/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,9 @@
*
* A index in elastic search is approximately equivalent to a table or collection
* in a relational datastore. This ODM maps each index to a class.
*
* @implements \Cake\Event\EventDispatcherInterface<\Cake\ElasticSearch\Index>
*/
class Index implements RepositoryInterface, EventListenerInterface, EventDispatcherInterface
{
/**
* @use \Cake\Event\EventDispatcherTrait<\Cake\ElasticSearch\Index>
*/
use EventDispatcherTrait;
use RulesAwareTrait;
use ValidatorAwareTrait;
Expand Down
19 changes: 12 additions & 7 deletions src/IndexRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use Cake\Datasource\Locator\LocatorInterface;
use Cake\Datasource\RepositoryInterface;
use Cake\Elasticsearch\Datasource\IndexLocator;
use Cake\ElasticSearch\Datasource\IndexLocator;

/**
* Factory/Registry class for Index objects.
Expand All @@ -36,14 +36,14 @@ class IndexRegistry implements LocatorInterface
/**
* The locator that the global registy is wrapping.
*
* @var \Cake\ElasticSearch\Cake\ElasticSearch\Datasource\IndexLocator
* @var \Cake\ElasticSearch\Datasource\IndexLocator
*/
protected static IndexLocator $locator;

/**
* Get the wrapped locator.
*
* @return \Cake\ElasticSearch\IndexLocator
* @return \Cake\ElasticSearch\Datasource\IndexLocator
*/
protected static function getLocator(): IndexLocator
{
Expand Down Expand Up @@ -81,7 +81,10 @@ public static function setFallbackClassName(string $className): void
*/
public function get(string $alias, array $options = []): Index
{
return static::getLocator()->get($alias, $options);
$instance = static::getLocator()->get($alias, $options);
assert($instance instanceof Index);

return $instance;
}

/**
Expand All @@ -101,11 +104,13 @@ public function exists(string $alias): bool
* @param string $alias The alias to set.
* @param \Cake\Datasource\RepositoryInterface $repository The type to set.
* @return \Cake\ElasticSearch\Index
* @psalm-return \Cake\Datasource\RepositoryInterface
*/
public function set(string $alias, RepositoryInterface $repository): RepositoryInterface
public function set(string $alias, RepositoryInterface $repository): Index
{
return static::getLocator()->set($alias, $repository);
$instance = static::getLocator()->set($alias, $repository);
assert($instance instanceof Index);

return $instance;
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* correct class and provide a Collection interface to the returned results.
*
* @template-extends \IteratorIterator<mixed, mixed, \Traversable<mixed>>
* @implements \Cake\Datasource\ResultSetInterface<\Cake\ElasticSearch\Document>
*/
class ResultSet extends IteratorIterator implements ResultSetInterface
{
Expand Down

0 comments on commit 486b932

Please sign in to comment.