Skip to content

Commit

Permalink
Add flattened fields with types
Browse files Browse the repository at this point in the history
  • Loading branch information
iquito committed May 10, 2020
1 parent c262253 commit 8ecb0ba
Show file tree
Hide file tree
Showing 5 changed files with 494 additions and 9 deletions.
44 changes: 37 additions & 7 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
parameters:
ignoreErrors:
-
message: "#^Call to an undefined method ReflectionType\\:\\:getName\\(\\)\\.$#"
message: "#^Parameter \\#1 \\$query of method Squirrel\\\\Entities\\\\RepositoryReadOnlyInterface\\:\\:fetchAll\\(\\) expects array\\(\\)\\|array\\('fields' \\=\\> array\\<string\\>, 'field' \\=\\> string, 'where' \\=\\> array\\<int\\|string, mixed\\>, 'order' \\=\\> array\\<int\\|string, string\\>, 'limit' \\=\\> int, 'offset' \\=\\> int, 'lock' \\=\\> bool\\), array\\('where' \\=\\> array\\<int\\|string, mixed\\>, 'order' \\=\\> array\\<int\\|string, string\\>, 'fields' \\=\\> array\\<string\\>, 'limit' \\=\\> int, 'offset' \\=\\> int, 'lock' \\=\\> bool\\) given\\.$#"
count: 1
path: src/Annotation/EntityProcessor.php
path: src/Action/SelectEntries.php

-
message: "#^Parameter \\#1 \\$query of method Squirrel\\\\Queries\\\\DBInterface\\:\\:fetchOne\\(\\) expects array\\<string, array\\<int\\|string, mixed\\>\\|bool\\|int\\|string\\>\\|string, array\\<string, array\\<int\\|string, mixed\\>\\|string\\|true\\> given\\.$#"
message: "#^Parameter \\#1 \\$query of method Squirrel\\\\Entities\\\\RepositoryReadOnlyInterface\\:\\:fetchOne\\(\\) expects array\\(\\)\\|array\\('fields' \\=\\> array\\<string\\>, 'field' \\=\\> string, 'where' \\=\\> array\\<int\\|string, mixed\\>, 'order' \\=\\> array\\<int\\|string, string\\>, 'offset' \\=\\> int, 'lock' \\=\\> bool\\), array\\('where' \\=\\> array\\<int\\|string, mixed\\>, 'order' \\=\\> array\\<int\\|string, string\\>, 'fields' \\=\\> array\\<string\\>, 'offset' \\=\\> int, 'lock' \\=\\> bool\\) given\\.$#"
count: 1
path: src/RepositoryReadOnly.php
path: src/Action/SelectEntries.php

-
message: "#^Parameter \\#1 \\$query of method Squirrel\\\\Entities\\\\RepositoryReadOnlyInterface\\:\\:fetchAllAndFlatten\\(\\) expects array\\(\\)\\|array\\('fields' \\=\\> array\\<string\\>, 'field' \\=\\> string, 'where' \\=\\> array\\<int\\|string, mixed\\>, 'order' \\=\\> array\\<int\\|string, string\\>, 'limit' \\=\\> int, 'offset' \\=\\> int, 'lock' \\=\\> bool\\), array\\('where' \\=\\> array\\<int\\|string, mixed\\>, 'order' \\=\\> array\\<int\\|string, string\\>, 'fields' \\=\\> array\\<string\\>, 'limit' \\=\\> int, 'offset' \\=\\> int, 'lock' \\=\\> bool\\) given\\.$#"
count: 1
path: src/Action/SelectEntries.php

-
message: "#^Method Squirrel\\\\Entities\\\\Action\\\\SelectEntries\\:\\:getFlattenedIntegerFields\\(\\) should return array\\<int\\> but returns array\\<bool\\|float\\|int\\|string\\|null\\>\\.$#"
count: 1
path: src/Action/SelectEntries.php

-
message: "#^Method Squirrel\\\\Entities\\\\Action\\\\SelectEntries\\:\\:getFlattenedFloatFields\\(\\) should return array\\<float\\> but returns array\\<bool\\|float\\|int\\|string\\|null\\>\\.$#"
count: 1
path: src/Action/SelectEntries.php

-
message: "#^Parameter \\#1 \\$query of method Squirrel\\\\Queries\\\\DBInterface\\:\\:select\\(\\) expects array\\<string, array\\<int\\|string, mixed\\>\\|bool\\|int\\|string\\>\\|string, array\\<string, mixed\\> given\\.$#"
message: "#^Method Squirrel\\\\Entities\\\\Action\\\\SelectEntries\\:\\:getFlattenedStringFields\\(\\) should return array\\<string\\> but returns array\\<bool\\|float\\|int\\|string\\|null\\>\\.$#"
count: 1
path: src/Action/SelectEntries.php

-
message: "#^Method Squirrel\\\\Entities\\\\Action\\\\SelectEntries\\:\\:getFlattenedBooleanFields\\(\\) should return array\\<bool\\> but returns array\\<bool\\|float\\|int\\|string\\|null\\>\\.$#"
count: 1
path: src/Action/SelectEntries.php

-
message: "#^Call to an undefined method ReflectionType\\:\\:getName\\(\\)\\.$#"
count: 1
path: src/Annotation/EntityProcessor.php

