Skip to content

Commit

Permalink
Apply PSR12 to codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
aivchen committed Oct 22, 2023
1 parent 9281f5b commit d166d09
Show file tree
Hide file tree
Showing 132 changed files with 253 additions and 307 deletions.
1 change: 0 additions & 1 deletion src/Manticoresearch/Arrayable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch;

interface Arrayable
Expand Down
7 changes: 3 additions & 4 deletions src/Manticoresearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Manticoresearch\Connection\ConnectionPool;
use Manticoresearch\Connection\Strategy\SelectorInterface;
use Manticoresearch\Connection\Strategy\StaticRoundRobin;

use Manticoresearch\Endpoints\Pq;
use Manticoresearch\Exceptions\ConnectionException;
use Manticoresearch\Exceptions\NoMoreNodesException;
Expand All @@ -27,7 +26,7 @@ class Client
/**
*
*/
const VERSION = '1.0.0';
public const VERSION = '1.0.0';

/**
* @var array
Expand Down Expand Up @@ -96,14 +95,14 @@ protected function initConnections()
throw new RuntimeException('Cannot create a strategy based on provided settings!');
}
} else {
$strategy = new $this->connectionStrategy;
$strategy = new $this->connectionStrategy();
}
if (!isset($this->config['retries'])) {
$this->config['retries'] = count($connections);
}
$this->connectionPool = new Connection\ConnectionPool(
$connections,
$strategy ?? new $this->connectionStrategy,
$strategy ?? new $this->connectionStrategy(),
$this->config['retries']
);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Manticoresearch/Cluster.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch;

use Manticoresearch\Endpoints\Cluster\Alter;
Expand All @@ -24,7 +23,7 @@ class Cluster
public function __construct($client)
{
$this->client = $client;
$this->params =['responseClass'=>'Manticoresearch\\Response\\SqlToArray'];
$this->params = ['responseClass' => 'Manticoresearch\\Response\\SqlToArray'];
}

public function alter($params)
Expand Down
1 change: 0 additions & 1 deletion src/Manticoresearch/Connection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch;

use Manticoresearch\Exceptions\RuntimeException;
Expand Down
2 changes: 1 addition & 1 deletion src/Manticoresearch/Connection/ConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ConnectionPool

public $retries;

public $retries_attempts =0;
public $retries_attempts = 0;

public function __construct(array $connections, SelectorInterface $strategy, int $retries)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Manticoresearch/Connection/Strategy/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Random implements SelectorInterface
* @param array $connections
* @return Connection
*/
public function getConnection(array $connections):Connection
public function getConnection(array $connections): Connection
{
shuffle($connections);
return $connections[0];
Expand Down
3 changes: 1 addition & 2 deletions src/Manticoresearch/Connection/Strategy/RoundRobin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Connection\Strategy;

use Manticoresearch\Connection;
Expand All @@ -20,7 +19,7 @@ class RoundRobin implements SelectorInterface
* @param array $connections
* @return Connection
*/
public function getConnection(array $connections) :Connection
public function getConnection(array $connections): Connection
{
$connection = $connections[$this->current % count($connections)];
++$this->current;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Connection\Strategy;

use Manticoresearch\Connection;
Expand All @@ -15,5 +14,5 @@ interface SelectorInterface
* @param array $connections
* @return Connection
*/
public function getConnection(array $connections):Connection;
public function getConnection(array $connections): Connection;
}
3 changes: 1 addition & 2 deletions src/Manticoresearch/Connection/Strategy/StaticRoundRobin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Connection\Strategy;

use Manticoresearch\Connection;
Expand All @@ -20,7 +19,7 @@ class StaticRoundRobin implements SelectorInterface
* @param array $connections
* @return Connection
*/
public function getConnection(array $connections):Connection
public function getConnection(array $connections): Connection
{
if ($connections[$this->current % count($connections)]->isAlive()) {
return $connections[$this->current];
Expand Down
3 changes: 2 additions & 1 deletion src/Manticoresearch/Endpoints/Cluster/Alter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class Alter extends EmulateBySql
{
use Utils;

/**
* @var string
*/
Expand All @@ -35,7 +36,7 @@ public function setBody($params = null)
throw new RuntimeException('Index name is missing.');
break;
case 'update':
return parent::setBody(['query' => "ALTER CLUSTER " .$this->cluster . " UPDATE nodes"]);
return parent::setBody(['query' => "ALTER CLUSTER " . $this->cluster . " UPDATE nodes"]);
break;
}
throw new RuntimeException('Unknown cluster operation');
Expand Down
1 change: 1 addition & 0 deletions src/Manticoresearch/Endpoints/Cluster/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class Create extends EmulateBySql
{
use Utils;

/**
* @var string
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Manticoresearch/Endpoints/Cluster/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class Delete extends EmulateBySql
{
use Utils;

/**
* @var string
*/
Expand All @@ -23,7 +24,7 @@ class Delete extends EmulateBySql
public function setBody($params = null)
{
if (isset($this->cluster)) {
return parent::setBody(['query' => "DELETE CLUSTER ".$this->cluster]);
return parent::setBody(['query' => "DELETE CLUSTER " . $this->cluster]);
}
throw new RuntimeException('Cluster name is missing.');
}
Expand Down
13 changes: 7 additions & 6 deletions src/Manticoresearch/Endpoints/Cluster/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class Join extends EmulateBySql
{
use Utils;

/**
* @var string
*/
Expand All @@ -24,17 +25,17 @@ public function setBody($params = null)
{
if (isset($this->cluster)) {
if (isset($params['node'])) {
return parent::setBody(['query' => "JOIN CLUSTER ".$this->cluster." AT '".$params['node']."'"]);
return parent::setBody(['query' => "JOIN CLUSTER " . $this->cluster . " AT '" . $params['node'] . "'"]);
} else {
$options =[];
$options = [];
if (isset($params['path'])) {
$options[] = "'".$params['path']. "' AS path";
$options[] = "'" . $params['path'] . "' AS path";
}
if (isset($params['nodes'])) {
$options[] = "'".$params['nodes']. "' AS nodes";
$options[] = "'" . $params['nodes'] . "' AS nodes";
}
return parent::setBody(['query' => "JOIN CLUSTER ".$this->cluster.
((count($options)>0)?" ".implode(',', $options):"")]);
return parent::setBody(['query' => "JOIN CLUSTER " . $this->cluster .
((count($options) > 0) ? " " . implode(',', $options) : "")]);
}
}
throw new RuntimeException('Cluster name is missing.');
Expand Down
2 changes: 1 addition & 1 deletion src/Manticoresearch/Endpoints/Cluster/Set.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Endpoints\Cluster;

use Manticoresearch\Endpoints\EmulateBySql;
Expand All @@ -11,6 +10,7 @@
class Set extends EmulateBySql
{
use Utils;

/**
* @var string
*/
Expand Down
1 change: 0 additions & 1 deletion src/Manticoresearch/Endpoints/EmulateBySql.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Endpoints;

class EmulateBySql extends Sql
Expand Down
4 changes: 2 additions & 2 deletions src/Manticoresearch/Endpoints/ExplainQuery.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Endpoints;

use Manticoresearch\Exceptions\RuntimeException;
Expand All @@ -9,6 +8,7 @@
class ExplainQuery extends EmulateBySql
{
use Utils;

/**
* @var string
*/
Expand All @@ -18,7 +18,7 @@ public function setBody($params = null)
{
if (isset($this->index)) {
if (isset($params['query'])) {
return parent::setBody(['query' => "EXPLAIN QUERY ".$this->index. '\''.$params['query'].'\'']);
return parent::setBody(['query' => "EXPLAIN QUERY " . $this->index . '\'' . $params['query'] . '\'']);
}
throw new RuntimeException('Query param is missing.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Manticoresearch/Endpoints/Indices/Alter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Endpoints\Indices;

use Manticoresearch\Endpoints\EmulateBySql;
Expand All @@ -10,6 +9,7 @@
class Alter extends EmulateBySql
{
use Utils;

/**
* @var string
*/
Expand Down
15 changes: 8 additions & 7 deletions src/Manticoresearch/Endpoints/Indices/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class Create extends EmulateBySql
{
use Utils;

/**
* @var string
*/
Expand All @@ -36,18 +37,18 @@ public function setBody($params = null)
foreach ($params['settings'] as $name => $value) {
if (is_array($value)) {
foreach ($value as $v) {
$options.=" ".$name." = '".$v."'";
$options .= " " . $name . " = '" . $v . "'";
}
} else {
$options.=" ".$name." = '".$value."'";
$options .= " " . $name . " = '" . $value . "'";
}
}
}
return parent::setBody(['query' => "CREATE TABLE ".
(isset($params['silent']) && $params['silent']===true?' IF NOT EXISTS ':'').
$this->index.
(count($columns)>0?"(".implode(",", $columns).")":" ")
.$options]);
return parent::setBody(['query' => "CREATE TABLE " .
(isset($params['silent']) && $params['silent'] === true ? ' IF NOT EXISTS ' : '') .
$this->index .
(count($columns) > 0 ? "(" . implode(",", $columns) . ")" : " ")
. $options]);
}
throw new RuntimeException('Index name is missing.');
}
Expand Down
6 changes: 3 additions & 3 deletions src/Manticoresearch/Endpoints/Indices/Describe.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Endpoints\Indices;

use Manticoresearch\Endpoints\EmulateBySql;
Expand All @@ -10,6 +9,7 @@
class Describe extends EmulateBySql
{
use Utils;

/**
* @var string
*/
Expand All @@ -18,8 +18,8 @@ class Describe extends EmulateBySql
public function setBody($params = null)
{
if (isset($this->index)) {
return parent::setBody(['query' => "DESCRIBE ".$this->index. " ".
(isset($params['pattern'])?" LIKE '".$params['pattern']."'":"")]);
return parent::setBody(['query' => "DESCRIBE " . $this->index . " " .
(isset($params['pattern']) ? " LIKE '" . $params['pattern'] . "'" : "")]);
}
throw new RuntimeException('Index name is missing.');
}
Expand Down
3 changes: 1 addition & 2 deletions src/Manticoresearch/Endpoints/Indices/Drop.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Endpoints\Indices;

use Manticoresearch\Endpoints\EmulateBySql;
Expand All @@ -17,7 +16,7 @@ public function setBody($params = null)
{
if (isset($this->index)) {
return parent::setBody(['query' => "DROP TABLE " .
(isset($params['silent']) && $params['silent']===true?' IF EXISTS ':'').
(isset($params['silent']) && $params['silent'] === true ? ' IF EXISTS ' : '') .
$this->index]);
}
throw new RuntimeException('Missing index name in /indices/drop');
Expand Down
4 changes: 2 additions & 2 deletions src/Manticoresearch/Endpoints/Indices/FlushRamchunk.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Endpoints\Indices;

use Manticoresearch\Endpoints\EmulateBySql;
Expand All @@ -10,6 +9,7 @@
class FlushRamchunk extends EmulateBySql
{
use Utils;

/**
* @var string
*/
Expand All @@ -19,7 +19,7 @@ public function setBody($params = null)
{

if (isset($this->index)) {
return parent::setBody(['query' => "FLUSH RAMCHUNK ".$this->index]);
return parent::setBody(['query' => "FLUSH RAMCHUNK " . $this->index]);
}
throw new RuntimeException('Index name is missing.');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Manticoresearch/Endpoints/Indices/FlushRtindex.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Endpoints\Indices;

use Manticoresearch\Endpoints\EmulateBySql;
Expand All @@ -10,6 +9,7 @@
class FlushRtindex extends EmulateBySql
{
use Utils;

/**
* @var string
*/
Expand All @@ -19,7 +19,7 @@ public function setBody($params = null)
{

if (isset($this->index)) {
return parent::setBody(['query' => "FLUSH RTINDEX ".$this->index]);
return parent::setBody(['query' => "FLUSH RTINDEX " . $this->index]);
}
throw new RuntimeException('Index name is missing.');
}
Expand Down
1 change: 0 additions & 1 deletion src/Manticoresearch/Endpoints/Indices/Import.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace Manticoresearch\Endpoints\Indices;

use Manticoresearch\Endpoints\EmulateBySql;
Expand Down
Loading

0 comments on commit d166d09

Please sign in to comment.