Skip to content

Commit 92abe7f

Browse files
committed
Added more types
1 parent d61e74c commit 92abe7f

5 files changed

Lines changed: 31 additions & 35 deletions

File tree

src/HalfVector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
class HalfVector
66
{
7-
protected $value;
7+
protected array $value;
88

9-
public function __construct($value)
9+
public function __construct(mixed $value)
1010
{
1111
if (is_string($value)) {
1212
try {
@@ -35,12 +35,12 @@ public function __construct($value)
3535
$this->value = $value;
3636
}
3737

38-
public function __toString()
38+
public function __toString(): string
3939
{
4040
return json_encode($this->value, JSON_THROW_ON_ERROR, 1);
4141
}
4242

43-
public function toArray()
43+
public function toArray(): array
4444
{
4545
return $this->value;
4646
}

src/SparseVector.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
class SparseVector
66
{
7-
protected $dimensions;
8-
protected $indices;
9-
protected $values;
7+
protected int $dimensions;
8+
protected array $indices;
9+
protected array $values;
1010

11-
public function __construct($value, $dimensions = null)
11+
public function __construct(mixed $value, mixed $dimensions = null)
1212
{
1313
$numArgs = func_num_args();
1414

@@ -35,7 +35,7 @@ public function __construct($value, $dimensions = null)
3535
}
3636
}
3737

38-
private function fromDense($value)
38+
private function fromDense(array $value)
3939
{
4040
$this->dimensions = count($value);
4141
$this->indices = [];
@@ -49,7 +49,7 @@ private function fromDense($value)
4949
}
5050
}
5151

52-
private function fromMap($map, $dimensions)
52+
private function fromMap(array $map, mixed $dimensions)
5353
{
5454
$this->dimensions = intval($dimensions);
5555
$this->indices = [];
@@ -66,7 +66,7 @@ private function fromMap($map, $dimensions)
6666
}
6767
}
6868

69-
private function fromString($value)
69+
private function fromString(string $value)
7070
{
7171
$parts = explode('/', $value, 2);
7272

@@ -82,7 +82,7 @@ private function fromString($value)
8282
}
8383
}
8484

85-
public function __toString()
85+
public function __toString(): string
8686
{
8787
$elements = [];
8888
for ($i = 0; $i < count($this->indices); $i++) {
@@ -91,22 +91,22 @@ public function __toString()
9191
return '{' . implode(',', $elements) . '}/' . $this->dimensions;
9292
}
9393

94-
public function dimensions()
94+
public function dimensions(): int
9595
{
9696
return $this->dimensions;
9797
}
9898

99-
public function indices()
99+
public function indices(): array
100100
{
101101
return $this->indices;
102102
}
103103

104-
public function values()
104+
public function values(): array
105105
{
106106
return $this->values;
107107
}
108108

109-
public function toArray()
109+
public function toArray(): array
110110
{
111111
$result = array_fill(0, $this->dimensions, 0.0);
112112
for ($i = 0; $i < count($this->indices); $i++) {

src/Vector.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
class Vector
66
{
7-
protected $value;
7+
protected array $value;
88

9-
public function __construct($value)
9+
public function __construct(mixed $value)
1010
{
1111
if (is_string($value)) {
1212
try {
@@ -35,12 +35,12 @@ public function __construct($value)
3535
$this->value = $value;
3636
}
3737

38-
public function __toString()
38+
public function __toString(): string
3939
{
4040
return json_encode($this->value, JSON_THROW_ON_ERROR, 1);
4141
}
4242

43-
public function toArray()
43+
public function toArray(): array
4444
{
4545
return $this->value;
4646
}

src/laravel/PgvectorServiceProvider.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,16 @@ class PgvectorServiceProvider extends ServiceProvider
88
{
99
/**
1010
* Register services.
11-
*
12-
* @return void
1311
*/
14-
public function register()
12+
public function register(): void
1513
{
1614
//
1715
}
1816

1917
/**
2018
* Bootstrap services.
21-
*
22-
* @return void
2319
*/
24-
public function boot()
20+
public function boot(): void
2521
{
2622
$this->loadMigrationsFrom(__DIR__.'/migrations');
2723

src/laravel/Schema.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,53 @@
88

99
class Schema
1010
{
11-
public static function register()
11+
public static function register(): void
1212
{
13-
PostgresGrammar::macro('typeVector', function (ColumnDefinition $column) {
13+
PostgresGrammar::macro('typeVector', function (ColumnDefinition $column): string {
1414
if ($column->get('dimensions')) {
1515
return 'vector(' . intval($column->get('dimensions')) . ')';
1616
} else {
1717
return 'vector';
1818
}
1919
});
2020

21-
PostgresGrammar::macro('typeHalfvec', function (ColumnDefinition $column) {
21+
PostgresGrammar::macro('typeHalfvec', function (ColumnDefinition $column): string {
2222
if ($column->get('dimensions')) {
2323
return 'halfvec(' . intval($column->get('dimensions')) . ')';
2424
} else {
2525
return 'halfvec';
2626
}
2727
});
2828

29-
PostgresGrammar::macro('typeBit', function (ColumnDefinition $column) {
29+
PostgresGrammar::macro('typeBit', function (ColumnDefinition $column): string {
3030
if ($column->get('length')) {
3131
return 'bit(' . intval($column->get('length')) . ')';
3232
} else {
3333
return 'bit';
3434
}
3535
});
3636

37-
PostgresGrammar::macro('typeSparsevec', function (ColumnDefinition $column) {
37+
PostgresGrammar::macro('typeSparsevec', function (ColumnDefinition $column): string {
3838
if ($column->get('dimensions')) {
3939
return 'sparsevec(' . intval($column->get('dimensions')) . ')';
4040
} else {
4141
return 'sparsevec';
4242
}
4343
});
4444

45-
Blueprint::macro('vector', function ($column, $dimensions = null) {
45+
Blueprint::macro('vector', function (string $column, mixed $dimensions = null): ColumnDefinition {
4646
return $this->addColumn('vector', $column, compact('dimensions'));
4747
});
4848

49-
Blueprint::macro('halfvec', function ($column, $dimensions = null) {
49+
Blueprint::macro('halfvec', function (string $column, mixed $dimensions = null): ColumnDefinition {
5050
return $this->addColumn('halfvec', $column, compact('dimensions'));
5151
});
5252

53-
Blueprint::macro('bit', function ($column, $length = null) {
53+
Blueprint::macro('bit', function (string $column, mixed $length = null): ColumnDefinition {
5454
return $this->addColumn('bit', $column, compact('length'));
5555
});
5656

57-
Blueprint::macro('sparsevec', function ($column, $dimensions = null) {
57+
Blueprint::macro('sparsevec', function (string $column, mixed $dimensions = null): ColumnDefinition {
5858
return $this->addColumn('sparsevec', $column, compact('dimensions'));
5959
});
6060
}

0 commit comments

Comments
 (0)