diff --git a/application/Espo/Core/Select/Order/Params.php b/application/Espo/Core/Select/Order/Params.php index 19968fec9a..5b6fe4feab 100644 --- a/application/Espo/Core/Select/Order/Params.php +++ b/application/Espo/Core/Select/Order/Params.php @@ -50,9 +50,13 @@ class Params private function __construct() {} /** - * @param array $params + * @param array{ + * forceDefault?: bool, + * orderBy?: ?string, + * order?: SearchParams::ORDER_ASC|SearchParams::ORDER_DESC|null, + * } $params */ - public static function fromArray(array $params): self + public static function fromAssoc(array $params): self { $object = new self(); @@ -71,10 +75,13 @@ class Params throw new InvalidArgumentException("Bad orderBy."); } + /** @var ?string $order */ + $order = $object->order; + if ( - $object->order && - $object->order !== SearchParams::ORDER_ASC && - $object->order !== SearchParams::ORDER_DESC + $order && + $order !== SearchParams::ORDER_ASC && + $order !== SearchParams::ORDER_DESC ) { throw new InvalidArgumentException("Bad order."); } diff --git a/application/Espo/Core/Select/SearchParams.php b/application/Espo/Core/Select/SearchParams.php index 0dfe9095ba..5c56f76c77 100644 --- a/application/Espo/Core/Select/SearchParams.php +++ b/application/Espo/Core/Select/SearchParams.php @@ -51,7 +51,7 @@ class SearchParams private function __construct() {} /** - * @return array + * @return array */ public function getRaw(): array { @@ -320,7 +320,7 @@ class SearchParams /** * Create an instance from a raw. * - * @param stdClass|array $params + * @param stdClass|array $params */ public static function fromRaw($params): self { @@ -493,7 +493,7 @@ class SearchParams /** * For compatibility with the legacy definition. * - * @param array $params + * @param array $params */ private function adjustParams(array &$params): void { diff --git a/application/Espo/Core/Select/SelectBuilder.php b/application/Espo/Core/Select/SelectBuilder.php index 6a379ea2e5..702bd1b3a9 100644 --- a/application/Espo/Core/Select/SelectBuilder.php +++ b/application/Espo/Core/Select/SelectBuilder.php @@ -396,7 +396,7 @@ class SelectBuilder $order = $this->searchParams?->getOrder(); - $params = OrderParams::fromArray([ + $params = OrderParams::fromAssoc([ 'forceDefault' => true, 'order' => $order, ]); @@ -429,7 +429,7 @@ class SelectBuilder { assert($this->queryBuilder !== null); - $params = WhereParams::fromArray([ + $params = WhereParams::fromAssoc([ 'applyPermissionCheck' => $this->applyWherePermissionCheck, 'forbidComplexExpressions' => $this->applyComplexExpressionsForbidden, ]); @@ -458,7 +458,7 @@ class SelectBuilder !$this->applyDefaultOrder && ($this->searchParams->getOrderBy() || $this->searchParams->getOrder()) ) { - $params = OrderParams::fromArray([ + $params = OrderParams::fromAssoc([ //'forbidComplexExpressions' => $this->applyComplexExpressionsForbidden, 'orderBy' => $this->searchParams->getOrderBy(), 'order' => $this->searchParams->getOrder(), diff --git a/application/Espo/Core/Select/Where/Params.php b/application/Espo/Core/Select/Where/Params.php index 097f96724c..95843c54a6 100644 --- a/application/Espo/Core/Select/Where/Params.php +++ b/application/Espo/Core/Select/Where/Params.php @@ -45,9 +45,12 @@ class Params {} /** - * @param array $params + * @param array{ + * applyPermissionCheck?: bool, + * forbidComplexExpressions?: bool, + * } $params */ - public static function fromArray(array $params): self + public static function fromAssoc(array $params): self { $object = new self(); diff --git a/tests/unit/Espo/Core/Select/Order/ParamsTest.php b/tests/unit/Espo/Core/Select/Order/ParamsTest.php index b544e89885..9852a57aa3 100644 --- a/tests/unit/Espo/Core/Select/Order/ParamsTest.php +++ b/tests/unit/Espo/Core/Select/Order/ParamsTest.php @@ -43,7 +43,7 @@ class ParamsTest extends \PHPUnit\Framework\TestCase public function testFromArray() { - $item = Params::fromArray([ + $item = Params::fromAssoc([ 'order' => 'DESC', 'orderBy' => 'test', //'forbidComplexExpressions' => true, @@ -55,7 +55,7 @@ class ParamsTest extends \PHPUnit\Framework\TestCase //$this->assertTrue($item->forbidComplexExpressions()); $this->assertTrue($item->forceDefault()); - $item = Params::fromArray([ + $item = Params::fromAssoc([ //'forbidComplexExpressions' => false, 'forceDefault' => false, ]); @@ -66,7 +66,7 @@ class ParamsTest extends \PHPUnit\Framework\TestCase public function testEmpty() { - $item = Params::fromArray([ + $item = Params::fromAssoc([ ]); $this->assertEquals(null, $item->getOrder()); @@ -79,7 +79,7 @@ class ParamsTest extends \PHPUnit\Framework\TestCase { $this->expectException(InvalidArgumentException::class); - $params = Params::fromArray([ + $params = Params::fromAssoc([ 'order' => 'd', ]); } @@ -88,7 +88,7 @@ class ParamsTest extends \PHPUnit\Framework\TestCase { $this->expectException(InvalidArgumentException::class); - $params = Params::fromArray([ + $params = Params::fromAssoc([ 'bad' => 'd', ]); } diff --git a/tests/unit/Espo/Core/Select/SelectBuilderTest.php b/tests/unit/Espo/Core/Select/SelectBuilderTest.php index 36ddf6c8ba..ed930dd725 100644 --- a/tests/unit/Espo/Core/Select/SelectBuilderTest.php +++ b/tests/unit/Espo/Core/Select/SelectBuilderTest.php @@ -195,7 +195,7 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase $whereItem = $searchParams->getWhere(); - $whereParams = WhereParams::fromArray([ + $whereParams = WhereParams::fromAssoc([ 'applyPermissionCheck' => true, 'forbidComplexExpressions' => true, ]); @@ -209,7 +209,7 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase $whereParams ); - $orderParams = OrderParams::fromArray([ + $orderParams = OrderParams::fromAssoc([ //'forbidComplexExpressions' => true, 'orderBy' => $searchParams->getOrderBy(), 'order' => $searchParams->getOrder(), @@ -248,7 +248,7 @@ class SelectBuilderTest extends \PHPUnit\Framework\TestCase $searchParams = SearchParams::fromRaw($raw); - $orderParams = OrderParams::fromArray([ + $orderParams = OrderParams::fromAssoc([ 'forceDefault' => true, 'order' => null, ]); diff --git a/tests/unit/Espo/Core/Select/Where/ParamsTest.php b/tests/unit/Espo/Core/Select/Where/ParamsTest.php index 0d41eafaa5..aff588647d 100644 --- a/tests/unit/Espo/Core/Select/Where/ParamsTest.php +++ b/tests/unit/Espo/Core/Select/Where/ParamsTest.php @@ -43,7 +43,7 @@ class ParamsTest extends \PHPUnit\Framework\TestCase public function testFromArray() { - $item = Params::fromArray([ + $item = Params::fromAssoc([ 'applyPermissionCheck' => true, 'forbidComplexExpressions' => true, ]); @@ -51,7 +51,7 @@ class ParamsTest extends \PHPUnit\Framework\TestCase $this->assertTrue($item->applyPermissionCheck()); $this->assertTrue($item->forbidComplexExpressions()); - $item = Params::fromArray([ + $item = Params::fromAssoc([ 'applyPermissionCheck' => false, 'forbidComplexExpressions' => false, ]); @@ -59,7 +59,7 @@ class ParamsTest extends \PHPUnit\Framework\TestCase $this->assertFalse($item->applyPermissionCheck()); $this->assertFalse($item->forbidComplexExpressions()); - $item = Params::fromArray([ + $item = Params::fromAssoc([ 'applyPermissionCheck' => false, 'forbidComplexExpressions' => true, ]); @@ -70,7 +70,7 @@ class ParamsTest extends \PHPUnit\Framework\TestCase public function testEmpty() { - $item = Params::fromArray([ + $item = Params::fromAssoc([ ]); $this->assertFalse($item->applyPermissionCheck()); @@ -81,7 +81,7 @@ class ParamsTest extends \PHPUnit\Framework\TestCase { $this->expectException(InvalidArgumentException::class); - $params = Params::fromArray([ + $params = Params::fromAssoc([ 'bad' => 'd', ]); }