Skip to content

Commit

Permalink
Clean up imports and whitespace (#282)
Browse files Browse the repository at this point in the history
* Fix imports and whitespace

Signed-off-by: Kim Pepper <[email protected]>

* Clean up code

Signed-off-by: Kim Pepper <[email protected]>

---------

Signed-off-by: Kim Pepper <[email protected]>
  • Loading branch information
kimpepper authored Feb 3, 2025
1 parent 70a5702 commit d35ea28
Show file tree
Hide file tree
Showing 118 changed files with 963 additions and 595 deletions.
13 changes: 11 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
<?php

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

/*
This document has been generated with
https://mlocati.github.io/php-cs-fixer-configurator/#version:3.0.0-rc.1|configurator
you can change this configuration by importing this file.
*/

return (new PhpCsFixer\Config())
return (new Config())
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'no_unused_imports' => true,
'fully_qualified_strict_types' => [
'import_symbols' => true,
'leading_backslash_in_global_namespace' => true,
'phpdoc_tags' => ['property-read', 'property-write'],
],
'no_extra_blank_lines' => ['tokens' => ['extra']],
])
->setFinder(
PhpCsFixer\Finder::create()
Finder::create()
->exclude('vendor')
->exclude('util/cache')
->in(__DIR__)
Expand Down
38 changes: 23 additions & 15 deletions samples/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?php

use GuzzleHttp\Psr7\HttpFactory;
use OpenSearch\Client;
use OpenSearch\EndpointFactory;
use OpenSearch\RequestFactory;
use OpenSearch\Serializers\SmartSerializer;
use OpenSearch\TransportFactory;
use Symfony\Component\HttpClient\Psr18Client;

/**
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
Expand All @@ -9,9 +17,9 @@

// Auto-configure by discovery example

$transport = (new \OpenSearch\TransportFactory())->create();
$endpointFactory = new \OpenSearch\EndpointFactory();
$client = new \OpenSearch\Client($transport, $endpointFactory, []);
$transport = (new TransportFactory())->create();
$endpointFactory = new EndpointFactory();
$client = new Client($transport, $endpointFactory, []);

// Send a request to the 'info' endpoint.
$info = $client->info();
Expand All @@ -26,35 +34,35 @@
'headers' => [
'Accept' => 'application/json',
'Content-Type' => 'application/json',
'User-Agent' => sprintf('opensearch-php/%s (%s; PHP %s)', \OpenSearch\Client::VERSION, PHP_OS, PHP_VERSION),
'User-Agent' => sprintf('opensearch-php/%s (%s; PHP %s)', Client::VERSION, PHP_OS, PHP_VERSION),
]
]);

$guzzleHttpFactory = new \GuzzleHttp\Psr7\HttpFactory();
$guzzleHttpFactory = new HttpFactory();

$serializer = new \OpenSearch\Serializers\SmartSerializer();
$serializer = new SmartSerializer();

$requestFactory = new \OpenSearch\RequestFactory(
$requestFactory = new RequestFactory(
$guzzleHttpFactory,
$guzzleHttpFactory,
$guzzleHttpFactory,
$serializer,
);

$transport = (new OpenSearch\TransportFactory())
$transport = (new TransportFactory())
->setHttpClient($guzzleClient)
->setRequestFactory($requestFactory)
->create();

$endpointFactory = new \OpenSearch\EndpointFactory();
$client = new \OpenSearch\Client($transport, $endpointFactory, []);
$endpointFactory = new EndpointFactory();
$client = new Client($transport, $endpointFactory, []);

// Send a request to the 'info' endpoint.
$info = $client->info();

// Symfony example

$symfonyPsr18Client = (new \Symfony\Component\HttpClient\Psr18Client())->withOptions([
$symfonyPsr18Client = (new Psr18Client())->withOptions([
'base_uri' => 'https://localhost:9200',
'auth_basic' => ['admin', getenv('OPENSEARCH_PASSWORD')],
'verify_peer' => false,
Expand All @@ -65,21 +73,21 @@
],
]);

$serializer = new \OpenSearch\Serializers\SmartSerializer();
$serializer = new SmartSerializer();

$requestFactory = new \OpenSearch\RequestFactory(
$requestFactory = new RequestFactory(
$symfonyPsr18Client,
$symfonyPsr18Client,
$symfonyPsr18Client,
$serializer,
);

$transport = (new \OpenSearch\TransportFactory())
$transport = (new TransportFactory())
->setHttpClient($symfonyPsr18Client)
->setRequestFactory($requestFactory)
->create();

$client = new \OpenSearch\Client($transport, $endpointFactory, []);
$client = new Client($transport, $endpointFactory, []);

// Send a request to the 'info' endpoint.
$info = $client->info();
Loading

0 comments on commit d35ea28

Please sign in to comment.