-
message: "#^Parameter \\#1 \\$query of method Squirrel\\\\Queries\\\\DBInterface\\:\\:fetchOne\\(\\) expects array\\(\\)\\|array\\('fields' \\=\\> array\\<int\\|string, string\\>, 'field' \\=\\> string, 'tables' \\=\\> array\\<int\\|string, mixed\\>, 'table' \\=\\> string, 'where' \\=\\> array\\<int\\|string, mixed\\>, 'group' \\=\\> array\\<int\\|string, string\\>, 'order' \\=\\> array\\<int\\|string, string\\>, 'limit' \\=\\> int, \\.\\.\\.\\)\\|string, array\\('table' \\=\\> string, 'fields' \\=\\> array\\('num' \\=\\> 'COUNT\\(\\*\\)'\\), \\?'where' \\=\\> array\\<int\\|string, mixed\\>, \\?'lock' \\=\\> true\\) given\\.$#"
count: 1
path: src/RepositoryReadOnly.php

Expand All @@ -21,7 +51,7 @@ parameters:
path: src/RepositoryReadOnly.php

-
message: "#^Parameter \\#1 \\$query of method Squirrel\\\\Queries\\\\DBInterface\\:\\:fetchAll\\(\\) expects array\\<string, array\\<int\\|string, mixed\\>\\|bool\\|int\\|string\\>\\|string, array\\<string, mixed\\> given\\.$#"
count: 2
message: "#^Parameter \\#1 \\$query of method Squirrel\\\\Entities\\\\RepositoryReadOnly\\:\\:select\\(\\) expects array\\(\\)\\|array\\('fields' \\=\\> array, 'field' \\=\\> string, 'where' \\=\\> array, 'order' \\=\\> array, 'limit' \\=\\> int, 'offset' \\=\\> int, 'lock' \\=\\> bool\\), array\\(\\?'fields' \\=\\> array\\<string\\>, \\?'field' \\=\\> string, \\?'where' \\=\\> array\\<int\\|string, mixed\\>, \\?'order' \\=\\> array\\<int\\|string, string\\>, \\?'offset' \\=\\> int, \\?'lock' \\=\\> bool, 'limit' \\=\\> 1\\) given\\.$#"
count: 1
path: src/RepositoryReadOnly.php

14 changes: 14 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.11.2@d470903722cfcbc1cd04744c5491d3e6d13ec3d9">
<file src="src/Action/SelectEntries.php">
<InvalidReturnStatement occurrences="4">
<code>$values</code>
<code>$values</code>
<code>$values</code>
<code>$values</code>
</InvalidReturnStatement>
<InvalidReturnType occurrences="4">
<code>int[]</code>
<code>float[]</code>
<code>string[]</code>
<code>bool[]</code>
</InvalidReturnType>
</file>
<file src="src/MultiRepositoryReadOnly.php">
<MissingConstructor occurrences="1">
<code>$db</code>
Expand Down
5 changes: 3 additions & 2 deletions src/Action/MultiCountEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Squirrel\Entities\Action;

use Squirrel\Entities\MultiRepositoryReadOnlyInterface;
use Squirrel\Entities\RepositoryBuilderReadOnlyInterface;
use Squirrel\Entities\RepositoryReadOnlyInterface;

/**
Expand All @@ -13,7 +14,7 @@ class MultiCountEntries implements ActionInterface
private MultiRepositoryReadOnlyInterface $queryHandler;

/**
* @var RepositoryReadOnlyInterface[] Repositories used in the multi query
* @var array<string,RepositoryBuilderReadOnlyInterface|RepositoryReadOnlyInterface> Repositories used in the multi query
*/
private array $repositories = [];

Expand All @@ -38,7 +39,7 @@ public function __construct(MultiRepositoryReadOnlyInterface $queryHandler)
}

/**
* @param RepositoryReadOnlyInterface[] $repositories
* @param array<string,RepositoryBuilderReadOnlyInterface|RepositoryReadOnlyInterface> $repositories
*/
public function inRepositories(array $repositories): self
{
Expand Down
87 changes: 87 additions & 0 deletions src/Action/SelectEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Squirrel\Entities\Action;

use Squirrel\Debug\Debug;
use Squirrel\Entities\RepositoryReadOnlyInterface;
use Squirrel\Queries\Exception\DBInvalidOptionException;

/**
* Select query builder as a fluent object - build query and return object(s) or flattened fields
Expand Down Expand Up @@ -155,6 +157,91 @@ public function getFlattenedFields(): array
]);
}

/**
* @return int[]
*/
public function getFlattenedIntegerFields(): array
{
$values = $this->getFlattenedFields();

foreach ($values as $value) {
if (!\is_int($value)) {
throw Debug::createException(
DBInvalidOptionException::class,
[ActionInterface::class],
'Flattened integers requested, but not all values were integers'
);
}
}

return $values;
}

/**
* @return float[]
*/
public function getFlattenedFloatFields(): array
{
$values = $this->getFlattenedFields();

foreach ($values as $key => $value) {
if (\is_int($value)) {
$values[$key] = \floatval($value);
continue;
}

if (!\is_float($value)) {
throw Debug::createException(
DBInvalidOptionException::class,
[ActionInterface::class],
'Flattened floats requested, but not all values were floats'
);
}
}

return $values;
}

/**
* @return string[]
*/
public function getFlattenedStringFields(): array
{
$values = $this->getFlattenedFields();

foreach ($values as $value) {
if (!\is_string($value)) {
throw Debug::createException(
DBInvalidOptionException::class,
[ActionInterface::class],
'Flattened strings requested, but not all values were strings'
);
}
}

return $values;
}

/**
* @return bool[]
*/
public function getFlattenedBooleanFields(): array
{
$values = $this->getFlattenedFields();

foreach ($values as $value) {
if (!\is_bool($value)) {
throw Debug::createException(
DBInvalidOptionException::class,
[ActionInterface::class],
'Flattened booleans requested, but not all values were booleans'
);
}
}

return $values;
}

public function getIterator(): SelectIterator
{
return new SelectIterator($this->repository, [
Expand Down
Loading

0 comments on commit 8ecb0ba

Please sign in to comment.