From 3735216f65547e23d02798cdc6a5612ef84e39e8 Mon Sep 17 00:00:00 2001
From: Ralf Kornberger <37985317+rakoitde@users.noreply.github.com>
Date: Thu, 22 Sep 2022 21:47:25 +0200
Subject: [PATCH 01/11] add Condition.php
---
src/Condition.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
create mode 100644 src/Condition.php
diff --git a/src/Condition.php b/src/Condition.php
new file mode 100644
index 0000000..0423de6
--- /dev/null
+++ b/src/Condition.php
@@ -0,0 +1,47 @@
+.
+ *
+ * @author Benjamin Heisig
+ * @copyright Copyright (C) 2022 synetics GmbH
+ * @copyright Copyright (C) 2016-2022 Benjamin Heisig
+ * @license http://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License (AGPL)
+ * @link https://github.com/i-doit/api-client-php
+ */
+
+declare(strict_types=1);
+
+namespace Idoit\APIClient;
+
+use \Exception;
+use \BadMethodCallException;
+use \RuntimeException;
+
+/**
+ * Requests for assigned files
+ */
+class Condition {
+
+ private string $message;
+
+ public function __construct()
+ {
+ $this->message = "Hello World!";
+ }
+
+}
From 876fba518167766d6560307f5f7df3f88f6a2146 Mon Sep 17 00:00:00 2001
From: rakoitde <37985317+rakoitde@users.noreply.github.com>
Date: Fri, 23 Sep 2022 09:11:43 +0200
Subject: [PATCH 02/11] Update Condition.php
---
src/Condition.php | 122 +++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 114 insertions(+), 8 deletions(-)
diff --git a/src/Condition.php b/src/Condition.php
index 0423de6..b8e249c 100644
--- a/src/Condition.php
+++ b/src/Condition.php
@@ -29,19 +29,125 @@
namespace Idoit\APIClient;
use \Exception;
-use \BadMethodCallException;
-use \RuntimeException;
/**
- * Requests for assigned files
+ * Conditional helper for more readable code
*/
-class Condition {
+class Condition {
- private string $message;
+ public $property;
- public function __construct()
+ public $comparison;
+
+ public $value;
+
+ public $operator;
+
+ public function where($const, $property):self {
+ $this->property = $const . "-" . $property;
+ return $this;
+ }
+
+ public function andWhere($const, $property):self {
+ $this->operator = 'AND';
+ $this->where($const, $property);
+ return $this;
+ }
+
+ public function orWhere($const, $property):self {
+ $this->operator = 'OR';
+ $this->where($const, $property);
+ return $this;
+ }
+
+ public function isLike($value):self {
+ $this->comparison = 'like';
+ $this->value = $value;
+ return $this;
+ }
+
+ public function isNotLike($value):self {
+ $this->comparison = 'notlike';
+ $this->value = $value;
+ return $this;
+ }
+
+ public function isEqualTo($value):self {
+ $this->comparison = '=';
+ $this->value = $value;
+ return $this;
+ }
+
+ public function isNotEqualTo($value):self {
+ $this->comparison = '!=';
+ $this->value = $value;
+ return $this;
+ }
+
+ public function isGreaterThan($value):self {
+ $this->comparison = '>';
+ $this->value = $value;
+ return $this;
+ }
+
+ public function isGreaterOrEqaulThan($value):self {
+ $this->comparison = '>=';
+ $this->value = $value;
+ return $this;
+ }
+
+ public function isLowerThan($value):self {
+ $this->comparison = '<';
+ $this->value = $value;
+ return $this;
+ }
+
+ public function isLowerOrEaqualThan($value):self {
+ $this->comparison = '<=';
+ $this->value = $value;
+ return $this;
+ }
+
+ public function isLowerOrGreaterThan($value):self {
+ $this->comparison = '<>';
+ $this->value = $value;
+ return $this;
+ }
+
+ public function __construct($const = null, $property = null, $comparison = null, $value = null, $operator = null)
{
- $this->message = "Hello World!";
+
+ if (!is_null($const) && !is_null($property)) {
+ $this->property = $const . "-" . $property;
+ }
+
+ $allowedComparison = ['=', '!=', 'like', 'not like', '>', '>=', '<', '<=', '<>'];
+ if (!is_null($comparison) && !is_null($value) && in_array($comparison, $allowedComparison)) {
+ $this->comparison = $comparison;
+ $this->value = $value;
+ }
+
+ $allowedOperators = ['AND', 'OR'];
+ if (!is_null($operator) && in_array(strtoupper($operator), $allowedOperators)) {
+ $this->operator = strtoupper($operator);
+ }
+ }
+
+ public function toArray(): array
+ {
+
+ $condition = [
+ 'property' => $this->property,
+ 'comparison' => $this->comparison,
+ 'value' => $this->value
+ ];
+
+ if (isset($this->operator)) {
+ $condition['operator'] = $this->operator;
+ }
+
+ return $condition;
+
}
-}
+}
\ No newline at end of file
From d3218176f633a3286d6f53d9375a8202c9e5e855 Mon Sep 17 00:00:00 2001
From: Ralf Kornberger <37985317+rakoitde@users.noreply.github.com>
Date: Sat, 24 Sep 2022 07:39:07 +0200
Subject: [PATCH 03/11] add condition helper class
---
README.md | 54 +++++
src/Condition.php | 66 ++++--
tests/Idoit/APIClient/ConditionTest.php | 280 ++++++++++++++++++++++++
3 files changed, 378 insertions(+), 22 deletions(-)
create mode 100644 tests/Idoit/APIClient/ConditionTest.php
diff --git a/README.md b/README.md
index d77355c..c70ed4e 100644
--- a/README.md
+++ b/README.md
@@ -477,6 +477,60 @@ $cmdbObjects
->purge([1, 2, 3]);
~~~
+#### Read object by condition
+
+Allowed comparison are '=', '!=', 'like', 'not like', '>', '>=', '<', '<=', '<>'.
+
+~~~ {.php}
+use Idoit\APIClient\API;
+use Idoit\APIClient\CMDBCondition;
+
+$api = new API([/* … */]);
+$condition = new CMDBCondition($api);
+$result = $condition->read(
+ [
+ [
+ 'property' => "C__CATG__ACCOUNTING-order_no",
+ 'comparison' => "=",
+ 'value' => "ORDER4711",
+ ]
+ ]
+);
+~~~
+
+You can use more than one condition and add an operator to them.
+Allowed oprerators are 'AND' and 'OR'.
+
+~~~ {.php}
+$result = $condition->read(
+ [
+ [
+ 'property' => "C__CATG__ACCOUNTING-order_no",
+ 'comparison' => "=",
+ 'value' => "ORDER4711",
+ ],
+ [
+ 'property' => "C__CATG__ACCOUNTING-order_no",
+ 'comparison' => "=",
+ 'value' => "ORDER0815",
+ 'operator' => 'OR',
+ ]
+ ]
+);
+~~~
+
+For more readable code you can use the condition helper class.
+
+~~~ {.php}
+use Idoit\APIClient\Condition;
+
+$conditions = [
+ new Condition("C__CATG__ACCOUNTING", "order_no", "=", "ORDER4711"),
+ new Condition("C__CATG__ACCOUNTING", "order_no", "=", "ORDER4711", Condition::OR),
+];
+$result = $condition->read($conditions);
+~~~
+
#### Create category entries with attributes
~~~ {.php}
diff --git a/src/Condition.php b/src/Condition.php
index b8e249c..e290a43 100644
--- a/src/Condition.php
+++ b/src/Condition.php
@@ -17,11 +17,11 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
- * @author Benjamin Heisig
+ * @author Benjamin Heisig
* @copyright Copyright (C) 2022 synetics GmbH
* @copyright Copyright (C) 2016-2022 Benjamin Heisig
- * @license http://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License (AGPL)
- * @link https://github.com/i-doit/api-client-php
+ * @license http://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License (AGPL)
+ * @link https://github.com/i-doit/api-client-php
*/
declare(strict_types=1);
@@ -33,7 +33,18 @@
/**
* Conditional helper for more readable code
*/
-class Condition {
+class Condition
+{
+
+ /**
+ * Operator: AND
+ */
+ const AND = 'AND';
+
+ /**
+ * Operator: URL
+ */
+ const OR = 'OR';
public $property;
@@ -43,72 +54,84 @@ class Condition {
public $operator;
- public function where($const, $property):self {
+ public function where($const, $property):self
+ {
$this->property = $const . "-" . $property;
return $this;
}
- public function andWhere($const, $property):self {
- $this->operator = 'AND';
+ public function andWhere($const, $property):self
+ {
+ $this->operator = self::AND;
$this->where($const, $property);
return $this;
}
- public function orWhere($const, $property):self {
- $this->operator = 'OR';
+ public function orWhere($const, $property):self
+ {
+ $this->operator = self::OR;
$this->where($const, $property);
return $this;
}
- public function isLike($value):self {
+ public function isLike($value):self
+ {
$this->comparison = 'like';
$this->value = $value;
return $this;
}
- public function isNotLike($value):self {
- $this->comparison = 'notlike';
+ public function isNotLike($value):self
+ {
+ $this->comparison = 'not like';
$this->value = $value;
return $this;
}
- public function isEqualTo($value):self {
+ public function isEqualTo($value):self
+ {
$this->comparison = '=';
$this->value = $value;
return $this;
}
- public function isNotEqualTo($value):self {
+ public function isNotEqualTo($value):self
+ {
$this->comparison = '!=';
$this->value = $value;
return $this;
}
- public function isGreaterThan($value):self {
+ public function isGreaterThan($value):self
+ {
$this->comparison = '>';
$this->value = $value;
return $this;
}
- public function isGreaterOrEqaulThan($value):self {
+ public function isGreaterOrEqaulThan($value):self
+ {
$this->comparison = '>=';
$this->value = $value;
return $this;
}
- public function isLowerThan($value):self {
+ public function isLowerThan($value):self
+ {
$this->comparison = '<';
$this->value = $value;
return $this;
}
- public function isLowerOrEaqualThan($value):self {
+ public function isLowerOrEaqualThan($value):self
+ {
$this->comparison = '<=';
$this->value = $value;
return $this;
}
- public function isLowerOrGreaterThan($value):self {
+ public function isLowerOrGreaterThan($value):self
+ {
$this->comparison = '<>';
$this->value = $value;
return $this;
@@ -127,7 +150,7 @@ public function __construct($const = null, $property = null, $comparison = null,
$this->value = $value;
}
- $allowedOperators = ['AND', 'OR'];
+ $allowedOperators = [self::AND, self::OR];
if (!is_null($operator) && in_array(strtoupper($operator), $allowedOperators)) {
$this->operator = strtoupper($operator);
}
@@ -147,7 +170,6 @@ public function toArray(): array
}
return $condition;
-
}
-}
\ No newline at end of file
+}
diff --git a/tests/Idoit/APIClient/ConditionTest.php b/tests/Idoit/APIClient/ConditionTest.php
new file mode 100644
index 0000000..4cda50f
--- /dev/null
+++ b/tests/Idoit/APIClient/ConditionTest.php
@@ -0,0 +1,280 @@
+.
+ *
+ * @author Benjamin Heisig
+ * @copyright Copyright (C) 2022 synetics GmbH
+ * @copyright Copyright (C) 2016-2022 Benjamin Heisig
+ * @license http://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License (AGPL)
+ * @link https://github.com/i-doit/api-client-php
+ */
+
+declare(strict_types=1);
+
+namespace Idoit\APIClient;
+
+use \Exception;
+
+class ConditionTest extends BaseTest {
+
+ /**
+ * @throws Exception on error
+ */
+ public function testConditionByConstructor() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "=",
+ 'value' => "INV4711",
+ ];
+
+ $entry = (new Condition("C__CATG__ACCOUNTING", "inventory_no", "=", "INV4711"))->toArray();
+
+ $this->assertIsArray($entry);
+ $this->assertArrayHasKey('property', $entry);
+ $this->assertArrayHasKey('comparison', $entry);
+ $this->assertArrayHasKey('value', $entry);
+
+ $this->assertIsString($entry['property']);
+ $this->assertIsString($entry['comparison']);
+ $this->assertIsString($entry['value']);
+
+ $this->assertSame($condition, $entry);
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testConditionByConstructorWithAndOperator() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "=",
+ 'value' => "INV4711",
+ 'operator' => "AND"
+ ];
+
+ $entry = (new Condition("C__CATG__ACCOUNTING", "inventory_no", "=", "INV4711", Condition::AND))->toArray();
+
+ $this->assertIsArray($entry);
+ $this->assertArrayHasKey('operator', $entry);
+ $this->assertIsString($entry['operator']);
+
+ $this->assertSame($condition, $entry);
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testConditionByConstructorWithOrOperator() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "=",
+ 'value' => "INV4711",
+ 'operator' => "OR"
+ ];
+
+ $entry = (new Condition("C__CATG__ACCOUNTING", "inventory_no", "=", "INV4711", Condition::OR))->toArray();
+
+ $this->assertIsArray($entry);
+ $this->assertArrayHasKey('operator', $entry);
+ $this->assertIsString($entry['operator']);
+
+ $this->assertSame($condition, $entry);
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testWhereIsLike() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "like",
+ 'value' => "INV4711",
+ ];
+
+ $entry = (new Condition())->where("C__CATG__ACCOUNTING", "inventory_no")->isLike("INV4711");
+
+ $this->assertSame($condition, $entry->toArray());
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testWhereIsNotLike() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "not like",
+ 'value' => "INV4711",
+ ];
+
+ $entry = (new Condition())->where("C__CATG__ACCOUNTING", "inventory_no")->isNotLike("INV4711");
+
+ $this->assertSame($condition, $entry->toArray());
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testWhereIsEqualTo() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "=",
+ 'value' => "INV4711",
+ ];
+
+ $entry = (new Condition())->where("C__CATG__ACCOUNTING", "inventory_no")->isEqualTo("INV4711");
+
+ $this->assertSame($condition, $entry->toArray());
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testAndWhereIsEqualTo() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "=",
+ 'value' => "INV4711",
+ 'operator' => "AND"
+ ];
+
+ $entry = (new Condition())->andWhere("C__CATG__ACCOUNTING", "inventory_no")->isEqualTo("INV4711");
+
+ $this->assertSame($condition, $entry->toArray());
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testOrWhereIsEqualTo() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "=",
+ 'value' => "INV4711",
+ 'operator' => "OR"
+ ];
+
+ $entry = (new Condition())->orWhere("C__CATG__ACCOUNTING", "inventory_no")->isEqualTo("INV4711");
+
+ $this->assertSame($condition, $entry->toArray());
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testWhereIsNotEqualTo() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "!=",
+ 'value' => "INV4711",
+ ];
+
+ $entry = (new Condition())->where("C__CATG__ACCOUNTING", "inventory_no")->isNotEqualTo("INV4711");
+
+ $this->assertSame($condition, $entry->toArray());
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testWhereIsGreaterThan() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => ">",
+ 'value' => "INV4711",
+ ];
+
+ $entry = (new Condition())->where("C__CATG__ACCOUNTING", "inventory_no")->isGreaterThan("INV4711");
+
+ $this->assertSame($condition, $entry->toArray());
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testWhereIsGreaterOrEqaulThan() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => ">=",
+ 'value' => "INV4711",
+ ];
+
+ $entry = (new Condition())->where("C__CATG__ACCOUNTING", "inventory_no")->isGreaterOrEqaulThan("INV4711");
+
+ $this->assertSame($condition, $entry->toArray());
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testWhereIsLowerThan() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "<",
+ 'value' => "INV4711",
+ ];
+
+ $entry = (new Condition())->where("C__CATG__ACCOUNTING", "inventory_no")->isLowerThan("INV4711");
+
+ $this->assertSame($condition, $entry->toArray());
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testWhereIsLowerOrEaqualThan() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "<=",
+ 'value' => "INV4711",
+ ];
+
+ $entry = (new Condition())->where("C__CATG__ACCOUNTING", "inventory_no")->isLowerOrEaqualThan("INV4711");
+
+ $this->assertSame($condition, $entry->toArray());
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testWhereIsLowerOrGreaterThan() {
+
+ $condition = [
+ 'property' => "C__CATG__ACCOUNTING-inventory_no",
+ 'comparison' => "<>",
+ 'value' => "INV4711",
+ ];
+
+ $entry = (new Condition())->where("C__CATG__ACCOUNTING", "inventory_no")->isLowerOrGreaterThan("INV4711");
+
+ $this->assertSame($condition, $entry->toArray());
+ }
+
+}
From c8e3b3eacf0c659b0eafb1b63ddae4addaac4d6f Mon Sep 17 00:00:00 2001
From: Kornberger
Date: Sun, 13 Aug 2023 13:37:48 +0200
Subject: [PATCH 04/11] Fixed typo in README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index c70ed4e..ddec6db 100644
--- a/README.md
+++ b/README.md
@@ -499,7 +499,7 @@ $result = $condition->read(
~~~
You can use more than one condition and add an operator to them.
-Allowed oprerators are 'AND' and 'OR'.
+Allowed operators are 'AND' and 'OR'.
~~~ {.php}
$result = $condition->read(
From 2fca95c419c08324c05d15397545f8bbf51ca453 Mon Sep 17 00:00:00 2001
From: Kornberger
Date: Sun, 13 Aug 2023 13:53:52 +0200
Subject: [PATCH 05/11] remove author
---
tests/Idoit/APIClient/ConditionTest.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/tests/Idoit/APIClient/ConditionTest.php b/tests/Idoit/APIClient/ConditionTest.php
index 4cda50f..03fa371 100644
--- a/tests/Idoit/APIClient/ConditionTest.php
+++ b/tests/Idoit/APIClient/ConditionTest.php
@@ -17,7 +17,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
- * @author Benjamin Heisig
* @copyright Copyright (C) 2022 synetics GmbH
* @copyright Copyright (C) 2016-2022 Benjamin Heisig
* @license http://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License (AGPL)
From c38e241835775abb4a45d4d6ac3cb669bcad19f5 Mon Sep 17 00:00:00 2001
From: "Kornberger, Ralf"
Date: Mon, 14 Aug 2023 08:50:23 +0200
Subject: [PATCH 06/11] added some tests
---
tests/Idoit/APIClient/ConditionTest.php | 47 +++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/tests/Idoit/APIClient/ConditionTest.php b/tests/Idoit/APIClient/ConditionTest.php
index 03fa371..548003d 100644
--- a/tests/Idoit/APIClient/ConditionTest.php
+++ b/tests/Idoit/APIClient/ConditionTest.php
@@ -28,6 +28,7 @@
namespace Idoit\APIClient;
use \Exception;
+use Idoit\APIClient\Constants\Category;
class ConditionTest extends BaseTest {
@@ -276,4 +277,50 @@ public function testWhereIsLowerOrGreaterThan() {
$this->assertSame($condition, $entry->toArray());
}
+ /**
+ * @throws Exception on error
+ */
+ public function testReadObjectByConditionWhereIsEqualToWithAndOperator() {
+ $objectID = $this->createServer();
+
+ $attributes = [
+ 'inventory_no' => $this->generateRandomString(),
+ 'order_no' => $this->generateRandomString(),
+ 'invoice_no' => $this->generateRandomString()
+ ];
+
+ $entryID = $this->useCMDBCategory()->save( $objectID, Category::CATG__ACCOUNTING, $attributes );
+
+ $cmdbCondition = $this->useCMDBCondition();
+ $conditions = [];
+ foreach ($attributes as $attribute => $value) {
+ $conditions[] = (new Condition())->where("C__CATG__ACCOUNTING", $attribute, Condition::AND)->isEqualTo($value);
+ }
+ $objects = $cmdbCondition->read($conditions);
+ $this->assertSame($objectID, intval($objects[0]['id']));
+ }
+
+ /**
+ * @throws Exception on error
+ */
+ public function testReadObjectByConditionWhereIsEqualToWithOrOperator() {
+ $objectID = $this->createServer();
+
+ $attributes = [
+ 'inventory_no' => $this->generateRandomString(),
+ 'order_no' => $this->generateRandomString(),
+ 'invoice_no' => $this->generateRandomString()
+ ];
+
+ $entryID = $this->useCMDBCategory()->save( $objectID, Category::CATG__ACCOUNTING, $attributes );
+
+ $cmdbCondition = $this->useCMDBCondition();
+ $conditions = [];
+ foreach ($attributes as $attribute => $value) {
+ $conditions[] = (new Condition())->where("C__CATG__ACCOUNTING", $attribute, Condition::OR)->isEqualTo($value);
+ }
+ $objects = $cmdbCondition->read($conditions);
+ $this->assertSame($objectID, intval($objects[0]['id']));
+ }
+
}
From 122d6c079d13192c5cc9107f7ff47b9bc733ae78 Mon Sep 17 00:00:00 2001
From: "Kornberger, Ralf"
Date: Mon, 14 Aug 2023 08:52:11 +0200
Subject: [PATCH 07/11] remove author and add type declarations
---
src/Condition.php | 35 +++++++++++++++++------------------
1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/src/Condition.php b/src/Condition.php
index e290a43..10d7505 100644
--- a/src/Condition.php
+++ b/src/Condition.php
@@ -17,7 +17,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
- * @author Benjamin Heisig
* @copyright Copyright (C) 2022 synetics GmbH
* @copyright Copyright (C) 2016-2022 Benjamin Heisig
* @license http://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License (AGPL)
@@ -46,98 +45,98 @@ class Condition
*/
const OR = 'OR';
- public $property;
+ public string $property;
- public $comparison;
+ public string $comparison;
- public $value;
+ public string $value;
- public $operator;
+ public string $operator;
- public function where($const, $property):self
+ public function where(string $const, string $property):self
{
$this->property = $const . "-" . $property;
return $this;
}
- public function andWhere($const, $property):self
+ public function andWhere(string $const, string $property):self
{
$this->operator = self::AND;
$this->where($const, $property);
return $this;
}
- public function orWhere($const, $property):self
+ public function orWhere(string $const, string $property):self
{
$this->operator = self::OR;
$this->where($const, $property);
return $this;
}
- public function isLike($value):self
+ public function isLike(string $value):self
{
$this->comparison = 'like';
$this->value = $value;
return $this;
}
- public function isNotLike($value):self
+ public function isNotLike(string $value):self
{
$this->comparison = 'not like';
$this->value = $value;
return $this;
}
- public function isEqualTo($value):self
+ public function isEqualTo(string $value):self
{
$this->comparison = '=';
$this->value = $value;
return $this;
}
- public function isNotEqualTo($value):self
+ public function isNotEqualTo(string $value):self
{
$this->comparison = '!=';
$this->value = $value;
return $this;
}
- public function isGreaterThan($value):self
+ public function isGreaterThan(string $value):self
{
$this->comparison = '>';
$this->value = $value;
return $this;
}
- public function isGreaterOrEqaulThan($value):self
+ public function isGreaterOrEqaulThan(string $value):self
{
$this->comparison = '>=';
$this->value = $value;
return $this;
}
- public function isLowerThan($value):self
+ public function isLowerThan(string $value):self
{
$this->comparison = '<';
$this->value = $value;
return $this;
}
- public function isLowerOrEaqualThan($value):self
+ public function isLowerOrEaqualThan(string $value):self
{
$this->comparison = '<=';
$this->value = $value;
return $this;
}
- public function isLowerOrGreaterThan($value):self
+ public function isLowerOrGreaterThan(string $value):self
{
$this->comparison = '<>';
$this->value = $value;
return $this;
}
- public function __construct($const = null, $property = null, $comparison = null, $value = null, $operator = null)
+ public function __construct(string $const = null, string $property = null, string $comparison = null, string $value = null, string $operator = null)
{
if (!is_null($const) && !is_null($property)) {
From 2bf133766aabec8abc8e64bde899578a6dcec71a Mon Sep 17 00:00:00 2001
From: "Kornberger, Ralf"
Date: Mon, 14 Aug 2023 09:52:43 +0200
Subject: [PATCH 08/11] make phpcs happy
---
tests/Idoit/APIClient/ConditionTest.php | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/tests/Idoit/APIClient/ConditionTest.php b/tests/Idoit/APIClient/ConditionTest.php
index 548003d..01b0c3c 100644
--- a/tests/Idoit/APIClient/ConditionTest.php
+++ b/tests/Idoit/APIClient/ConditionTest.php
@@ -289,12 +289,13 @@ public function testReadObjectByConditionWhereIsEqualToWithAndOperator() {
'invoice_no' => $this->generateRandomString()
];
- $entryID = $this->useCMDBCategory()->save( $objectID, Category::CATG__ACCOUNTING, $attributes );
+ $entryID = $this->useCMDBCategory()->save($objectID, Category::CATG__ACCOUNTING, $attributes);
$cmdbCondition = $this->useCMDBCondition();
$conditions = [];
foreach ($attributes as $attribute => $value) {
- $conditions[] = (new Condition())->where("C__CATG__ACCOUNTING", $attribute, Condition::AND)->isEqualTo($value);
+ $condition = new Condition();
+ $conditions[] = $condition->where("C__CATG__ACCOUNTING", $attribute, Condition::AND)->isEqualTo($value);
}
$objects = $cmdbCondition->read($conditions);
$this->assertSame($objectID, intval($objects[0]['id']));
@@ -312,12 +313,13 @@ public function testReadObjectByConditionWhereIsEqualToWithOrOperator() {
'invoice_no' => $this->generateRandomString()
];
- $entryID = $this->useCMDBCategory()->save( $objectID, Category::CATG__ACCOUNTING, $attributes );
+ $entryID = $this->useCMDBCategory()->save($objectID, Category::CATG__ACCOUNTING, $attributes);
$cmdbCondition = $this->useCMDBCondition();
$conditions = [];
foreach ($attributes as $attribute => $value) {
- $conditions[] = (new Condition())->where("C__CATG__ACCOUNTING", $attribute, Condition::OR)->isEqualTo($value);
+ $condition = new Condition();
+ $conditions[] = $condition->where("C__CATG__ACCOUNTING", $attribute, Condition::OR)->isEqualTo($value);
}
$objects = $cmdbCondition->read($conditions);
$this->assertSame($objectID, intval($objects[0]['id']));
From 91e34b38b279041f7d6965e6db241476fdd23750 Mon Sep 17 00:00:00 2001
From: "Kornberger, Ralf"
Date: Mon, 14 Aug 2023 09:55:32 +0200
Subject: [PATCH 09/11] make phpcs happy
with type declarations the characters in this lines exceeds 120. so i have to remove type declarations.
---
src/Condition.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Condition.php b/src/Condition.php
index 10d7505..578ace6 100644
--- a/src/Condition.php
+++ b/src/Condition.php
@@ -136,7 +136,7 @@ public function isLowerOrGreaterThan(string $value):self
return $this;
}
- public function __construct(string $const = null, string $property = null, string $comparison = null, string $value = null, string $operator = null)
+ public function __construct ($const = null, $property = null, $comparison = null, $value = null, $operator = null)
{
if (!is_null($const) && !is_null($property)) {
From 4b79618db4afac766cb23a1332ad7763b95ed6f2 Mon Sep 17 00:00:00 2001
From: "Kornberger, Ralf"
Date: Mon, 14 Aug 2023 10:00:25 +0200
Subject: [PATCH 10/11] remove whitespace
---
src/Condition.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Condition.php b/src/Condition.php
index 578ace6..c3da8c3 100644
--- a/src/Condition.php
+++ b/src/Condition.php
@@ -136,7 +136,7 @@ public function isLowerOrGreaterThan(string $value):self
return $this;
}
- public function __construct ($const = null, $property = null, $comparison = null, $value = null, $operator = null)
+ public function __construct($const = null, $property = null, $comparison = null, $value = null, $operator = null)
{
if (!is_null($const) && !is_null($property)) {
From 9c9a25678766fbefdfef4ee7bb6149fdac7f1b99 Mon Sep 17 00:00:00 2001
From: "Kornberger, Ralf"
Date: Mon, 14 Aug 2023 10:36:40 +0200
Subject: [PATCH 11/11] correct use of method
---
tests/Idoit/APIClient/ConditionTest.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/Idoit/APIClient/ConditionTest.php b/tests/Idoit/APIClient/ConditionTest.php
index 01b0c3c..13d30fc 100644
--- a/tests/Idoit/APIClient/ConditionTest.php
+++ b/tests/Idoit/APIClient/ConditionTest.php
@@ -295,7 +295,7 @@ public function testReadObjectByConditionWhereIsEqualToWithAndOperator() {
$conditions = [];
foreach ($attributes as $attribute => $value) {
$condition = new Condition();
- $conditions[] = $condition->where("C__CATG__ACCOUNTING", $attribute, Condition::AND)->isEqualTo($value);
+ $conditions[] = $condition->andWhere("C__CATG__ACCOUNTING", $attribute)->isEqualTo($value);
}
$objects = $cmdbCondition->read($conditions);
$this->assertSame($objectID, intval($objects[0]['id']));
@@ -319,7 +319,7 @@ public function testReadObjectByConditionWhereIsEqualToWithOrOperator() {
$conditions = [];
foreach ($attributes as $attribute => $value) {
$condition = new Condition();
- $conditions[] = $condition->where("C__CATG__ACCOUNTING", $attribute, Condition::OR)->isEqualTo($value);
+ $conditions[] = $condition->orWhere("C__CATG__ACCOUNTING", $attribute)->isEqualTo($value);
}
$objects = $cmdbCondition->read($conditions);
$this->assertSame($objectID, intval($objects[0]['id']));