Skip to content

Commit

Permalink
Fixed type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Radiergummi committed Sep 18, 2020
1 parent efb3e4e commit ff6bf5b
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 74 deletions.
35 changes: 34 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand All @@ -15,11 +15,44 @@
</projectFiles>

<issueHandlers>

<!--
As these functions are included with Laravel and don't come bundled in a separate package, we have to ignore
them for now. They should ultimately be removed still, to allow using the package with other apps.
-->
<UndefinedFunction>
<errorLevel type="suppress">
<referencedFunction name="app"/>
<referencedFunction name="config"/>
</errorLevel>
</UndefinedFunction>

<!--
Due to the way Laravel handles console commands, psalm cannot be sure argument values are actually strings. We
know better, though.
-->
<PossiblyInvalidCast>
<errorLevel type="suppress">
<directory name="src/Commands"/>
</errorLevel>
</PossiblyInvalidCast>

<!--
This is caused by Laravel collections and scout having an unfortunate combination of type hints.
-->
<LessSpecificReturnStatement>
<errorLevel type="suppress">
<file name="src/ScoutEngine.php"/>
</errorLevel>
</LessSpecificReturnStatement>

<!--
This is caused by Laravel collections and scout having an unfortunate combination of type hints.
-->
<MoreSpecificReturnType>
<errorLevel type="suppress">
<file name="src/ScoutEngine.php"/>
</errorLevel>
</MoreSpecificReturnType>
</issueHandlers>
</psalm>
14 changes: 9 additions & 5 deletions src/Commands/ReindexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use InvalidArgumentException;
use JsonException;
use Matchory\Elasticsearch\Connection;
use RuntimeException;

Expand Down Expand Up @@ -83,20 +84,22 @@ public function __construct()
* @return void
* @throws InvalidArgumentException
* @throws RuntimeException
* @throws JsonException
* @psalm-suppress PossiblyInvalidArgument
*/
public function handle(): void
{
$this->connection = $this->option("connection") ?: config('es.default');
$this->size = (int)$this->option("bulk-size");
$this->scroll = $this->option("scroll");
$this->scroll = (string)$this->option("scroll");

if ($this->size <= 0) {
$this->warn("Invalid size value");

return;
}

$originalIndex = $this->argument('index');
$originalIndex = (string)$this->argument('index');
$newIndex = $this->argument('new_index');

if ( ! array_key_exists($originalIndex, config('es.indices'))) {
Expand All @@ -119,17 +122,18 @@ public function handle(): void
*
* @param string $originalIndex
* @param string $newIndex
* @param string|null $scroll_id
* @param string|null $scrollId
* @param int $errors
* @param int $page
*
* @throws InvalidArgumentException
* @throws RuntimeException
* @throws JsonException
*/
public function migrate(
string $originalIndex,
string $newIndex,
?string $scroll_id = null,
?string $scrollId = null,
int $errors = 0,
int $page = 1
): void {
Expand All @@ -155,7 +159,7 @@ public function migrate(
->index($originalIndex)
->type('')
->scroll($this->scroll)
->scrollID($scroll_id)
->scrollID($scrollId ?: '')
->response();
}

Expand Down
5 changes: 4 additions & 1 deletion src/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ public function exists(): bool
public function create(): array
{
$callback = $this->callback;
$callback($this);

if ($callback) {
$callback($this);
}

$params = [
'index' => $this->name,
Expand Down
2 changes: 1 addition & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Model
* @param array $attributes
* @param bool $exists
*/
public function __construct($attributes = [], $exists = false)
final public function __construct($attributes = [], $exists = false)
{
$this->attributes = $attributes;

Expand Down
Loading

0 comments on commit ff6bf5b

Please sign in to comment.