diff --git a/composer.json b/composer.json index 8e0e2942..46341b02 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ } ], "require": { - "php": ">=5.6.0" + "php": ">=8.0" }, "autoload": { "psr-0": { diff --git a/lib/ArangoDBClient/Analyzer.php b/lib/ArangoDBClient/Analyzer.php index adbe5f4c..b4d1205b 100644 --- a/lib/ArangoDBClient/Analyzer.php +++ b/lib/ArangoDBClient/Analyzer.php @@ -48,7 +48,11 @@ class Analyzer * Analyzer features index */ const ENTRY_FEATURES = 'features'; - + + private array $_features; + private array $_properties; + private string $_type; + /** * Constructs an analyzer * diff --git a/lib/ArangoDBClient/Batch.php b/lib/ArangoDBClient/Batch.php index d845fc9e..5a3589b2 100644 --- a/lib/ArangoDBClient/Batch.php +++ b/lib/ArangoDBClient/Batch.php @@ -85,7 +85,6 @@ class Batch */ private $_nextId = 0; - /** * Constructor for Batch instance. Batch instance by default starts capturing request after initiated. * To disable this, pass startCapture=>false inside the options array parameter @@ -109,16 +108,15 @@ public function __construct(Connection $connection, array $options = []) $options = array_merge($options, $this->getCursorOptions()); extract($options, EXTR_IF_EXISTS); $this->_sanitize = $sanitize; - $this->batchSize = $batchSize; - if ($this->batchSize > 0) { - $this->_batchParts = new \SplFixedArray($this->batchSize); + if ($batchSize > 0) { + $this->_batchParts = new \SplFixedArray($batchSize); } $this->setConnection($connection); // set default cursor options. Sanitize is currently the only local one. - $this->_batchPartCursorOptions = [Cursor::ENTRY_SANITIZE => (bool) $this->_sanitize]; + $this->_batchPartCursorOptions = [Cursor::ENTRY_SANITIZE => $this->_sanitize]; if ($startCapture === true) { $this->startCapture(); diff --git a/lib/ArangoDBClient/ConnectionOptions.php b/lib/ArangoDBClient/ConnectionOptions.php index a1bd61ae..222a07e3 100644 --- a/lib/ArangoDBClient/ConnectionOptions.php +++ b/lib/ArangoDBClient/ConnectionOptions.php @@ -69,23 +69,23 @@ class ConnectionOptions implements \ArrayAccess * @deprecated superseded by OPTION_CONNECT_TIMEOUT and OPTION_REQUEST_TIMEOUT */ const OPTION_TIMEOUT = 'timeout'; - + /** * Connect timeout value index constant */ const OPTION_CONNECT_TIMEOUT = 'connectTimeout'; - + /** * Request timeout value index constant */ const OPTION_REQUEST_TIMEOUT = 'requestTimeout'; - + /** * Number of servers tried in case of failover * if set to 0, then an unlimited amount of servers will be tried */ const OPTION_FAILOVER_TRIES = 'failoverTries'; - + /** * Max amount of time (in seconds) that is spent waiting on failover */ @@ -100,7 +100,7 @@ class ConnectionOptions implements \ArrayAccess * "verify certificates" index constant */ const OPTION_VERIFY_CERT = 'verifyCert'; - + /** * "verify certificate host name" index constant */ @@ -110,7 +110,7 @@ class ConnectionOptions implements \ArrayAccess * "allow self-signed" index constant */ const OPTION_ALLOW_SELF_SIGNED = 'allowSelfSigned'; - + /** * "caFile" index constant */ @@ -180,7 +180,7 @@ class ConnectionOptions implements \ArrayAccess * Wait for sync index constant */ const OPTION_IS_SYSTEM = 'isSystem'; - + /** * Authentication JWT */ @@ -230,32 +230,32 @@ class ConnectionOptions implements \ArrayAccess * UTF-8 CHeck Flag */ const OPTION_CHECK_UTF8_CONFORM = 'CheckUtf8Conform'; - + /** * Entry for memcached servers array */ const OPTION_MEMCACHED_SERVERS = 'memcachedServers'; - + /** * Entry for memcached options array */ const OPTION_MEMCACHED_OPTIONS = 'memcachedOptions'; - + /** * Entry for memcached endpoints key */ const OPTION_MEMCACHED_ENDPOINTS_KEY = 'memcachedEndpointsKey'; - + /** * Entry for memcached persistend id */ const OPTION_MEMCACHED_PERSISTENT_ID = 'memcachedPersistentId'; - + /** * Entry for memcached cache ttl */ const OPTION_MEMCACHED_TTL = 'memcachedTtl'; - + /** * Entry for notification callback */ @@ -271,8 +271,8 @@ class ConnectionOptions implements \ArrayAccess public function __construct(array $options) { $this->_values = array_merge(self::getDefaults(), $options); - - if (isset($this->_values[self::OPTION_ENDPOINT]) && + + if (isset($this->_values[self::OPTION_ENDPOINT]) && !is_array($this->_values[self::OPTION_ENDPOINT])) { $this->_values[self::OPTION_ENDPOINT] = [ $this->_values[self::OPTION_ENDPOINT] ]; } @@ -286,7 +286,7 @@ public function __construct(array $options) * * @return array - all options as an array */ - public function getAll() + public function getAll(): array { return $this->_values; } @@ -301,7 +301,7 @@ public function getAll() * * @return void */ - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { $this->_values[$offset] = $value; if ($offset === self::OPTION_CONNECT_TIMEOUT || $offset === self::OPTION_REQUEST_TIMEOUT) { @@ -319,7 +319,7 @@ public function offsetSet($offset, $value) * * @return bool - true if option exists, false otherwise */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return isset($this->_values[$offset]); } @@ -333,7 +333,7 @@ public function offsetExists($offset) * * @return void */ - public function offsetUnset($offset) + public function offsetUnset($offset): void { unset($this->_values[$offset]); $this->validate(); @@ -348,7 +348,7 @@ public function offsetUnset($offset) * * @return mixed - value of option, will throw if option is not set */ - public function offsetGet($offset) + public function offsetGet($offset): mixed { if (!array_key_exists($offset, $this->_values)) { throw new ClientException('Invalid option ' . $offset); @@ -362,18 +362,18 @@ public function offsetGet($offset) * * @return string - Endpoint string to connect to */ - public function getCurrentEndpoint() + public function getCurrentEndpoint(): string { assert(is_array($this->_values[self::OPTION_ENDPOINT])); return $this->_values[self::OPTION_ENDPOINT][$this->_currentEndpointIndex]; } - + /** * Whether or not we have multiple endpoints to connect to * * @return bool - true if we have more than one endpoint to connect to */ - public function haveMultipleEndpoints() + public function haveMultipleEndpoints(): bool { assert(is_array($this->_values[self::OPTION_ENDPOINT])); return count($this->_values[self::OPTION_ENDPOINT]) > 1; @@ -388,7 +388,7 @@ public function haveMultipleEndpoints() * * @return void */ - public function addEndpoint($endpoint) + public function addEndpoint($endpoint): void { if (!is_string($endpoint) || !Endpoint::isValid($endpoint)) { throw new ClientException(sprintf("invalid endpoint specification '%s'", $endpoint)); @@ -405,7 +405,7 @@ public function addEndpoint($endpoint) break; } } - + if ($found === false) { // a new endpoint we have not seen before $this->_values[self::OPTION_ENDPOINT][] = $endpoint; @@ -414,14 +414,14 @@ public function addEndpoint($endpoint) $this->storeOptionsInCache(); } - + /** * Return the next endpoint from the list of endpoints * As a side-effect this function switches to a new endpoint * * @return string - the next endpoint */ - public function nextEndpoint() + public function nextEndpoint(): string { assert(is_array($this->_values[self::OPTION_ENDPOINT])); $endpoints = $this->_values[self::OPTION_ENDPOINT]; @@ -447,7 +447,7 @@ public function nextEndpoint() * * @return array - array of default connection options */ - private static function getDefaults() + private static function getDefaults(): array { return [ self::OPTION_ENDPOINT => [ ], @@ -494,7 +494,7 @@ private static function getDefaults() * * @return array - array with supported authorization types */ - private static function getSupportedAuthTypes() + private static function getSupportedAuthTypes(): array { return ['Basic', 'Bearer']; } @@ -504,7 +504,7 @@ private static function getSupportedAuthTypes() * * @return array - array with supported connection types */ - private static function getSupportedConnectionTypes() + private static function getSupportedConnectionTypes(): array { return ['Close', 'Keep-Alive']; } @@ -515,7 +515,7 @@ private static function getSupportedConnectionTypes() * @throws ClientException * @return void - will throw if an invalid option value is found */ - private function validate() + private function validate(): void { if (isset($this->_values[self::OPTION_HOST]) && !is_string($this->_values[self::OPTION_HOST])) { throw new ClientException('host should be a string'); @@ -535,17 +535,17 @@ private function validate() $this->_values[self::OPTION_ENDPOINT] = [ 'tcp://' . $this->_values[self::OPTION_HOST] . ':' . $this->_values[self::OPTION_PORT] ]; unset($this->_values[self::OPTION_HOST]); } - + if (!is_array($this->_values[self::OPTION_ENDPOINT])) { // make sure that we always have an array of endpoints $this->_values[self::OPTION_ENDPOINT] = [ $this->_values[self::OPTION_ENDPOINT] ]; } - + assert(is_array($this->_values[self::OPTION_ENDPOINT])); foreach ($this->_values[self::OPTION_ENDPOINT] as $key => $value) { $this->_values[self::OPTION_ENDPOINT][$key] = Endpoint::normalize($value); } - + if (count($this->_values[self::OPTION_ENDPOINT]) > 1) { // when we have more than a single endpoint, we must always use the reconnect option $this->_values[ConnectionOptions::OPTION_RECONNECT] = true; @@ -565,13 +565,13 @@ private function validate() // must set port to 0 for SSL connections $this->_values[self::OPTION_PORT] = 0; } else { - if (preg_match("/:(\d+)$/", $ep, $match)) { - // get port number from endpoint, to not confuse developers when dumping - // connection details - $this->_values[self::OPTION_PORT] = (int) $match[1]; - } + if (preg_match("/:(\d+)$/", $ep, $match)) { + // get port number from endpoint, to not confuse developers when dumping + // connection details + $this->_values[self::OPTION_PORT] = (int) $match[1]; + } } - + if (isset($this->_values[self::OPTION_AUTH_TYPE]) && !in_array( $this->_values[self::OPTION_AUTH_TYPE], self::getSupportedAuthTypes(), true @@ -592,7 +592,7 @@ private function validate() ) ); } - + if (isset($this->_values[self::OPTION_TIMEOUT])) { // propagate values from OPTION_TIMOEUT into OPTION_CONNECT_TIMEOUT and OPTION_REQUEST_TIMEOUT $this->_values[self::OPTION_CONNECT_TIMEOUT] = (float) $this->_values[self::OPTION_TIMEOUT]; @@ -611,14 +611,14 @@ private function validate() * * @return void */ - private function loadOptionsFromCache() + private function loadOptionsFromCache(): void { $cache = $this->getEndpointsCache(); if ($cache === null) { return; } - + $endpoints = $cache->get($this->_values[self::OPTION_MEMCACHED_ENDPOINTS_KEY]); if ($endpoints) { $this->_values[self::OPTION_ENDPOINT] = $endpoints; @@ -627,13 +627,13 @@ private function loadOptionsFromCache() } } } - + /** * store the updated options in the optional Memcached cache * * @return void */ - private function storeOptionsInCache() + private function storeOptionsInCache(): void { $endpoints = $this->_values[self::OPTION_ENDPOINT]; $numberOfEndpoints = count($endpoints); @@ -647,7 +647,7 @@ private function storeOptionsInCache() if ($cache === null) { return; } - + $update = [ $endpoints[$this->_currentEndpointIndex] ]; for ($i = 0; $i < $numberOfEndpoints; ++$i) { if ($i !== $this->_currentEndpointIndex) { @@ -657,15 +657,16 @@ private function storeOptionsInCache() $ttl = (int) $this->_values[self::OPTION_MEMCACHED_TTL]; $cache->set($this->_values[self::OPTION_MEMCACHED_ENDPOINTS_KEY], $update, $ttl); - } + } /** - * Initialize and return a memcached cache instance, + * Initialize and return a memcached cache instance, * if option "memcachedServers" is set * * @return Memcached - memcached server instance if configured or null if not + * @throws ClientException */ - private function getEndpointsCache() + private function getEndpointsCache(): ?\Memcached { if ($this->_cache === null) { if (!isset($this->_values[self::OPTION_MEMCACHED_SERVERS])) { @@ -684,7 +685,7 @@ private function getEndpointsCache() if (empty($cache->getServerList())) { $cache->addServers($servers); } - + if (isset($this->_values[self::OPTION_MEMCACHED_OPTIONS])) { $options = $this->_values[self::OPTION_MEMCACHED_OPTIONS]; if (!is_array($options)) { @@ -694,7 +695,7 @@ private function getEndpointsCache() } $this->_cache = $cache; - + } return $this->_cache; } diff --git a/lib/ArangoDBClient/Cursor.php b/lib/ArangoDBClient/Cursor.php index 816449cc..0940de80 100644 --- a/lib/ArangoDBClient/Cursor.php +++ b/lib/ArangoDBClient/Cursor.php @@ -107,7 +107,7 @@ class Cursor implements \Iterator * whether or not the query result was served from the AQL query result cache */ private $_cached; - + /** * precalculated number of documents in the cursor, as returned by the server * @@ -196,7 +196,7 @@ public function __construct(Connection $connection, array $data, array $options) if (isset($data[self::ENTRY_ID])) { $this->_id = $data[self::ENTRY_ID]; } - + if (isset($data[Statement::ENTRY_COUNT])) { $this->_count = $data[Statement::ENTRY_COUNT]; } @@ -240,7 +240,7 @@ public function __construct(Connection $connection, array $data, array $options) * @throws Exception * @return bool - true if the server acknowledged the deletion request, false otherwise */ - public function delete() + public function delete(): bool { if ($this->_id) { try { @@ -264,7 +264,7 @@ public function delete() * @throws Exception * @return int - total number of results */ - public function getCount() + public function getCount(): int { if ($this->_count !== null) { return $this->_count; @@ -282,7 +282,7 @@ public function getCount() * * @return int - total number of results */ - public function getFullCount() + public function getFullCount(): int { return $this->_fullCount; } @@ -293,7 +293,7 @@ public function getFullCount() * * @return bool - whether or not the query result was served from the AQL query cache */ - public function getCached() + public function getCached(): bool { return $this->_cached; } @@ -308,7 +308,7 @@ public function getCached() * @throws Exception * @return array - an array of all results */ - public function getAll() + public function getAll(): array { while ($this->_hasMore) { $this->fetchOutstanding(); @@ -323,7 +323,7 @@ public function getAll() * * @return void */ - public function rewind() + public function rewind(): void { $this->_position = 0; } @@ -334,7 +334,7 @@ public function rewind() * * @return array - the current result row as an assoc array */ - public function current() + public function current(): array { return $this->_result[$this->_position]; } @@ -345,7 +345,7 @@ public function current() * * @return int - the current result row index */ - public function key() + public function key(): int { return $this->_position; } @@ -356,7 +356,7 @@ public function key() * * @return void */ - public function next() + public function next(): void { ++$this->_position; } @@ -371,7 +371,7 @@ public function next() * @throws Exception * @return bool - true if the cursor can be advanced further, false if cursor is at end */ - public function valid() + public function valid(): bool { if ($this->_position <= $this->_length - 1) { // we have more results than the current position is @@ -398,7 +398,7 @@ public function valid() * @return void * @throws \ArangoDBClient\ClientException */ - private function add(array $data) + private function add(array $data): void { foreach ($this->sanitize($data) as $row) { if (!is_array($row) || (isset($this->_options[self::ENTRY_FLAT]) && $this->_options[self::ENTRY_FLAT])) { @@ -449,7 +449,7 @@ private function add(array $data) * * @return void */ - private function addFlatFromArray($data) + private function addFlatFromArray($data): void { $this->_result[] = $data; } @@ -463,7 +463,7 @@ private function addFlatFromArray($data) * @return void * @throws \ArangoDBClient\ClientException */ - private function addDocumentsFromArray(array $data) + private function addDocumentsFromArray(array $data): void { $_documentClass = $this->_documentClass; @@ -478,7 +478,7 @@ private function addDocumentsFromArray(array $data) * @return void * @throws \ArangoDBClient\ClientException */ - private function addPathsFromArray(array $data) + private function addPathsFromArray(array $data): void { $_documentClass = $this->_documentClass; $_edgeClass = $this->_edgeClass; @@ -506,7 +506,7 @@ private function addPathsFromArray(array $data) * @return void * @throws \ArangoDBClient\ClientException */ - private function addShortestPathFromArray(array $data) + private function addShortestPathFromArray(array $data): void { $_documentClass = $this->_documentClass; $_edgeClass = $this->_edgeClass; @@ -550,7 +550,7 @@ private function addShortestPathFromArray(array $data) * * @return void */ - private function addDistanceToFromArray(array $data) + private function addDistanceToFromArray(array $data): void { $entry = [ 'source' => $data['startVertex'], @@ -568,7 +568,7 @@ private function addDistanceToFromArray(array $data) * @return void * @throws \ArangoDBClient\ClientException */ - private function addCommonNeighborsFromArray(array $data) + private function addCommonNeighborsFromArray(array $data): void { $_documentClass = $this->_documentClass; @@ -594,7 +594,7 @@ private function addCommonNeighborsFromArray(array $data) * * @return void */ - private function addCommonPropertiesFromArray(array $data) + private function addCommonPropertiesFromArray(array $data): void { $k = array_keys($data); $k = $k[0]; @@ -613,7 +613,7 @@ private function addCommonPropertiesFromArray(array $data) * * @return void */ - private function addFigureFromArray(array $data) + private function addFigureFromArray(array $data): void { $this->_result = $data; } @@ -626,7 +626,7 @@ private function addFigureFromArray(array $data) * @return void * @throws \ArangoDBClient\ClientException */ - private function addEdgesFromArray(array $data) + private function addEdgesFromArray(array $data): void { $_edgeClass = $this->_edgeClass; @@ -642,7 +642,7 @@ private function addEdgesFromArray(array $data) * @return void * @throws \ArangoDBClient\ClientException */ - private function addVerticesFromArray(array $data) + private function addVerticesFromArray(array $data): void { $_documentClass = $this->_documentClass; @@ -660,7 +660,7 @@ private function addVerticesFromArray(array $data) * * @return array - sanitized rows */ - private function sanitize(array $rows) + private function sanitize(array $rows): array { $_documentClass = $this->_documentClass; @@ -687,7 +687,7 @@ private function sanitize(array $rows) * @throws Exception * @return void */ - private function fetchOutstanding() + private function fetchOutstanding(): void { // continuation $response = $this->_connection->post($this->url() . '/' . $this->_id, '', []); @@ -712,7 +712,7 @@ private function fetchOutstanding() * * @return void */ - private function updateLength() + private function updateLength(): void { $this->_length = count($this->_result); } @@ -723,7 +723,7 @@ private function updateLength() * * @return string */ - private function url() + private function url(): string { if (isset($this->_options[self::ENTRY_BASEURL])) { return $this->_options[self::ENTRY_BASEURL]; @@ -740,7 +740,7 @@ private function url() * * @return int */ - private function getStatValue($name) + private function getStatValue($name): int { if (isset($this->_extra[self::ENTRY_STATS][$name])) { return $this->_extra[self::ENTRY_STATS][$name]; @@ -754,7 +754,7 @@ private function getStatValue($name) * * @return array */ - public function getMetadata() + public function getMetadata(): array { return $this->data; } @@ -765,7 +765,7 @@ public function getMetadata() * * @return array */ - public function getExtra() + public function getExtra(): array { return $this->_extra; } @@ -775,7 +775,7 @@ public function getExtra() * * @return array */ - public function getWarnings() + public function getWarnings(): array { if (isset($this->_extra['warnings'])) { return $this->_extra['warnings']; @@ -789,7 +789,7 @@ public function getWarnings() * * @return int */ - public function getWritesExecuted() + public function getWritesExecuted(): int { return $this->getStatValue('writesExecuted'); } @@ -799,7 +799,7 @@ public function getWritesExecuted() * * @return int */ - public function getWritesIgnored() + public function getWritesIgnored(): int { return $this->getStatValue('writesIgnored'); } @@ -809,7 +809,7 @@ public function getWritesIgnored() * * @return int */ - public function getScannedFull() + public function getScannedFull(): int { return $this->getStatValue('scannedFull'); } @@ -819,7 +819,7 @@ public function getScannedFull() * * @return int */ - public function getScannedIndex() + public function getScannedIndex(): int { return $this->getStatValue('scannedIndex'); } @@ -829,22 +829,22 @@ public function getScannedIndex() * * @return int */ - public function getFiltered() + public function getFiltered(): int { return $this->getStatValue('filtered'); } - + /** * Return the peak memory usage of the query * * @return int */ - public function getPeakMemoryUsage() + public function getPeakMemoryUsage(): int { return $this->getStatValue('peakMemoryUsage'); } - - + + /** * Return the execution time of the query * @@ -860,7 +860,7 @@ public function getExecutionTime() * * @return int */ - public function getFetches() + public function getFetches(): int { return $this->_fetches; } @@ -870,7 +870,7 @@ public function getFetches() * * @return string */ - public function getId() + public function getId(): ?string { return $this->_id; } diff --git a/lib/ArangoDBClient/View.php b/lib/ArangoDBClient/View.php index 00cc7499..b41e4112 100644 --- a/lib/ArangoDBClient/View.php +++ b/lib/ArangoDBClient/View.php @@ -50,7 +50,14 @@ class View * View type index */ const ENTRY_TYPE = 'type'; - + + /** + * The view type + * + * @var string - view name + */ + private string $_type; + /** * Constructs an empty view *