Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace self with static #172

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest']
php-version: ['7.1', '7.3', '7.4', '8.0', '8.1']
php-version: ['7.1', '7.3', '7.4', '8.0', '8.1', '8.2']
phpunit-version: ['latest']
transport: ['', 'PhpHttp']

Expand Down
2 changes: 1 addition & 1 deletion src/Manticoresearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function setConfig(array $config): self
*/
public static function create($config): Client
{
return self::createFromArray($config);
return static::createFromArray($config);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Manticoresearch/Endpoints/Keywords.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function setBody($params = null)
{
if (isset($this->index)) {
$binds =[];
$binds[] = "'" . self::escape($params['query']) . "'";
$binds[] = "'" . static::escape($params['query']) . "'";
$binds[] = "'" . $this->index . "'";
if (count($params['options']) > 0) {
foreach ($params['options'] as $name => $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Manticoresearch/Endpoints/Suggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function setBody($params = null)
{
if (isset($this->index)) {
$binds =[];
$binds[] = "'" . self::escape($params['query']) . "'";
$binds[] = "'" . static::escape($params['query']) . "'";
$binds[] = "'" . $this->index . "'";
if (count($params['options']) > 0) {
foreach ($params['options'] as $name => $value) {
Expand Down
16 changes: 8 additions & 8 deletions src/Manticoresearch/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function search($input): Search

public function getDocumentById($id)
{
self::checkDocumentId($id);
static::checkDocumentId($id);
$params = [
'body' => [
'index' => $this->index,
Expand All @@ -56,7 +56,7 @@ public function getDocumentByIds($ids)
if (!is_array($ids)) {
$ids = [$ids];
}
array_walk($ids, 'self::checkDocumentId');
array_walk($ids, [static::class, 'checkDocumentId']);
$params = [
'body' => [
'index' => $this->index,
Expand All @@ -70,7 +70,7 @@ public function getDocumentByIds($ids)

public function addDocument($data, $id = 0)
{
self::checkDocumentId($id);
static::checkDocumentId($id);
if (is_object($data)) {
$data = (array) $data;
} elseif (is_string($data)) {
Expand Down Expand Up @@ -101,7 +101,7 @@ public function addDocuments($documents)
}
if (isset($document['id'])) {
$id = $document['id'];
self::checkDocumentId($id);
static::checkDocumentId($id);
unset($document['id']);
} else {
$id = 0;
Expand All @@ -121,7 +121,7 @@ public function addDocuments($documents)

public function deleteDocument($id)
{
self::checkDocumentId($id);
static::checkDocumentId($id);
$params = [
'body' => [
'index' => $this->index,
Expand Down Expand Up @@ -153,7 +153,7 @@ public function deleteDocuments($query)

public function updateDocument($data, $id)
{
self::checkDocumentId($id);
static::checkDocumentId($id);
$params = [
'body' => [
'index' => $this->index,
Expand Down Expand Up @@ -187,7 +187,7 @@ public function updateDocuments($data, $query)

public function replaceDocument($data, $id)
{
self::checkDocumentId($id);
static::checkDocumentId($id);
if (is_object($data)) {
$data = (array) $data;
} elseif (is_string($data)) {
Expand Down Expand Up @@ -216,7 +216,7 @@ public function replaceDocuments($documents)
$document = json_decode($document, true);
}
$id = $document['id'];
self::checkDocumentId($id);
static::checkDocumentId($id);
unset($document['id']);
$replace = [
'index' => $this->index,
Expand Down
10 changes: 5 additions & 5 deletions src/Manticoresearch/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ public function filter($attr, $op = null, $values = null, $boolean = self::FILTE
}
}

if ($boolean === self::FILTER_AND) {
if ($boolean === static::FILTER_AND) {
$this->query->must($attr);
} elseif ($boolean === self::FILTER_OR) {
} elseif ($boolean === static::FILTER_OR) {
$this->query->should($attr);
} elseif ($boolean === self::FILTER_NOT) {
} elseif ($boolean === static::FILTER_NOT) {
$this->query->mustNot($attr);
}

Expand All @@ -230,12 +230,12 @@ public function filter($attr, $op = null, $values = null, $boolean = self::FILTE

public function orFilter($attr, $op = null, $values = null): self
{
return $this->filter($attr, $op, $values, self::FILTER_OR);
return $this->filter($attr, $op, $values, static::FILTER_OR);
}

public function notFilter($attr, $op = null, $values = null): self
{
return $this->filter($attr, $op, $values, self::FILTER_NOT);
return $this->filter($attr, $op, $values, static::FILTER_NOT);
}

public function offset($offset): self
Expand Down
8 changes: 4 additions & 4 deletions src/Manticoresearch/Transport/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function execute(Request $request, $params = [])
if ($errorno>0) {
$error = curl_error($conn);

self::$curl = null;
static::$curl = null;
throw new ConnectionException($error, $request);
}

Expand Down Expand Up @@ -131,9 +131,9 @@ public function execute(Request $request, $params = [])

protected function getCurlConnection(bool $persistent = true)
{
if (!$persistent || !self::$curl) {
self::$curl = curl_init();
if (!$persistent || !static::$curl) {
static::$curl = curl_init();
}
return self::$curl;
return static::$curl;
}
}
4 changes: 2 additions & 2 deletions test/Manticoresearch/Endpoints/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function setUpBeforeClass(): void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
static::$client = $helper->getClient();
}

public function testPath()
Expand All @@ -42,7 +42,7 @@ public function testDelete()
]
];

$response = self::$client->delete($doc);
$response = static::$client->delete($doc);
$helper->search('products', 'broken', 0);
}
}
14 changes: 7 additions & 7 deletions test/Manticoresearch/Endpoints/Indices/AlterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function setUp() : void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
self::$helper = $helper;
static::$client = $helper->getClient();
static::$helper = $helper;
}

public function testIndexNoOperation()
Expand All @@ -38,7 +38,7 @@ public function testIndexNoOperation()
];
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Operation is missing.');
$response = self::$client->indices()->alter($params);
$response = static::$client->indices()->alter($params);
}

public function testIndexDropColumn()
Expand All @@ -53,11 +53,11 @@ public function testIndexDropColumn()

]
];
$response = self::$client->indices()->alter($params);
$response = static::$client->indices()->alter($params);
$this->assertEquals(['total' => 0, 'error' => '', 'warning' => ''], $response);

// check the column has been added using the Describe endpoint
$response = self::$client->indices()->describe(['index' => 'products']);
$response = static::$client->indices()->describe(['index' => 'products']);

$expectedResponse = [
'id' =>
Expand Down Expand Up @@ -87,11 +87,11 @@ public function testIndexAddColumn()

]
];
$response = self::$client->indices()->alter($params);
$response = static::$client->indices()->alter($params);
$this->assertEquals(['total'=>0,'error'=>'','warning'=>''], $response);

// check the column has been added using the Describe endpoint
$response = self::$client->indices()->describe(['index' => 'products']);
$response = static::$client->indices()->describe(['index' => 'products']);

$expectedResponse = [
'id' =>
Expand Down
6 changes: 3 additions & 3 deletions test/Manticoresearch/Endpoints/Indices/DescribeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static function setUpBeforeClass(): void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
self::$helper = $helper;
static::$client = $helper->getClient();
static::$helper = $helper;
}

public function testDescribeIndex()
{
$response = self::$client->indices()->describe(['index' => 'products']);
$response = static::$client->indices()->describe(['index' => 'products']);

$this->assertEquals(array_keys([
'id' => [
Expand Down
6 changes: 3 additions & 3 deletions test/Manticoresearch/Endpoints/Indices/DropTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static function setUpBeforeClass(): void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
self::$helper = $helper;
static::$client = $helper->getClient();
static::$helper = $helper;
}

public function testIndexTruncate()
{
$response = self::$client->indices()->truncate(['index' => 'products']);
$response = static::$client->indices()->truncate(['index' => 'products']);

$this->assertEquals(['total'=>0,'error'=>'','warning'=>''], $response);
}
Expand Down
6 changes: 3 additions & 3 deletions test/Manticoresearch/Endpoints/Indices/FlushRamchunkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static function setUpBeforeClass(): void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
self::$helper = $helper;
static::$client = $helper->getClient();
static::$helper = $helper;
}

public function testFlushRamchunkIndex()
{
$response = self::$client->indices()->flushramchunk(['index' => 'products']);
$response = static::$client->indices()->flushramchunk(['index' => 'products']);

$this->assertEquals(['total'=>0,'error'=>'','warning'=>''], $response);
}
Expand Down
6 changes: 3 additions & 3 deletions test/Manticoresearch/Endpoints/Indices/FlushRtindexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static function setUpBeforeClass(): void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
self::$helper = $helper;
static::$client = $helper->getClient();
static::$helper = $helper;
}

public function testFlushRTIndex()
{
$response = self::$client->indices()->flushrtindex(['index' => 'products']);
$response = static::$client->indices()->flushrtindex(['index' => 'products']);

$this->assertEquals(['total'=>0,'error'=>'','warning'=>''], $response);
}
Expand Down
6 changes: 3 additions & 3 deletions test/Manticoresearch/Endpoints/Indices/OptimizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static function setUpBeforeClass(): void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
self::$helper = $helper;
static::$client = $helper->getClient();
static::$helper = $helper;
}

public function testDescribeIndex()
{
$response = self::$client->indices()->optimize(['index' => 'products']);
$response = static::$client->indices()->optimize(['index' => 'products']);

$this->assertEquals([
'total' => 0,
Expand Down
6 changes: 3 additions & 3 deletions test/Manticoresearch/Endpoints/Indices/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static function setUpBeforeClass(): void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
self::$helper = $helper;
static::$client = $helper->getClient();
static::$helper = $helper;
}

public function testSettings()
{
$response = self::$client->indices()->settings(['index' => 'products']);
$response = static::$client->indices()->settings(['index' => 'products']);

$expectedSettings = "min_infix_len = 3\nrt_mem_limit = 268435456" ;

Expand Down
6 changes: 3 additions & 3 deletions test/Manticoresearch/Endpoints/Indices/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static function setUpBeforeClass(): void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
self::$helper = $helper;
static::$client = $helper->getClient();
static::$helper = $helper;
}

public function testIndexStatus()
{
$response = self::$client->indices()->status(['index' => 'products']);
$response = static::$client->indices()->status(['index' => 'products']);
$this->assertArrayHasKey('disk_bytes', $response);
}

Expand Down
6 changes: 3 additions & 3 deletions test/Manticoresearch/Endpoints/Indices/TruncateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public static function setUpBeforeClass(): void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
self::$helper = $helper;
static::$client = $helper->getClient();
static::$helper = $helper;
}

public function testIndexTruncate()
{
$response = self::$client->indices()->truncate(['index' => 'products']);
$response = static::$client->indices()->truncate(['index' => 'products']);

$this->assertEquals(['total'=>0,'error'=>'','warning'=>''], $response);
}
Expand Down
2 changes: 1 addition & 1 deletion test/Manticoresearch/Endpoints/KeywordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function setUpBeforeClass(): void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
static::$client = $helper->getClient();
}

public function testKeywords()
Expand Down
4 changes: 2 additions & 2 deletions test/Manticoresearch/Endpoints/SuggestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function setUpBeforeClass(): void

$helper = new PopulateHelperTest();
$helper->populateForKeywords();
self::$client = $helper->getClient();
static::$client = $helper->getClient();
}
public function testSuggest()
{
Expand All @@ -30,7 +30,7 @@ public function testSuggest()
]
]
];
$response = self::$client->suggest($params);
$response = static::$client->suggest($params);
$this->assertSame('broken', array_keys($response)[0]);
}
public function testSuggestBadIndex()
Expand Down
Loading
Loading